Skip to content

Commit

Permalink
Enforce the platform constraints when resolving the Quarkus bootstrap…
Browse files Browse the repository at this point in the history
… Gradle resolver dependencies
  • Loading branch information
Alexey Loubyansky committed Nov 14, 2024
1 parent b6324cd commit 8873bf0
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,7 @@ private void registerTasks(Project project, QuarkusPluginExtension quarkusExt) {
forcedPropertiesService, ForcedPropertieBuildService.class,
spec -> {
});
final String devRuntimeConfigName = ApplicationDeploymentClasspathBuilder
.getBaseRuntimeConfigName(LaunchMode.DEVELOPMENT);
final String devRuntimeConfigName = ApplicationDeploymentClasspathBuilder.getBaseRuntimeConfigName(LaunchMode.DEVELOPMENT);
final Configuration devRuntimeDependencies = project.getConfigurations().maybeCreate(devRuntimeConfigName);

tasks.register(LIST_EXTENSIONS_TASK_NAME, QuarkusListExtensions.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -551,18 +551,41 @@ protected void modifyDevModeContext(GradleDevModeLauncher.Builder builder) {

private void addQuarkusDevModeDeps(GradleDevModeLauncher.Builder builder, ApplicationModel appModel) {

ResolvedDependency coreDeployment = null;
for (ResolvedDependency d : appModel.getDependencies()) {
if (d.isDeploymentCp() && d.getArtifactId().equals("quarkus-core-deployment")
&& d.getGroupId().equals("io.quarkus")) {
coreDeployment = d;
break;
}
var devModeDependencyConfiguration = getProject().getConfigurations()
.findByName(ApplicationDeploymentClasspathBuilder.QUARKUS_BOOTSTRAP_RESOLVER_CONFIGURATION);
if (devModeDependencyConfiguration == null) {
final Configuration platformConfig = getProject().getConfigurations().findByName(
ToolingUtils.toPlatformConfigurationName(
ApplicationDeploymentClasspathBuilder.getFinalRuntimeConfigName(LaunchMode.DEVELOPMENT)));
getProject().getConfigurations().register(
ApplicationDeploymentClasspathBuilder.QUARKUS_BOOTSTRAP_RESOLVER_CONFIGURATION,
configuration -> {
configuration.setCanBeConsumed(false);
configuration.extendsFrom(platformConfig);
configuration.getDependencies().add(getQuarkusGradleBootstrapResolver());
configuration.getDependencies().add(getQuarkusCoreDeployment(appModel));
});
devModeDependencyConfiguration = getProject().getConfigurations()
.getByName(ApplicationDeploymentClasspathBuilder.QUARKUS_BOOTSTRAP_RESOLVER_CONFIGURATION);
}
if (coreDeployment == null) {
throw new GradleException("Failed to locate io.quarkus:quarkus-core-deployment on the application build classpath");

for (ResolvedArtifact appDep : devModeDependencyConfiguration.getResolvedConfiguration().getResolvedArtifacts()) {
ModuleVersionIdentifier artifactId = appDep.getModuleVersion().getId();
//we only use the launcher for launching from the IDE, we need to exclude it
if (!(artifactId.getGroup().equals("io.quarkus")
&& artifactId.getName().equals("quarkus-ide-launcher"))) {
if (artifactId.getGroup().equals("io.quarkus")
&& artifactId.getName().equals("quarkus-class-change-agent")) {
builder.jvmArgs("-javaagent:" + appDep.getFile().getAbsolutePath());
} else {
builder.classpathEntry(ArtifactKey.of(appDep.getModuleVersion().getId().getGroup(), appDep.getName(),
appDep.getClassifier(), appDep.getExtension()), appDep.getFile());
}
}
}
}

private Dependency getQuarkusGradleBootstrapResolver() {
final String pomPropsPath = "META-INF/maven/io.quarkus/quarkus-bootstrap-gradle-resolver/pom.properties";
final InputStream devModePomPropsIs = DevModeMain.class.getClassLoader().getResourceAsStream(pomPropsPath);
if (devModePomPropsIs == null) {
Expand All @@ -586,38 +609,26 @@ private void addQuarkusDevModeDeps(GradleDevModeLauncher.Builder builder, Applic
if (devModeVersion == null) {
throw new GradleException("Classpath resource " + pomPropsPath + " is missing version");
}

Dependency gradleResolverDep = getProject().getDependencies()
.create(String.format("%s:%s:%s", devModeGroupId, devModeArtifactId, devModeVersion));
Dependency coreDeploymentDep = getProject().getDependencies()
.create(String.format("%s:%s:%s", coreDeployment.getGroupId(), coreDeployment.getArtifactId(),
coreDeployment.getVersion()));

final Configuration devModeDependencyConfiguration = getProject().getConfigurations()
.detachedConfiguration(gradleResolverDep, coreDeploymentDep);

final String platformConfigName = ToolingUtils.toPlatformConfigurationName(
ApplicationDeploymentClasspathBuilder.getFinalRuntimeConfigName(LaunchMode.DEVELOPMENT));
final Configuration platformConfig = getProject().getConfigurations().findByName(platformConfigName);
if (platformConfig != null) {
// apply the platforms
devModeDependencyConfiguration.extendsFrom(platformConfig);
}
return gradleResolverDep;
}

for (ResolvedArtifact appDep : devModeDependencyConfiguration.getResolvedConfiguration().getResolvedArtifacts()) {
ModuleVersionIdentifier artifactId = appDep.getModuleVersion().getId();
//we only use the launcher for launching from the IDE, we need to exclude it
if (!(artifactId.getGroup().equals("io.quarkus")
&& artifactId.getName().equals("quarkus-ide-launcher"))) {
if (artifactId.getGroup().equals("io.quarkus")
&& artifactId.getName().equals("quarkus-class-change-agent")) {
builder.jvmArgs("-javaagent:" + appDep.getFile().getAbsolutePath());
} else {
builder.classpathEntry(ArtifactKey.of(appDep.getModuleVersion().getId().getGroup(), appDep.getName(),
appDep.getClassifier(), appDep.getExtension()), appDep.getFile());
}
private Dependency getQuarkusCoreDeployment(ApplicationModel appModel) {
ResolvedDependency coreDeployment = null;
for (ResolvedDependency d : appModel.getDependencies()) {
if (d.isDeploymentCp() && d.getArtifactId().equals("quarkus-core-deployment")
&& d.getGroupId().equals("io.quarkus")) {
coreDeployment = d;
break;
}
}
if (coreDeployment == null) {
throw new GradleException("Failed to locate io.quarkus:quarkus-core-deployment on the application build classpath");
}
return getProject().getDependencies()
.create(String.format("%s:%s:%s", coreDeployment.getGroupId(), coreDeployment.getArtifactId(),
coreDeployment.getVersion()));
}

private void addLocalProject(ResolvedDependency project, GradleDevModeLauncher.Builder builder, Set<ArtifactKey> addeDeps,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@

public class ApplicationDeploymentClasspathBuilder {

public static final String QUARKUS_BOOTSTRAP_RESOLVER_CONFIGURATION = "quarkusBootstrapResolverConfiguration";

private static String getLaunchModeAlias(LaunchMode mode) {
if (mode == LaunchMode.DEVELOPMENT) {
return "Dev";
Expand Down

0 comments on commit 8873bf0

Please sign in to comment.