diff --git a/independent-projects/bootstrap/core/src/main/java/io/quarkus/bootstrap/app/QuarkusBootstrap.java b/independent-projects/bootstrap/core/src/main/java/io/quarkus/bootstrap/app/QuarkusBootstrap.java index f4e5ab0a46a2a1..9b3ac791e99c54 100644 --- a/independent-projects/bootstrap/core/src/main/java/io/quarkus/bootstrap/app/QuarkusBootstrap.java +++ b/independent-projects/bootstrap/core/src/main/java/io/quarkus/bootstrap/app/QuarkusBootstrap.java @@ -102,7 +102,7 @@ private QuarkusBootstrap(Builder builder, ConfiguredClassLoading classLoadingCon this.additionalApplicationArchives = new ArrayList<>(builder.additionalApplicationArchives); this.excludeFromClassPath = new ArrayList<>(builder.excludeFromClassPath); this.projectRoot = builder.projectRoot != null ? builder.projectRoot.normalize() : null; - this.buildSystemProperties = builder.buildSystemProperties; + this.buildSystemProperties = new Properties(builder.buildSystemProperties); this.mode = builder.mode; this.offline = builder.offline; this.test = builder.test; @@ -159,7 +159,20 @@ public CuratedApplication bootstrap() throws BootstrapException { appModelFactory.setEnableClasspathCache(true); } } - return new CuratedApplication(this, appModelFactory.resolveAppModel(), classLoadingConfig); + CurationResult curationResult = appModelFactory.resolveAppModel(); + if (curationResult.getApplicationModel().getApplicationModule() != null + && curationResult.getApplicationModel().getApplicationModule().getId() != null) { + if (curationResult.getApplicationModel().getApplicationModule().getId().getArtifactId() != null) { + buildSystemProperties.putIfAbsent("quarkus.application.name", + curationResult.getApplicationModel().getApplicationModule().getId().getArtifactId()); + } + if (curationResult.getApplicationModel().getApplicationModule().getId().getVersion() != null) { + buildSystemProperties.putIfAbsent("quarkus.application.version", + curationResult.getApplicationModel().getApplicationModule().getId().getVersion()); + } + } + + return new CuratedApplication(this, curationResult, classLoadingConfig); } public static ConfiguredClassLoading createClassLoadingConfig(PathCollection applicationRoot, Mode mode, diff --git a/integration-tests/gradle/src/main/resources/basic-java-library-module/application/src/main/java/org/acme/ApplicationConfigResource.java b/integration-tests/gradle/src/main/resources/basic-java-library-module/application/src/main/java/org/acme/ApplicationConfigResource.java new file mode 100644 index 00000000000000..ca578869780f95 --- /dev/null +++ b/integration-tests/gradle/src/main/resources/basic-java-library-module/application/src/main/java/org/acme/ApplicationConfigResource.java @@ -0,0 +1,25 @@ +package org.acme; + + +import org.eclipse.microprofile.config.inject.ConfigProperty; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.core.MediaType; + +@Path("/app-config") +public class ApplicationConfigResource { + + @ConfigProperty(name = "quarkus.application.name") + String name; + + @ConfigProperty(name = "quarkus.application.version") + String version; + + @GET + @Produces(MediaType.TEXT_PLAIN) + public String hello() { + return String.format("%s:%s", name, version); + } +} diff --git a/integration-tests/gradle/src/main/resources/basic-java-library-module/application/src/test/java/org/acme/ApplicationConfigResourceTest.java b/integration-tests/gradle/src/main/resources/basic-java-library-module/application/src/test/java/org/acme/ApplicationConfigResourceTest.java new file mode 100644 index 00000000000000..0e54e2de32b434 --- /dev/null +++ b/integration-tests/gradle/src/main/resources/basic-java-library-module/application/src/test/java/org/acme/ApplicationConfigResourceTest.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 ApplicationConfigResourceTest { + + @Test + public void testAppConfigEndpoint() { + given() + .when().get("/app-config") + .then() + .statusCode(200) + .body(is("application:1.0.0-SNAPSHOT")); + } + +} \ No newline at end of file diff --git a/integration-tests/gradle/src/test/java/io/quarkus/gradle/ApplicationConfigurationTest.java b/integration-tests/gradle/src/test/java/io/quarkus/gradle/ApplicationConfigurationTest.java new file mode 100644 index 00000000000000..f44453718537c2 --- /dev/null +++ b/integration-tests/gradle/src/test/java/io/quarkus/gradle/ApplicationConfigurationTest.java @@ -0,0 +1,20 @@ +package io.quarkus.gradle; + +import static org.assertj.core.api.Assertions.assertThat; + +import java.io.File; + +import org.junit.jupiter.api.Test; + +public class ApplicationConfigurationTest extends QuarkusGradleWrapperTestBase { + + @Test + public void shouldSuccessfullyInjectApplicationConfigInTest() throws Exception { + File projectDir = getProjectDir("basic-java-library-module"); + + BuildResult testResult = runGradleWrapper(projectDir, "clean", ":application:test"); + + assertThat(testResult.getTasks().get(":application:test")).isEqualTo(BuildResult.SUCCESS_OUTCOME); + } + +}