From 176367bad5ec3e1faa61deffb37bcebf1d8d80ed Mon Sep 17 00:00:00 2001 From: Ashley Scopes <73482956+ascopes@users.noreply.github.com> Date: Sun, 12 May 2024 16:22:56 +0100 Subject: [PATCH] GH-172: Fix dependency conflict resolution This fixes the outstanding issue at GH-172 that creates an issue when mixing project and plugin-based dependencies that could be on different versions transitively. This only now works because of GH-215 fixing the way dependencies get resolved... we now resolve both project and plugin dependencies at the exact same time, which allows for some version resolution and conflict fixes to be performed by Eclipse Aether. --- .../selector.groovy | 17 ----------------- .../generation/SourceCodeGenerator.java | 17 ++++++++++++----- 2 files changed, 12 insertions(+), 22 deletions(-) delete mode 100644 protobuf-maven-plugin/src/it/gh-172-transitive-dependency-conflicts/selector.groovy diff --git a/protobuf-maven-plugin/src/it/gh-172-transitive-dependency-conflicts/selector.groovy b/protobuf-maven-plugin/src/it/gh-172-transitive-dependency-conflicts/selector.groovy deleted file mode 100644 index 85aaabe2..00000000 --- a/protobuf-maven-plugin/src/it/gh-172-transitive-dependency-conflicts/selector.groovy +++ /dev/null @@ -1,17 +0,0 @@ -/* - * Copyright (C) 2023 - 2024, Ashley Scopes. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -println("This test is disabled until GH-172 is addressed") -return false diff --git a/protobuf-maven-plugin/src/main/java/io/github/ascopes/protobufmavenplugin/generation/SourceCodeGenerator.java b/protobuf-maven-plugin/src/main/java/io/github/ascopes/protobufmavenplugin/generation/SourceCodeGenerator.java index ba97eaa1..7dd3993d 100644 --- a/protobuf-maven-plugin/src/main/java/io/github/ascopes/protobufmavenplugin/generation/SourceCodeGenerator.java +++ b/protobuf-maven-plugin/src/main/java/io/github/ascopes/protobufmavenplugin/generation/SourceCodeGenerator.java @@ -85,8 +85,8 @@ public boolean generate(GenerationRequest request) throws ResolutionException, I final var protocPath = discoverProtocPath(request); final var resolvedPlugins = discoverPlugins(request); - final var importPaths = discoverImportPaths(request); final var sourcePaths = discoverCompilableSources(request); + final var importPaths = discoverImportPaths(sourcePaths, request); if (sourcePaths.isEmpty()) { if (request.isFailOnMissingSources()) { @@ -173,17 +173,24 @@ private Collection discoverPlugins( } private Collection discoverImportPaths( + Collection sourcePathListings, GenerationRequest request ) throws IOException, ResolutionException { - var artifacts = concat(request.getImportDependencies(), request.getSourceDependencies()); var artifactPaths = artifactPathResolver.resolveDependencies( - artifacts, + request.getImportDependencies(), request.getDependencyResolutionDepth(), !request.isIgnoreProjectDependencies() ); - var importPaths = request.getImportPaths(); - return protoListingResolver.createProtoFileListings(concat(artifactPaths, importPaths)); + var importPathListings = protoListingResolver + .createProtoFileListings(concat(request.getImportPaths(), artifactPaths)); + + // Use the source paths here as well and use them first to give them precedence. This works + // around GH-172 where we can end up with different versions on the import and source paths + // depending on how dependency conflicts arise. + return Stream.concat(sourcePathListings.stream(), importPathListings.stream()) + .distinct() + .collect(Collectors.toList()); } private Collection discoverCompilableSources(