From 50c1c12fd736af47cb0e14bd054223cf6f608954 Mon Sep 17 00:00:00 2001 From: Inaki Villar Date: Mon, 9 Dec 2024 23:02:09 +0100 Subject: [PATCH] Defining a Property to Resolve Conditional Dependencies --- .../main/java/io/quarkus/gradle/QuarkusPlugin.java | 14 ++++++++------ .../gradle/extension/QuarkusPluginExtension.java | 7 +++++++ .../gradle/tasks/QuarkusApplicationModelTask.java | 2 ++ .../conditional-test-project/runner/build.gradle | 4 ++++ .../scenario-two/build.gradle | 4 ++++ 5 files changed, 25 insertions(+), 6 deletions(-) diff --git a/devtools/gradle/gradle-application-plugin/src/main/java/io/quarkus/gradle/QuarkusPlugin.java b/devtools/gradle/gradle-application-plugin/src/main/java/io/quarkus/gradle/QuarkusPlugin.java index 0a849539e132b..f47945a9afcc6 100644 --- a/devtools/gradle/gradle-application-plugin/src/main/java/io/quarkus/gradle/QuarkusPlugin.java +++ b/devtools/gradle/gradle-application-plugin/src/main/java/io/quarkus/gradle/QuarkusPlugin.java @@ -189,12 +189,12 @@ private void registerTasks(Project project, QuarkusPluginExtension quarkusExt) { "quarkusGenerateTestAppModel", QuarkusApplicationModelTask.class, task -> { configureApplicationModelTask(project, task, projectDescriptor, testClasspath, LaunchMode.TEST, - "quarkus/application-model/quarkus-app-test-model.dat"); + "quarkus/application-model/quarkus-app-test-model.dat", quarkusExt.getConditionalExtensions()); }); TaskProvider quarkusGenerateDevAppModelTask = tasks.register("quarkusGenerateDevAppModel", QuarkusApplicationModelTask.class, task -> { configureApplicationModelTask(project, task, projectDescriptor, devClasspath, LaunchMode.DEVELOPMENT, - "quarkus/application-model/quarkus-app-dev-model.dat"); + "quarkus/application-model/quarkus-app-dev-model.dat", quarkusExt.getConditionalExtensions()); }); TaskProvider quarkusGenerateAppModelTask = tasks.register("quarkusGenerateAppModel", @@ -202,7 +202,7 @@ private void registerTasks(Project project, QuarkusPluginExtension quarkusExt) { configureApplicationModelTask(project, task, projectDescriptor .map(d -> d.withSourceSetView(Collections.singleton(SourceSet.MAIN_SOURCE_SET_NAME))), normalClasspath, LaunchMode.NORMAL, - "quarkus/application-model/quarkus-app-model.dat"); + "quarkus/application-model/quarkus-app-model.dat", quarkusExt.getConditionalExtensions()); }); // quarkusGenerateCode @@ -232,7 +232,7 @@ private void registerTasks(Project project, QuarkusPluginExtension quarkusExt) { configureApplicationModelTask(project, task, projectDescriptor .map(d -> d.withSourceSetView(Collections.singleton(SourceSet.MAIN_SOURCE_SET_NAME))), normalClasspath, LaunchMode.NORMAL, - "quarkus/application-model/quarkus-app-model-build.dat"); + "quarkus/application-model/quarkus-app-model-build.dat", quarkusExt.getConditionalExtensions()); }); tasks.register(QUARKUS_SHOW_EFFECTIVE_CONFIG_TASK_NAME, QuarkusShowEffectiveConfig.class, task -> { @@ -500,14 +500,16 @@ public void execute(Task task) { private static void configureApplicationModelTask(Project project, QuarkusApplicationModelTask task, Provider projectDescriptor, ApplicationDeploymentClasspathBuilder classpath, - LaunchMode launchMode, String quarkusModelFile) { + LaunchMode launchMode, String quarkusModelFile, Property conditionalExtensions) { task.getProjectDescriptor().set(projectDescriptor); task.getLaunchMode().set(launchMode); task.getOriginalClasspath().setFrom(classpath.getOriginalRuntimeClasspathAsInput()); task.getAppClasspath().configureFrom(classpath.getRuntimeConfigurationWithoutResolvingDeployment()); task.getPlatformConfiguration().configureFrom(classpath.getPlatformConfiguration()); task.getDeploymentClasspath().configureFrom(classpath.getDeploymentConfiguration()); - task.getDeploymentResolvedWorkaround().from(classpath.getDeploymentConfiguration().getIncoming().getFiles()); + if (conditionalExtensions.get()) { + task.getDeploymentResolvedWorkaround().from(classpath.getDeploymentConfiguration().getIncoming().getFiles()); + } task.getPlatformImportProperties().set(classpath.getPlatformImportsWithoutResolvingPlatform().getPlatformProperties()); task.getApplicationModel().set(project.getLayout().getBuildDirectory().file(quarkusModelFile)); } diff --git a/devtools/gradle/gradle-application-plugin/src/main/java/io/quarkus/gradle/extension/QuarkusPluginExtension.java b/devtools/gradle/gradle-application-plugin/src/main/java/io/quarkus/gradle/extension/QuarkusPluginExtension.java index 7e45c652dbcf4..74ee40bc33114 100644 --- a/devtools/gradle/gradle-application-plugin/src/main/java/io/quarkus/gradle/extension/QuarkusPluginExtension.java +++ b/devtools/gradle/gradle-application-plugin/src/main/java/io/quarkus/gradle/extension/QuarkusPluginExtension.java @@ -48,6 +48,7 @@ public abstract class QuarkusPluginExtension extends AbstractQuarkusExtension { private final Property cacheLargeArtifacts; private final Property cleanupBuildOutput; + private final Property conditionalExtensions; public QuarkusPluginExtension(Project project) { super(project); @@ -56,6 +57,8 @@ public QuarkusPluginExtension(Project project) { .convention(true); this.cacheLargeArtifacts = project.getObjects().property(Boolean.class) .convention(!System.getenv().containsKey("CI")); + this.conditionalExtensions = project.getObjects().property(Boolean.class) + .convention(false); this.sourceSetExtension = new SourceSetExtension(); } @@ -130,6 +133,10 @@ public Property getCleanupBuildOutput() { return cleanupBuildOutput; } + public Property getConditionalExtensions() { + return conditionalExtensions; + } + public void setCleanupBuildOutput(boolean cleanupBuildOutput) { this.cleanupBuildOutput.set(cleanupBuildOutput); } diff --git a/devtools/gradle/gradle-application-plugin/src/main/java/io/quarkus/gradle/tasks/QuarkusApplicationModelTask.java b/devtools/gradle/gradle-application-plugin/src/main/java/io/quarkus/gradle/tasks/QuarkusApplicationModelTask.java index c505daef136b9..e9f445efa8a8e 100644 --- a/devtools/gradle/gradle-application-plugin/src/main/java/io/quarkus/gradle/tasks/QuarkusApplicationModelTask.java +++ b/devtools/gradle/gradle-application-plugin/src/main/java/io/quarkus/gradle/tasks/QuarkusApplicationModelTask.java @@ -52,6 +52,7 @@ import org.gradle.api.tasks.InputFiles; import org.gradle.api.tasks.Internal; import org.gradle.api.tasks.Nested; +import org.gradle.api.tasks.Optional; import org.gradle.api.tasks.OutputFile; import org.gradle.api.tasks.SourceSet; import org.gradle.api.tasks.TaskAction; @@ -109,6 +110,7 @@ public abstract class QuarkusApplicationModelTask extends DefaultTask { public abstract ConfigurableFileCollection getOriginalClasspath(); @InputFiles + @Optional public abstract ConfigurableFileCollection getDeploymentResolvedWorkaround(); @Nested diff --git a/integration-tests/gradle/src/main/resources/conditional-test-project/runner/build.gradle b/integration-tests/gradle/src/main/resources/conditional-test-project/runner/build.gradle index e62a8d1c3476b..0368bea9993b7 100644 --- a/integration-tests/gradle/src/main/resources/conditional-test-project/runner/build.gradle +++ b/integration-tests/gradle/src/main/resources/conditional-test-project/runner/build.gradle @@ -26,3 +26,7 @@ dependencies { testImplementation 'io.quarkus:quarkus-junit5' testImplementation 'io.rest-assured:rest-assured' } + +quarkus { + conditionalExtensions = true +} diff --git a/integration-tests/gradle/src/main/resources/conditional-test-project/scenario-two/build.gradle b/integration-tests/gradle/src/main/resources/conditional-test-project/scenario-two/build.gradle index 70526b6fb7c89..60f39ba9a68c5 100644 --- a/integration-tests/gradle/src/main/resources/conditional-test-project/scenario-two/build.gradle +++ b/integration-tests/gradle/src/main/resources/conditional-test-project/scenario-two/build.gradle @@ -26,3 +26,7 @@ dependencies { testImplementation 'io.quarkus:quarkus-junit5' testImplementation 'io.rest-assured:rest-assured' } + +quarkus { + conditionalExtensions = true +}