How to access maven.build.timestamp for resource filtering

前端 未结 4 552
北荒
北荒 2020-12-02 08:20

I am using maven 3.0.4 and would like to make the build timestamp accessible to my application. For this, I\'m putting a placeholder in a .properties file and l

4条回答
  •  南笙
    南笙 (楼主)
    2020-12-02 09:00

    Adding Maven properties at the pom project level doesn't take into account correct local Timezone, so timestamp may appear wrong :

    ${maven.build.timestamp}
    

    Using the build-helper-maven-plugin applies the correct timezone and current daylight saving to the timestamp :

    
        
            
                org.codehaus.mojo
                build-helper-maven-plugin
                1.9.1
                
                    
                        timestamp-property
                        
                            timestamp-property
                        
                        
                            timestamp
                            yyyy-MM-dd HH:mm:ss
                            Europe/Zurich
                        
                    
                
            
         
         
             
                 src/main/resources
                 true
             
         
     
    

    When packaging, Maven will replace any token timestamp in /resources folder, e.g. resources/version.properties :

    build.timestamp=${timestamp}

    You can then load this properties file in your Application.

提交回复
热议问题