diff --git a/core/deployment/src/test/java/io/quarkus/deployment/runnerjar/ProvidedExtensionDepsTest.java b/core/deployment/src/test/java/io/quarkus/deployment/runnerjar/ProvidedExtensionDepsTest.java index adaca8f5ead22..8a259cd726946 100644 --- a/core/deployment/src/test/java/io/quarkus/deployment/runnerjar/ProvidedExtensionDepsTest.java +++ b/core/deployment/src/test/java/io/quarkus/deployment/runnerjar/ProvidedExtensionDepsTest.java @@ -50,6 +50,7 @@ protected TsArtifact composeApplication() { final TsArtifact depC2 = TsArtifact.jar("dep-c", "2"); // make sure provided dependencies don't override compile/runtime dependencies directProvidedDep.addDependency(depC2); + directProvidedDep.addDependency(extADeploymentDep); final TsArtifact transitiveProvidedDep = TsArtifact.jar("transitive-provided-dep"); directProvidedDep.addDependency(transitiveProvidedDep); @@ -68,7 +69,7 @@ protected void assertAppModel(ApplicationModel model) throws Exception { expected.add(new ArtifactDependency(ArtifactCoords.jar("io.quarkus.bootstrap.test", "ext-a-deployment", "1"), DependencyFlags.DEPLOYMENT_CP)); expected.add(new ArtifactDependency(ArtifactCoords.jar("io.quarkus.bootstrap.test", "ext-a-deployment-dep", "1"), - DependencyFlags.DEPLOYMENT_CP)); + DependencyFlags.DEPLOYMENT_CP, DependencyFlags.COMPILE_ONLY)); assertEquals(expected, getDeploymentOnlyDeps(model)); final Set expectedRuntime = new HashSet<>(); @@ -83,7 +84,8 @@ protected void assertAppModel(ApplicationModel model) throws Exception { DependencyFlags.DEPLOYMENT_CP)); expectedRuntime.add(new ArtifactDependency(ArtifactCoords.jar("io.quarkus.bootstrap.test", "dep-c", "1"), DependencyFlags.RUNTIME_CP, - DependencyFlags.DEPLOYMENT_CP)); + DependencyFlags.DEPLOYMENT_CP, + DependencyFlags.COMPILE_ONLY)); assertEquals(expectedRuntime, getDependenciesWithFlag(model, DependencyFlags.RUNTIME_CP)); final Set expectedCompileOnly = new HashSet<>(); @@ -102,6 +104,13 @@ protected void assertAppModel(ApplicationModel model) throws Exception { .add(new ArtifactDependency(ArtifactCoords.jar("io.quarkus.bootstrap.test", "transitive-provided-dep", "1"), JavaScopes.PROVIDED, DependencyFlags.COMPILE_ONLY)); + expectedCompileOnly.add(new ArtifactDependency(ArtifactCoords.jar("io.quarkus.bootstrap.test", "dep-c", "1"), + DependencyFlags.RUNTIME_CP, + DependencyFlags.DEPLOYMENT_CP, + DependencyFlags.COMPILE_ONLY)); + expectedCompileOnly + .add(new ArtifactDependency(ArtifactCoords.jar("io.quarkus.bootstrap.test", "ext-a-deployment-dep", "1"), + DependencyFlags.DEPLOYMENT_CP, DependencyFlags.COMPILE_ONLY)); assertEquals(expectedCompileOnly, getDependenciesWithFlag(model, DependencyFlags.COMPILE_ONLY)); final Set compileOnlyPlusRuntime = new HashSet<>(); diff --git a/independent-projects/bootstrap/core/src/test/java/io/quarkus/bootstrap/resolver/test/ProvidedScopeDepsAreNotCollectedTestCase.java b/independent-projects/bootstrap/core/src/test/java/io/quarkus/bootstrap/resolver/test/ProvidedScopeDepsAreNotCollectedTestCase.java index a563396e40319..6438e2bc2d27b 100644 --- a/independent-projects/bootstrap/core/src/test/java/io/quarkus/bootstrap/resolver/test/ProvidedScopeDepsAreNotCollectedTestCase.java +++ b/independent-projects/bootstrap/core/src/test/java/io/quarkus/bootstrap/resolver/test/ProvidedScopeDepsAreNotCollectedTestCase.java @@ -3,6 +3,7 @@ import io.quarkus.bootstrap.resolver.CollectDependenciesBase; import io.quarkus.bootstrap.resolver.TsArtifact; import io.quarkus.bootstrap.resolver.TsDependency; +import io.quarkus.maven.dependency.DependencyFlags; /** * @@ -20,7 +21,8 @@ protected void setupDependencies() { .addDependency( new TsDependency( notCollected, "provided")); - install(common1, true); + install(common1); + addCollectedDep(common1, DependencyFlags.COMPILE_ONLY); installAsDep(new TsArtifact("required-dep") .addDependency(common1), diff --git a/independent-projects/bootstrap/maven-resolver/src/main/java/io/quarkus/bootstrap/resolver/maven/ApplicationDependencyTreeResolver.java b/independent-projects/bootstrap/maven-resolver/src/main/java/io/quarkus/bootstrap/resolver/maven/ApplicationDependencyTreeResolver.java index f7d2cc72d0a07..7a3fd7574fb5d 100644 --- a/independent-projects/bootstrap/maven-resolver/src/main/java/io/quarkus/bootstrap/resolver/maven/ApplicationDependencyTreeResolver.java +++ b/independent-projects/bootstrap/maven-resolver/src/main/java/io/quarkus/bootstrap/resolver/maven/ApplicationDependencyTreeResolver.java @@ -281,15 +281,19 @@ private void collectCompileOnly(CollectRequest collectRtDepsRequest, DependencyN int flags = DependencyFlags.DIRECT | DependencyFlags.COMPILE_ONLY; while (children != null) { for (DependencyNode node : children) { - if (appBuilder.getDependency(getKey(node.getArtifact())) == null) { - var dep = newDependencyBuilder(node, resolver).setFlags(flags); - if (getExtensionInfoOrNull(node.getArtifact(), node.getRepositories()) != null) { + var extInfo = getExtensionInfoOrNull(node.getArtifact(), node.getRepositories()); + var dep = appBuilder.getDependency(getKey(node.getArtifact())); + if (dep == null) { + dep = newDependencyBuilder(node, resolver).setFlags(flags); + if (extInfo != null) { dep.setFlags(DependencyFlags.RUNTIME_EXTENSION_ARTIFACT); if (dep.isFlagSet(DependencyFlags.DIRECT)) { dep.setFlags(DependencyFlags.TOP_LEVEL_RUNTIME_EXTENSION_ARTIFACT); } } appBuilder.addDependency(dep); + } else { + dep.setFlags(DependencyFlags.COMPILE_ONLY); } if (!node.getChildren().isEmpty()) { depStack.add(node.getChildren()); diff --git a/integration-tests/gradle/pom.xml b/integration-tests/gradle/pom.xml index 3c4a34a85ed73..7cd72302039e2 100644 --- a/integration-tests/gradle/pom.xml +++ b/integration-tests/gradle/pom.xml @@ -84,6 +84,10 @@ io.quarkus quarkus-avro + + io.quarkus + quarkus-bootstrap-maven-resolver + io.quarkus quarkus-core diff --git a/integration-tests/gradle/src/main/resources/compile-only-dependency-flags/componly/build.gradle b/integration-tests/gradle/src/main/resources/compile-only-dependency-flags/componly/build.gradle index 7963961b03fcc..42a65ff920e63 100644 --- a/integration-tests/gradle/src/main/resources/compile-only-dependency-flags/componly/build.gradle +++ b/integration-tests/gradle/src/main/resources/compile-only-dependency-flags/componly/build.gradle @@ -4,6 +4,9 @@ plugins { dependencies { implementation project(':common') + implementation("io.quarkus:quarkus-bootstrap-maven-resolver:${quarkusPlatformVersion}") { + exclude group: '*' + } } group 'org.acme' diff --git a/integration-tests/gradle/src/test/java/io/quarkus/gradle/CompileOnlyDependencyFlagsTest.java b/integration-tests/gradle/src/test/java/io/quarkus/gradle/CompileOnlyDependencyFlagsTest.java index 13a55a7d19b1f..b7e8ed45f80da 100644 --- a/integration-tests/gradle/src/test/java/io/quarkus/gradle/CompileOnlyDependencyFlagsTest.java +++ b/integration-tests/gradle/src/test/java/io/quarkus/gradle/CompileOnlyDependencyFlagsTest.java @@ -28,7 +28,9 @@ public void compileOnlyFlags() throws Exception { final String componly = ArtifactCoords.jar("org.acme", "componly", "1.0.0-SNAPSHOT").toCompactCoords(); final String common = ArtifactCoords.jar("org.acme", "common", "1.0.0-SNAPSHOT").toCompactCoords(); - var expectedCompileOnly = Set.of(componly, common); + final String bootstrapResolver = ArtifactCoords + .jar("io.quarkus", "quarkus-bootstrap-maven-resolver", System.getProperty("project.version")).toCompactCoords(); + var expectedCompileOnly = Set.of(componly, common, bootstrapResolver); final Map> compileOnlyDeps; try (ProjectConnection connection = GradleConnector.newConnector() @@ -65,6 +67,11 @@ public void compileOnlyFlags() throws Exception { DependencyFlags.RELOADABLE, DependencyFlags.WORKSPACE_MODULE, DependencyFlags.DIRECT); + assertOnlyFlagsSet(bootstrapResolver, compileOnly.get(bootstrapResolver), + DependencyFlags.COMPILE_ONLY, + DependencyFlags.RUNTIME_CP, + DependencyFlags.DEPLOYMENT_CP, + DependencyFlags.CLASSLOADER_PARENT_FIRST); compileOnly = compileOnlyDeps.get(LaunchMode.TEST.name()); assertEqual(compileOnly, expectedCompileOnly); @@ -77,6 +84,9 @@ public void compileOnlyFlags() throws Exception { DependencyFlags.DIRECT); assertOnlyFlagsSet(componly, compileOnly.get(componly), DependencyFlags.COMPILE_ONLY); + assertOnlyFlagsSet(bootstrapResolver, compileOnly.get(bootstrapResolver), + DependencyFlags.COMPILE_ONLY, + DependencyFlags.CLASSLOADER_PARENT_FIRST); compileOnly = compileOnlyDeps.get(LaunchMode.NORMAL.name()); assertEqual(compileOnly, expectedCompileOnly); @@ -87,6 +97,9 @@ public void compileOnlyFlags() throws Exception { DependencyFlags.DIRECT); assertOnlyFlagsSet(componly, compileOnly.get(componly), DependencyFlags.COMPILE_ONLY); + assertOnlyFlagsSet(bootstrapResolver, compileOnly.get(bootstrapResolver), + DependencyFlags.COMPILE_ONLY, + DependencyFlags.CLASSLOADER_PARENT_FIRST); } private static void assertOnlyFlagsSet(String coords, int flags, int... expectedFlags) {