Make application version and name available as runtime properties

Fixes: #6255

Co-authored-by: Guillaume Smet <guillaume.smet@gmail.com>
This commit is contained in:
Georgios Andrianakis
2019-12-19 12:39:50 +02:00
parent 7c017871d0
commit 6aee06ba92
4 changed files with 12 additions and 5 deletions

View File

@@ -1,8 +1,8 @@
package io.quarkus.deployment.steps;
import io.quarkus.deployment.ApplicationConfig;
import io.quarkus.deployment.annotations.BuildStep;
import io.quarkus.deployment.builditem.ApplicationInfoBuildItem;
import io.quarkus.runtime.ApplicationConfig;
public class ApplicationInfoBuildStep {

View File

@@ -97,6 +97,7 @@ public class RuntimeRunner implements Runnable, Closeable {
builder.setRoot(target);
builder.setClassLoader(loader);
builder.setLaunchMode(launchMode);
builder.setBuildSystemProperties(buildSystemProperties);
if (liveReloadState != null) {
builder.setLiveReloadState(liveReloadState);
}

View File

@@ -1,4 +1,4 @@
package io.quarkus.deployment;
package io.quarkus.runtime;
import java.util.Optional;
@@ -6,19 +6,19 @@ import io.quarkus.runtime.annotations.ConfigItem;
import io.quarkus.runtime.annotations.ConfigPhase;
import io.quarkus.runtime.annotations.ConfigRoot;
@ConfigRoot(phase = ConfigPhase.BUILD_TIME)
@ConfigRoot(phase = ConfigPhase.BUILD_AND_RUN_TIME_FIXED)
public class ApplicationConfig {
/**
* The name of the application.
* If not set, defaults to the name of the project.
* If not set, defaults to the name of the project (except for tests where it is not set at all).
*/
@ConfigItem
public Optional<String> name;
/**
* The version of the application.
* If not set, defaults to the version of the project
* If not set, defaults to the version of the project (except for tests where it is not set at all).
*/
@ConfigItem
public Optional<String> version;

View File

@@ -490,7 +490,13 @@ public class DevMojo extends AbstractMojo {
for (Map.Entry<Object, Object> e : System.getProperties().entrySet()) {
devModeContext.getSystemProperties().put(e.getKey().toString(), (String) e.getValue());
}
devModeContext.getBuildSystemProperties().putAll((Map) project.getProperties());
// this is a minor hack to allow ApplicationConfig to be populated with defaults
devModeContext.getBuildSystemProperties().putIfAbsent("quarkus.application.name", project.getArtifactId());
devModeContext.getBuildSystemProperties().putIfAbsent("quarkus.application.version", project.getVersion());
devModeContext.setSourceEncoding(getSourceEncoding());
devModeContext.setSourceJavaVersion(source);
devModeContext.setTargetJvmVersion(target);