Defining System Properties in Spring Boot Plugin

谁都会走 提交于 2019-12-02 07:52:42

问题


I would like to specify some system properties in my applicatio (deterined at compile time).

I am using the spring boot maven plugin to compile

Currently, according to this questions: Specify system property to Maven project I tried the following setup (however this does not work as it is for a different plugin)

    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <configuration>
                <mainClass>application.boot.AppStarter</mainClass>
                <systemProperties>
                    <systemProperty>
                        <name>application.version</name>
                        <value>${application.version}</value>
                    </systemProperty>
                    <systemProperty>
                        <name>release.date</name>
                        <value>${timestamp}</value>
                    </systemProperty>
                </systemProperties> 
            </configuration>
            <executions>
                <execution>
                    <goals>
                        <goal>repackage</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>

How can i specify the properties in this plugin?


回答1:


Java system properties which you add are only accessible by the process they are added to.So even if you manage to add some system properties during the Maven build, it will no longer be there when the build is done.

What will happen if you distribute your jar to someone else. How do you expect these properties to be available?

Solution

Refer this post to see how to access the artifactId and version at runtime In a similar fashion you can add the timestamp entry as well to the src/main/resources/project.properties

buildTimestamp=${timestamp}

timestamp is not a pre-defined property like project.version or project.artifactId.So you will have to set extract the timestamp from the Maven property ${maven.build.timestamp} and set it as value to your timestamp property. This is already answered in this question.



来源:https://stackoverflow.com/questions/26574004/defining-system-properties-in-spring-boot-plugin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!