Skip to content

Commit

Permalink
Merge pull request quarkusio#38760 from aloubyansky/set-compile-only-…
Browse files Browse the repository at this point in the history
…flag-on-rt-and-deployment-deps

Set COMPILE_ONLY flag on relevant dependencies that appear on DEPLOYMENT_CP and RUNTIME_CP
  • Loading branch information
gsmet authored Feb 13, 2024
2 parents e88fb36 + 94aa1a9 commit b70ea45
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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<Dependency> expectedRuntime = new HashSet<>();
Expand All @@ -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<Dependency> expectedCompileOnly = new HashSet<>();
Expand All @@ -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<Dependency> compileOnlyPlusRuntime = new HashSet<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
*
Expand All @@ -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),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
4 changes: 4 additions & 0 deletions integration-tests/gradle/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@
<groupId>io.quarkus</groupId>
<artifactId>quarkus-avro</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-bootstrap-maven-resolver</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-core</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ plugins {

dependencies {
implementation project(':common')
implementation("io.quarkus:quarkus-bootstrap-maven-resolver:${quarkusPlatformVersion}") {
exclude group: '*'
}
}

group 'org.acme'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, Map<String, Integer>> compileOnlyDeps;
try (ProjectConnection connection = GradleConnector.newConnector()
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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) {
Expand Down

0 comments on commit b70ea45

Please sign in to comment.