From b6324cd1b535df6dd3fbaa9c5c9ac314aa4d1187 Mon Sep 17 00:00:00 2001 From: Inaki Villar Date: Fri, 8 Nov 2024 15:24:12 -0800 Subject: [PATCH] declaring explicitly the build service in the QuarkusBuildTask --- .../java/io/quarkus/gradle/QuarkusPlugin.java | 33 ++-- .../gradle/tasks/QuarkusBuildTask.java | 6 +- .../build.gradle.kts | 15 ++ .../gradle.properties | 4 + .../modA/build.gradle.kts | 16 ++ .../modB/.dockerignore | 5 + .../modB/build.gradle.kts | 15 ++ .../main/java/org/acme/GreetingResource.java | 16 ++ .../resources/META-INF/resources/index.html | 182 ++++++++++++++++++ .../src/main/resources/application.properties | 0 .../org/acme/NativeGreetingResourceIT.java | 9 + .../java/org/acme/GreetingResourceTest.java | 21 ++ .../settings.gradle.kts | 23 +++ .../QuarkusAppliedToMultipleModulesTest.java | 18 ++ 14 files changed, 345 insertions(+), 18 deletions(-) create mode 100644 integration-tests/gradle/src/main/resources/quarkus-plugin-in-multiple-modules/build.gradle.kts create mode 100644 integration-tests/gradle/src/main/resources/quarkus-plugin-in-multiple-modules/gradle.properties create mode 100644 integration-tests/gradle/src/main/resources/quarkus-plugin-in-multiple-modules/modA/build.gradle.kts create mode 100644 integration-tests/gradle/src/main/resources/quarkus-plugin-in-multiple-modules/modB/.dockerignore create mode 100644 integration-tests/gradle/src/main/resources/quarkus-plugin-in-multiple-modules/modB/build.gradle.kts create mode 100644 integration-tests/gradle/src/main/resources/quarkus-plugin-in-multiple-modules/modB/src/main/java/org/acme/GreetingResource.java create mode 100644 integration-tests/gradle/src/main/resources/quarkus-plugin-in-multiple-modules/modB/src/main/resources/META-INF/resources/index.html create mode 100644 integration-tests/gradle/src/main/resources/quarkus-plugin-in-multiple-modules/modB/src/main/resources/application.properties create mode 100644 integration-tests/gradle/src/main/resources/quarkus-plugin-in-multiple-modules/modB/src/native-test/java/org/acme/NativeGreetingResourceIT.java create mode 100644 integration-tests/gradle/src/main/resources/quarkus-plugin-in-multiple-modules/modB/src/test/java/org/acme/GreetingResourceTest.java create mode 100644 integration-tests/gradle/src/main/resources/quarkus-plugin-in-multiple-modules/settings.gradle.kts create mode 100644 integration-tests/gradle/src/test/java/io/quarkus/gradle/QuarkusAppliedToMultipleModulesTest.java 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 15d58e6c94f71..8e6b0a97d9d01 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 @@ -139,10 +139,6 @@ public void apply(Project project) { // Apply the `java` plugin project.getPluginManager().apply(JavaPlugin.class); - project.getGradle().getSharedServices().registerIfAbsent("forcedPropertiesService", ForcedPropertieBuildService.class, - spec -> { - }); - registerModel(); // register extension @@ -156,7 +152,11 @@ public void apply(Project project) { private void registerTasks(Project project, QuarkusPluginExtension quarkusExt) { TaskContainer tasks = project.getTasks(); - + String forcedPropertiesService = String.format("forcedPropertiesService-%s", project.getName()); + Provider serviceProvider = project.getGradle().getSharedServices().registerIfAbsent( + forcedPropertiesService, ForcedPropertieBuildService.class, + spec -> { + }); final String devRuntimeConfigName = ApplicationDeploymentClasspathBuilder .getBaseRuntimeConfigName(LaunchMode.DEVELOPMENT); final Configuration devRuntimeDependencies = project.getConfigurations().maybeCreate(devRuntimeConfigName); @@ -236,14 +236,14 @@ private void registerTasks(Project project, QuarkusPluginExtension quarkusExt) { }); tasks.register(QUARKUS_SHOW_EFFECTIVE_CONFIG_TASK_NAME, QuarkusShowEffectiveConfig.class, task -> { - configureQuarkusBuildTask(project, quarkusExt, task, quarkusBuildAppModelTask); + configureQuarkusBuildTask(project, task, quarkusBuildAppModelTask, serviceProvider); task.setDescription("Show effective Quarkus build configuration."); }); TaskProvider quarkusBuildDependencies = tasks.register(QUARKUS_BUILD_DEP_TASK_NAME, QuarkusBuildDependencies.class, task -> { - configureQuarkusBuildTask(project, quarkusExt, task, quarkusBuildAppModelTask); + configureQuarkusBuildTask(project, task, quarkusBuildAppModelTask, serviceProvider); task.getOutputs().doNotCacheIf("Dependencies are never cached", t -> true); task.getApplicationModel() @@ -256,7 +256,7 @@ private void registerTasks(Project project, QuarkusPluginExtension quarkusExt) { TaskProvider quarkusBuildCacheableAppParts = tasks.register( QUARKUS_BUILD_APP_PARTS_TASK_NAME, QuarkusBuildCacheableAppParts.class, task -> { - configureQuarkusBuildTask(project, quarkusExt, task, quarkusBuildAppModelTask); + configureQuarkusBuildTask(project, task, quarkusBuildAppModelTask, serviceProvider); task.dependsOn(quarkusGenerateCode); task.getOutputs().doNotCacheIf( "Not adding uber-jars, native binaries and mutable-jar package type to Gradle " + @@ -272,7 +272,7 @@ public boolean isSatisfiedBy(Task t) { }); TaskProvider quarkusBuild = tasks.register(QUARKUS_BUILD_TASK_NAME, QuarkusBuild.class, build -> { - configureQuarkusBuildTask(project, quarkusExt, build, quarkusBuildAppModelTask); + configureQuarkusBuildTask(project, build, quarkusBuildAppModelTask, serviceProvider); build.dependsOn(quarkusBuildDependencies, quarkusBuildCacheableAppParts); build.getOutputs().doNotCacheIf( "Only collects and combines the outputs of " + QUARKUS_BUILD_APP_PARTS_TASK_NAME + " and " @@ -296,7 +296,7 @@ public boolean isSatisfiedBy(Task t) { tasks.register(IMAGE_BUILD_TASK_NAME, ImageBuild.class, task -> { task.dependsOn(quarkusRequiredExtension); - configureQuarkusBuildTask(project, quarkusExt, task, quarkusBuildAppModelTask); + configureQuarkusBuildTask(project, task, quarkusBuildAppModelTask, serviceProvider); task.getBuilderName().set(quarkusRequiredExtension.flatMap(ImageCheckRequirementsTask::getOutputFile)); task.getOutputs().doNotCacheIf("Dependencies are never cached", t -> true); task.getApplicationModel() @@ -306,7 +306,7 @@ public boolean isSatisfiedBy(Task t) { tasks.register(IMAGE_PUSH_TASK_NAME, ImagePush.class, task -> { task.dependsOn(quarkusRequiredExtension); - configureQuarkusBuildTask(project, quarkusExt, task, quarkusBuildAppModelTask); + configureQuarkusBuildTask(project, task, quarkusBuildAppModelTask, serviceProvider); task.getBuilderName().set(quarkusRequiredExtension.flatMap(ImageCheckRequirementsTask::getOutputFile)); task.getOutputs().doNotCacheIf("Dependencies are never cached", t -> true); task.getApplicationModel() @@ -315,7 +315,7 @@ public boolean isSatisfiedBy(Task t) { }); tasks.register(DEPLOY_TASK_NAME, Deploy.class, task -> { - configureQuarkusBuildTask(project, quarkusExt, task, quarkusBuildAppModelTask); + configureQuarkusBuildTask(project, task, quarkusBuildAppModelTask, serviceProvider); task.getOutputs().doNotCacheIf("Dependencies are never cached", t -> true); task.getApplicationModel() .set(quarkusGenerateAppModelTask.flatMap(QuarkusApplicationModelTask::getApplicationModel)); @@ -326,7 +326,7 @@ public boolean isSatisfiedBy(Task t) { quarkusExt); TaskProvider quarkusRun = tasks.register(QUARKUS_RUN_TASK_NAME, QuarkusRun.class, build -> { - configureQuarkusBuildTask(project, quarkusExt, build, quarkusBuildAppModelTask); + configureQuarkusBuildTask(project, build, quarkusBuildAppModelTask, serviceProvider); build.getOutputs().doNotCacheIf("Dependencies are never cached", t -> true); build.getApplicationModel() .set(quarkusGenerateAppModelTask.flatMap(QuarkusApplicationModelTask::getApplicationModel)); @@ -527,10 +527,13 @@ private static void configureApplicationModelTask(Project project, QuarkusApplic task.getApplicationModel().set(project.getLayout().getBuildDirectory().file(quarkusModelFile)); } - private static void configureQuarkusBuildTask(Project project, QuarkusPluginExtension quarkusExt, QuarkusBuildTask task, - TaskProvider quarkusGenerateAppModelTask) { + private static void configureQuarkusBuildTask(Project project, QuarkusBuildTask task, + TaskProvider quarkusGenerateAppModelTask, + Provider serviceProvider) { task.getApplicationModel().set(quarkusGenerateAppModelTask.flatMap(QuarkusApplicationModelTask::getApplicationModel)); SourceSet mainSourceSet = getSourceSet(project, SourceSet.MAIN_SOURCE_SET_NAME); + task.getAdditionalForcedProperties().set(serviceProvider); + task.usesService(serviceProvider); task.setCompileClasspath(mainSourceSet.getCompileClasspath().plus(mainSourceSet.getRuntimeClasspath()) .plus(mainSourceSet.getAnnotationProcessorPath()) .plus(mainSourceSet.getResources())); diff --git a/devtools/gradle/gradle-application-plugin/src/main/java/io/quarkus/gradle/tasks/QuarkusBuildTask.java b/devtools/gradle/gradle-application-plugin/src/main/java/io/quarkus/gradle/tasks/QuarkusBuildTask.java index a67d05456d118..f5f75c86681ed 100644 --- a/devtools/gradle/gradle-application-plugin/src/main/java/io/quarkus/gradle/tasks/QuarkusBuildTask.java +++ b/devtools/gradle/gradle-application-plugin/src/main/java/io/quarkus/gradle/tasks/QuarkusBuildTask.java @@ -17,10 +17,10 @@ import org.gradle.api.file.RegularFileProperty; import org.gradle.api.logging.LogLevel; import org.gradle.api.provider.Property; -import org.gradle.api.services.ServiceReference; import org.gradle.api.tasks.Classpath; import org.gradle.api.tasks.Input; import org.gradle.api.tasks.InputFile; +import org.gradle.api.tasks.Internal; import org.gradle.api.tasks.Nested; import org.gradle.api.tasks.PathSensitive; import org.gradle.api.tasks.PathSensitivity; @@ -48,8 +48,8 @@ public abstract class QuarkusBuildTask extends QuarkusTask { static final String NATIVE_SOURCES = "native-sources"; private final QuarkusPluginExtensionView extensionView; - @ServiceReference("forcedPropertiesService") - abstract Property getAdditionalForcedProperties(); + @Internal + public abstract Property getAdditionalForcedProperties(); QuarkusBuildTask(String description, boolean compatible) { super(description, compatible); diff --git a/integration-tests/gradle/src/main/resources/quarkus-plugin-in-multiple-modules/build.gradle.kts b/integration-tests/gradle/src/main/resources/quarkus-plugin-in-multiple-modules/build.gradle.kts new file mode 100644 index 0000000000000..c6260a98129f5 --- /dev/null +++ b/integration-tests/gradle/src/main/resources/quarkus-plugin-in-multiple-modules/build.gradle.kts @@ -0,0 +1,15 @@ +allprojects { + + group = "org.acme" + version = "1.0.0-SNAPSHOT" + + repositories { + mavenLocal { + content { + includeGroupByRegex("io.quarkus.*") + includeGroup("org.hibernate.orm") + } + } + mavenCentral() + } +} diff --git a/integration-tests/gradle/src/main/resources/quarkus-plugin-in-multiple-modules/gradle.properties b/integration-tests/gradle/src/main/resources/quarkus-plugin-in-multiple-modules/gradle.properties new file mode 100644 index 0000000000000..0b9b349582ac3 --- /dev/null +++ b/integration-tests/gradle/src/main/resources/quarkus-plugin-in-multiple-modules/gradle.properties @@ -0,0 +1,4 @@ +# Gradle properties + +quarkusPlatformArtifactId=quarkus-bom +quarkusPlatformGroupId=io.quarkus diff --git a/integration-tests/gradle/src/main/resources/quarkus-plugin-in-multiple-modules/modA/build.gradle.kts b/integration-tests/gradle/src/main/resources/quarkus-plugin-in-multiple-modules/modA/build.gradle.kts new file mode 100644 index 0000000000000..f9b4541bc516f --- /dev/null +++ b/integration-tests/gradle/src/main/resources/quarkus-plugin-in-multiple-modules/modA/build.gradle.kts @@ -0,0 +1,16 @@ +plugins { + `java-library` + id("io.quarkus") + id("com.github.ben-manes.versions") version "0.51.0" + +} +val quarkusPlatformGroupId: String by project +val quarkusPlatformArtifactId: String by project +val quarkusPlatformVersion: String by project + +dependencies { + implementation(enforcedPlatform("$quarkusPlatformGroupId:$quarkusPlatformArtifactId:$quarkusPlatformVersion")) + api("io.quarkus:quarkus-resteasy") + api("io.quarkus:quarkus-resteasy-jackson") + api("io.quarkus:quarkus-arc") +} diff --git a/integration-tests/gradle/src/main/resources/quarkus-plugin-in-multiple-modules/modB/.dockerignore b/integration-tests/gradle/src/main/resources/quarkus-plugin-in-multiple-modules/modB/.dockerignore new file mode 100644 index 0000000000000..4361d2fb38ddc --- /dev/null +++ b/integration-tests/gradle/src/main/resources/quarkus-plugin-in-multiple-modules/modB/.dockerignore @@ -0,0 +1,5 @@ +* +!build/*-runner +!build/*-runner.jar +!build/lib/* +!build/quarkus-app/* \ No newline at end of file diff --git a/integration-tests/gradle/src/main/resources/quarkus-plugin-in-multiple-modules/modB/build.gradle.kts b/integration-tests/gradle/src/main/resources/quarkus-plugin-in-multiple-modules/modB/build.gradle.kts new file mode 100644 index 0000000000000..7db659d8359d7 --- /dev/null +++ b/integration-tests/gradle/src/main/resources/quarkus-plugin-in-multiple-modules/modB/build.gradle.kts @@ -0,0 +1,15 @@ +plugins { + `java-library` + id("io.quarkus") + id("com.github.ben-manes.versions") version "0.51.0" +} +val quarkusPlatformGroupId: String by project +val quarkusPlatformArtifactId: String by project +val quarkusPlatformVersion: String by project + +val javaVersion = "17" + +dependencies { + implementation(enforcedPlatform("$quarkusPlatformGroupId:$quarkusPlatformArtifactId:$quarkusPlatformVersion")) + implementation(project(":modA")) +} diff --git a/integration-tests/gradle/src/main/resources/quarkus-plugin-in-multiple-modules/modB/src/main/java/org/acme/GreetingResource.java b/integration-tests/gradle/src/main/resources/quarkus-plugin-in-multiple-modules/modB/src/main/java/org/acme/GreetingResource.java new file mode 100644 index 0000000000000..e5f5b6ca5694b --- /dev/null +++ b/integration-tests/gradle/src/main/resources/quarkus-plugin-in-multiple-modules/modB/src/main/java/org/acme/GreetingResource.java @@ -0,0 +1,16 @@ +package org.acme; + +import jakarta.ws.rs.GET; +import jakarta.ws.rs.Path; +import jakarta.ws.rs.Produces; +import jakarta.ws.rs.core.MediaType; + +@Path("/hello") +public class GreetingResource { + + @GET + @Produces(MediaType.TEXT_PLAIN) + public String hello() { + return "foo bar"; + } +} diff --git a/integration-tests/gradle/src/main/resources/quarkus-plugin-in-multiple-modules/modB/src/main/resources/META-INF/resources/index.html b/integration-tests/gradle/src/main/resources/quarkus-plugin-in-multiple-modules/modB/src/main/resources/META-INF/resources/index.html new file mode 100644 index 0000000000000..abf53e21ca41b --- /dev/null +++ b/integration-tests/gradle/src/main/resources/quarkus-plugin-in-multiple-modules/modB/src/main/resources/META-INF/resources/index.html @@ -0,0 +1,182 @@ + + + + + code-with-quarkus - 1.0.0-SNAPSHOT + + + + + + +
+
+

Congratulations, you have created a new Quarkus cloud application.

+ +

What is this page?

+ +

This page is served by Quarkus. The source is in + src/main/resources/META-INF/resources/index.html.

+ +

What are your next steps?

+ +

If not already done, run the application in dev mode using: ./gradlew quarkusDev. +

+
    +
  • Your static assets are located in src/main/resources/META-INF/resources.
  • +
  • Configure your application in src/main/resources/application.properties.
  • +
  • Quarkus now ships with a Dev UI (available in dev mode only)
  • +
  • Play with the getting started example code located in src/main/java:
  • +
+
+

RESTEasy JAX-RS example

+

REST is easy peasy with this Hello World RESTEasy resource.

+

@Path: /hello-resteasy

+

Related guide section...

+
+
+

RESTEasy JSON serialisation using Jackson

+

This example demonstrate RESTEasy JSON serialisation by letting you list, add and remove quark types from a list. Quarked!

+

@Path: /resteasy-jackson/quarks/

+

Related guide section...

+
+ +
+
+
+

Application

+
    +
  • GroupId: org.acme
  • +
  • ArtifactId: code-with-quarkus
  • +
  • Version: 1.0.0-SNAPSHOT
  • +
  • Quarkus Version: 1.12.2.Final
  • +
+
+
+

Do you like Quarkus?

+
    +
  • Go give it a star on GitHub.
  • +
+
+
+

Selected extensions guides

+ +
+ +
+
+ + \ No newline at end of file diff --git a/integration-tests/gradle/src/main/resources/quarkus-plugin-in-multiple-modules/modB/src/main/resources/application.properties b/integration-tests/gradle/src/main/resources/quarkus-plugin-in-multiple-modules/modB/src/main/resources/application.properties new file mode 100644 index 0000000000000..e69de29bb2d1d diff --git a/integration-tests/gradle/src/main/resources/quarkus-plugin-in-multiple-modules/modB/src/native-test/java/org/acme/NativeGreetingResourceIT.java b/integration-tests/gradle/src/main/resources/quarkus-plugin-in-multiple-modules/modB/src/native-test/java/org/acme/NativeGreetingResourceIT.java new file mode 100644 index 0000000000000..909dc2e828c69 --- /dev/null +++ b/integration-tests/gradle/src/main/resources/quarkus-plugin-in-multiple-modules/modB/src/native-test/java/org/acme/NativeGreetingResourceIT.java @@ -0,0 +1,9 @@ +package org.acme; + +import io.quarkus.test.junit.QuarkusIntegrationTest; + +@QuarkusIntegrationTest +public class NativeGreetingResourceIT extends GreetingResourceTest { + + // Execute the same tests but in native mode. +} diff --git a/integration-tests/gradle/src/main/resources/quarkus-plugin-in-multiple-modules/modB/src/test/java/org/acme/GreetingResourceTest.java b/integration-tests/gradle/src/main/resources/quarkus-plugin-in-multiple-modules/modB/src/test/java/org/acme/GreetingResourceTest.java new file mode 100644 index 0000000000000..c832dcf849e72 --- /dev/null +++ b/integration-tests/gradle/src/main/resources/quarkus-plugin-in-multiple-modules/modB/src/test/java/org/acme/GreetingResourceTest.java @@ -0,0 +1,21 @@ +package org.acme; + +import io.quarkus.test.junit.QuarkusTest; +import org.junit.jupiter.api.Test; + +import static io.restassured.RestAssured.given; +import static org.hamcrest.CoreMatchers.is; + +@QuarkusTest +public class GreetingResourceTest { + + @Test + public void testHelloEndpoint() { + given() + .when().get("/hello") + .then() + .statusCode(200) + .body(is("foo bar")); + } + +} \ No newline at end of file diff --git a/integration-tests/gradle/src/main/resources/quarkus-plugin-in-multiple-modules/settings.gradle.kts b/integration-tests/gradle/src/main/resources/quarkus-plugin-in-multiple-modules/settings.gradle.kts new file mode 100644 index 0000000000000..b93cd3eb8bc81 --- /dev/null +++ b/integration-tests/gradle/src/main/resources/quarkus-plugin-in-multiple-modules/settings.gradle.kts @@ -0,0 +1,23 @@ +pluginManagement { + val quarkusPluginVersion: String by settings + repositories { + mavenLocal { + content { + includeGroupByRegex("io.quarkus.*") + includeGroup("org.hibernate.orm") + } + } + mavenCentral() + gradlePluginPortal() + } + plugins { + id("io.quarkus") version quarkusPluginVersion + } +} + +rootProject.name="code-with-quarkus" + +include( + "modA", + "modB" +) diff --git a/integration-tests/gradle/src/test/java/io/quarkus/gradle/QuarkusAppliedToMultipleModulesTest.java b/integration-tests/gradle/src/test/java/io/quarkus/gradle/QuarkusAppliedToMultipleModulesTest.java new file mode 100644 index 0000000000000..849ed8abd92b7 --- /dev/null +++ b/integration-tests/gradle/src/test/java/io/quarkus/gradle/QuarkusAppliedToMultipleModulesTest.java @@ -0,0 +1,18 @@ +package io.quarkus.gradle; + +import static org.assertj.core.api.Assertions.assertThat; + +import java.io.File; + +import org.junit.jupiter.api.Test; + +public class QuarkusAppliedToMultipleModulesTest extends QuarkusGradleWrapperTestBase { + + @Test + public void testBasicMultiModuleBuild() throws Exception { + final File projectDir = getProjectDir("quarkus-plugin-in-multiple-modules"); + final BuildResult build = runGradleWrapper(projectDir, "clean", "quarkusBuild"); + assertThat(BuildResult.isSuccessful(build.getTasks().get(":modA:quarkusBuild"))).isTrue(); + assertThat(BuildResult.isSuccessful(build.getTasks().get(":modB:quarkusBuild"))).isTrue(); + } +}