diff --git a/devtools/gradle/gradle-application-plugin/src/main/java/io/quarkus/gradle/tasks/QuarkusDev.java b/devtools/gradle/gradle-application-plugin/src/main/java/io/quarkus/gradle/tasks/QuarkusDev.java index 5cc8b1319ac2f..50018c18c965e 100644 --- a/devtools/gradle/gradle-application-plugin/src/main/java/io/quarkus/gradle/tasks/QuarkusDev.java +++ b/devtools/gradle/gradle-application-plugin/src/main/java/io/quarkus/gradle/tasks/QuarkusDev.java @@ -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) { @@ -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 addeDeps, diff --git a/devtools/gradle/gradle-model/src/main/java/io/quarkus/gradle/dependency/ApplicationDeploymentClasspathBuilder.java b/devtools/gradle/gradle-model/src/main/java/io/quarkus/gradle/dependency/ApplicationDeploymentClasspathBuilder.java index 70c195738f6bd..7fc07fdf4f152 100644 --- a/devtools/gradle/gradle-model/src/main/java/io/quarkus/gradle/dependency/ApplicationDeploymentClasspathBuilder.java +++ b/devtools/gradle/gradle-model/src/main/java/io/quarkus/gradle/dependency/ApplicationDeploymentClasspathBuilder.java @@ -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";