Skip to content

Commit

Permalink
Merge pull request #44503 from aloubyansky/quarkusDev-dependency-warn
Browse files Browse the repository at this point in the history
Enforce the platform constraints when resolving the Quarkus bootstrap Gradle resolver dependencies
  • Loading branch information
gsmet authored Nov 19, 2024
2 parents 3a7a760 + 94140f2 commit 3dff5a4
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -564,18 +564,41 @@ protected void modifyDevModeContext(DevModeCommandLineBuilder builder) {

private void addQuarkusDevModeDeps(DevModeCommandLineBuilder 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 @@ -599,38 +622,26 @@ private void addQuarkusDevModeDeps(DevModeCommandLineBuilder builder, Applicatio
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, DevModeCommandLineBuilder 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 3dff5a4

Please sign in to comment.