Skip to content

Commit

Permalink
Collect and expose compile-only dependencies through ApplicationModel
Browse files Browse the repository at this point in the history
with DependencyFlag.COMPILE_ONLY flag set (Maven provided scope)
  • Loading branch information
aloubyansky committed Jan 8, 2024
1 parent ba97483 commit a3882d2
Show file tree
Hide file tree
Showing 23 changed files with 957 additions and 225 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import java.util.HashSet;
import java.util.Set;

import org.eclipse.aether.util.artifact.JavaScopes;

import io.quarkus.bootstrap.model.ApplicationModel;
import io.quarkus.bootstrap.resolver.TsArtifact;
import io.quarkus.bootstrap.resolver.TsDependency;
Expand Down Expand Up @@ -35,25 +37,29 @@ protected TsArtifact composeApplication() {
addToExpectedLib(extA.getRuntime());
extA.getRuntime()
.addDependency(extADep)
.addDependency(new TsDependency(extAProvidedDep, "provided"));
.addDependency(new TsDependency(extAProvidedDep, JavaScopes.PROVIDED));
extA.getDeployment()
.addDependency(extADeploymentDep)
.addDependency(new TsDependency(extAOptionalDeploymentDep, "provided"));
.addDependency(new TsDependency(extAOptionalDeploymentDep, JavaScopes.PROVIDED));

final TsQuarkusExt extB = new TsQuarkusExt("ext-b");
this.install(extB);

final TsArtifact directProvidedDep = TsArtifact.jar("direct-provided-dep");

final TsArtifact depC2 = TsArtifact.jar("dep-c", "2");
// make sure provided dependencies don't override compile/runtime dependencies
directProvidedDep.addDependency(depC2);

final TsArtifact transitiveProvidedDep = TsArtifact.jar("transitive-provided-dep");
directProvidedDep.addDependency(transitiveProvidedDep);

return TsArtifact.jar("app")
.addManagedDependency(platformDescriptor())
.addManagedDependency(platformProperties())
.addDependency(extA)
.addDependency(extB, "provided")
.addDependency(new TsDependency(directProvidedDep, "provided"));
.addDependency(extB, JavaScopes.PROVIDED)
.addDependency(new TsDependency(directProvidedDep, JavaScopes.PROVIDED));
}

@Override
Expand All @@ -64,5 +70,36 @@ protected void assertAppModel(ApplicationModel model) throws Exception {
expected.add(new ArtifactDependency(ArtifactCoords.jar("io.quarkus.bootstrap.test", "ext-a-deployment-dep", "1"),
DependencyFlags.DEPLOYMENT_CP));
assertEquals(expected, getDeploymentOnlyDeps(model));

expected = new HashSet<>();
expected.add(new ArtifactDependency(ArtifactCoords.jar("io.quarkus.bootstrap.test", "ext-a", "1"),
DependencyFlags.RUNTIME_CP,
DependencyFlags.DEPLOYMENT_CP,
DependencyFlags.DIRECT,
DependencyFlags.RUNTIME_EXTENSION_ARTIFACT,
DependencyFlags.TOP_LEVEL_RUNTIME_EXTENSION_ARTIFACT));
expected.add(new ArtifactDependency(ArtifactCoords.jar("io.quarkus.bootstrap.test", "ext-a-dep", "1"),
DependencyFlags.RUNTIME_CP,
DependencyFlags.DEPLOYMENT_CP));
expected.add(new ArtifactDependency(ArtifactCoords.jar("io.quarkus.bootstrap.test", "dep-c", "1"),
DependencyFlags.RUNTIME_CP,
DependencyFlags.DEPLOYMENT_CP));
assertEquals(expected, getDependenciesWithFlag(model, DependencyFlags.RUNTIME_CP));

expected = new HashSet<>();
expected.add(new ArtifactDependency(ArtifactCoords.jar("io.quarkus.bootstrap.test", "ext-b", "1"),
JavaScopes.PROVIDED,
DependencyFlags.RUNTIME_EXTENSION_ARTIFACT,
DependencyFlags.DIRECT,
DependencyFlags.TOP_LEVEL_RUNTIME_EXTENSION_ARTIFACT,
DependencyFlags.COMPILE_ONLY));
expected.add(new ArtifactDependency(ArtifactCoords.jar("io.quarkus.bootstrap.test", "direct-provided-dep", "1"),
JavaScopes.PROVIDED,
DependencyFlags.DIRECT,
DependencyFlags.COMPILE_ONLY));
expected.add(new ArtifactDependency(ArtifactCoords.jar("io.quarkus.bootstrap.test", "transitive-provided-dep", "1"),
JavaScopes.PROVIDED,
DependencyFlags.COMPILE_ONLY));
assertEquals(expected, getDependenciesWithFlag(model, DependencyFlags.COMPILE_ONLY));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
package io.quarkus.deployment.runnerjar;

import static org.junit.jupiter.api.Assertions.assertEquals;

import java.util.HashSet;
import java.util.Set;

import org.eclipse.aether.util.artifact.JavaScopes;

import io.quarkus.bootstrap.model.ApplicationModel;
import io.quarkus.bootstrap.resolver.TsArtifact;
import io.quarkus.bootstrap.resolver.TsDependency;
import io.quarkus.bootstrap.resolver.TsQuarkusExt;
import io.quarkus.maven.dependency.ArtifactCoords;
import io.quarkus.maven.dependency.ArtifactDependency;
import io.quarkus.maven.dependency.Dependency;
import io.quarkus.maven.dependency.DependencyFlags;

public class ProvidedExtensionDepsTestModeTest extends BootstrapFromOriginalJarTestBase {

@Override
protected boolean isBootstrapForTestMode() {
return true;
}

@Override
protected TsArtifact composeApplication() {

final TsArtifact extADep = TsArtifact.jar("ext-a-dep");
addToExpectedLib(extADep);

final TsArtifact depC1 = TsArtifact.jar("dep-c");
//addToExpectedLib(depC1);
extADep.addDependency(depC1);

final TsArtifact extAProvidedDep = TsArtifact.jar("ext-a-provided-dep");

final TsArtifact extADeploymentDep = TsArtifact.jar("ext-a-deployment-dep");
final TsArtifact extAOptionalDeploymentDep = TsArtifact.jar("ext-a-provided-deployment-dep");

final TsQuarkusExt extA = new TsQuarkusExt("ext-a");
addToExpectedLib(extA.getRuntime());
extA.getRuntime()
.addDependency(extADep)
.addDependency(new TsDependency(extAProvidedDep, JavaScopes.PROVIDED));
extA.getDeployment()
.addDependency(extADeploymentDep)
.addDependency(new TsDependency(extAOptionalDeploymentDep, JavaScopes.PROVIDED));

final TsQuarkusExt extB = new TsQuarkusExt("ext-b");
addToExpectedLib(extB.getRuntime());
this.install(extB);

final TsArtifact directProvidedDep = TsArtifact.jar("direct-provided-dep");
addToExpectedLib(directProvidedDep);

final TsArtifact depC2 = TsArtifact.jar("dep-c", "2");
// here provided dependencies will override compile/runtime ones during version convergence
addToExpectedLib(depC2);
directProvidedDep.addDependency(depC2);

final TsArtifact transitiveProvidedDep = TsArtifact.jar("transitive-provided-dep");
addToExpectedLib(transitiveProvidedDep);
directProvidedDep.addDependency(transitiveProvidedDep);

return TsArtifact.jar("app")
.addManagedDependency(platformDescriptor())
.addManagedDependency(platformProperties())
.addDependency(extA)
.addDependency(extB, JavaScopes.PROVIDED)
.addDependency(new TsDependency(directProvidedDep, JavaScopes.PROVIDED));
}

@Override
protected void assertAppModel(ApplicationModel model) throws Exception {
Set<Dependency> expected = new HashSet<>();
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));
expected.add(new ArtifactDependency(ArtifactCoords.jar("io.quarkus.bootstrap.test", "ext-b-deployment", "1"),
JavaScopes.PROVIDED,
DependencyFlags.DEPLOYMENT_CP));
assertEquals(expected, getDeploymentOnlyDeps(model));

expected = new HashSet<>();
expected.add(new ArtifactDependency(ArtifactCoords.jar("io.quarkus.bootstrap.test", "ext-a", "1"),
DependencyFlags.RUNTIME_CP,
DependencyFlags.DEPLOYMENT_CP,
DependencyFlags.DIRECT,
DependencyFlags.RUNTIME_EXTENSION_ARTIFACT,
DependencyFlags.TOP_LEVEL_RUNTIME_EXTENSION_ARTIFACT));
expected.add(new ArtifactDependency(ArtifactCoords.jar("io.quarkus.bootstrap.test", "ext-a-dep", "1"),
DependencyFlags.RUNTIME_CP,
DependencyFlags.DEPLOYMENT_CP));
expected.add(new ArtifactDependency(ArtifactCoords.jar("io.quarkus.bootstrap.test", "dep-c", "2"),
DependencyFlags.RUNTIME_CP,
DependencyFlags.DEPLOYMENT_CP));
expected.add(new ArtifactDependency(ArtifactCoords.jar("io.quarkus.bootstrap.test", "ext-b", "1"),
JavaScopes.PROVIDED,
DependencyFlags.RUNTIME_EXTENSION_ARTIFACT,
DependencyFlags.DIRECT,
DependencyFlags.TOP_LEVEL_RUNTIME_EXTENSION_ARTIFACT,
DependencyFlags.RUNTIME_CP,
DependencyFlags.DEPLOYMENT_CP,
DependencyFlags.COMPILE_ONLY));
expected.add(new ArtifactDependency(ArtifactCoords.jar("io.quarkus.bootstrap.test", "direct-provided-dep", "1"),
JavaScopes.PROVIDED,
DependencyFlags.DIRECT,
DependencyFlags.RUNTIME_CP,
DependencyFlags.DEPLOYMENT_CP,
DependencyFlags.COMPILE_ONLY));
expected.add(new ArtifactDependency(ArtifactCoords.jar("io.quarkus.bootstrap.test", "transitive-provided-dep", "1"),
JavaScopes.PROVIDED,
DependencyFlags.RUNTIME_CP,
DependencyFlags.DEPLOYMENT_CP,
DependencyFlags.COMPILE_ONLY));
assertEquals(expected, getDependenciesWithFlag(model, DependencyFlags.RUNTIME_CP));

expected = new HashSet<>();
expected.add(new ArtifactDependency(ArtifactCoords.jar("io.quarkus.bootstrap.test", "ext-b", "1"),
JavaScopes.PROVIDED,
DependencyFlags.RUNTIME_EXTENSION_ARTIFACT,
DependencyFlags.DIRECT,
DependencyFlags.TOP_LEVEL_RUNTIME_EXTENSION_ARTIFACT,
DependencyFlags.RUNTIME_CP,
DependencyFlags.DEPLOYMENT_CP,
DependencyFlags.COMPILE_ONLY));
expected.add(new ArtifactDependency(ArtifactCoords.jar("io.quarkus.bootstrap.test", "direct-provided-dep", "1"),
JavaScopes.PROVIDED,
DependencyFlags.DIRECT,
DependencyFlags.RUNTIME_CP,
DependencyFlags.DEPLOYMENT_CP,
DependencyFlags.COMPILE_ONLY));
expected.add(new ArtifactDependency(ArtifactCoords.jar("io.quarkus.bootstrap.test", "transitive-provided-dep", "1"),
JavaScopes.PROVIDED,
DependencyFlags.RUNTIME_CP,
DependencyFlags.DEPLOYMENT_CP,
DependencyFlags.COMPILE_ONLY));
assertEquals(expected, getDependenciesWithFlag(model, DependencyFlags.COMPILE_ONLY));
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
package io.quarkus.gradle.dependency;

import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.Set;
import java.util.*;
import java.util.stream.Collectors;

import org.gradle.api.GradleException;
Expand Down Expand Up @@ -37,16 +32,19 @@

public class ApplicationDeploymentClasspathBuilder {

private static String getRuntimeConfigName(LaunchMode mode, boolean base) {
final StringBuilder sb = new StringBuilder();
sb.append("quarkus");
private static String getLaunchModeAlias(LaunchMode mode) {
if (mode == LaunchMode.DEVELOPMENT) {
sb.append("Dev");
} else if (mode == LaunchMode.TEST) {
sb.append("Test");
} else {
sb.append("Prod");
return "Dev";
}
if (mode == LaunchMode.TEST) {
return "Test";
}
return "Prod";
}

private static String getRuntimeConfigName(LaunchMode mode, boolean base) {
final StringBuilder sb = new StringBuilder();
sb.append("quarkus").append(getLaunchModeAlias(mode));
if (base) {
sb.append("Base");
}
Expand Down Expand Up @@ -118,6 +116,8 @@ public static void initConfigurations(Project project) {
private final String runtimeConfigurationName;
private final String platformConfigurationName;
private final String deploymentConfigurationName;
private final String compileOnlyConfigurationName;

/**
* The platform configuration updates the PlatformImports, but since the PlatformImports don't
* have a place to be stored in the project, they're stored here. The way that extensions are
Expand All @@ -136,10 +136,12 @@ public ApplicationDeploymentClasspathBuilder(Project project, LaunchMode mode) {
this.platformConfigurationName = ToolingUtils.toPlatformConfigurationName(this.runtimeConfigurationName);
this.deploymentConfigurationName = ToolingUtils.toDeploymentConfigurationName(this.runtimeConfigurationName);
this.platformImportName = project.getPath() + ":" + this.platformConfigurationName;
this.compileOnlyConfigurationName = "quarkus" + getLaunchModeAlias(mode) + "CompileOnlyConfiguration";

setUpPlatformConfiguration();
setUpRuntimeConfiguration();
setUpDeploymentConfiguration();
setUpCompileOnlyConfiguration();
}

private void setUpPlatformConfiguration() {
Expand Down Expand Up @@ -254,6 +256,16 @@ private void setUpDeploymentConfiguration() {
}
}

private void setUpCompileOnlyConfiguration() {
if (!project.getConfigurations().getNames().contains(compileOnlyConfigurationName)) {
project.getConfigurations().register(compileOnlyConfigurationName, config -> {
config.extendsFrom(project.getConfigurations().getByName(JavaPlugin.COMPILE_ONLY_CONFIGURATION_NAME));
config.shouldResolveConsistentlyWith(getDeploymentConfiguration());
config.setCanBeConsumed(false);
});
}
}

public Configuration getPlatformConfiguration() {
return project.getConfigurations().getByName(this.platformConfigurationName);
}
Expand All @@ -274,6 +286,14 @@ public Configuration getDeploymentConfiguration() {
return project.getConfigurations().getByName(this.deploymentConfigurationName);
}

/**
* Compile-only configuration which is consistent with the deployment one
*/
public Configuration getCompileOnly() {
this.getDeploymentConfiguration().resolve();
return project.getConfigurations().getByName(compileOnlyConfigurationName);
}

/**
* Forces the platform configuration to resolve and then uses that to populate platform imports.
*/
Expand Down
Loading

0 comments on commit a3882d2

Please sign in to comment.