Output system time to MANIFEST.MF with Maven

Java web project deployed with Maven in MANIFEST.MF file "When did you compile?" I was asked to output, so I checked it, so make a note.

environment

Requirements

--Output the system time when Maven is executed to MANIFEST.MF in the jar file.

Somehow sticking to it.

--Do not use AntRun Plugin. I don't want to build build.xml. --I don't want to write code.

manner

use maven.build.timestamp

First, how to use the property maven.build.timestamp prepared by Maven. See below. http://vbnmkyoto.blogspot.com/

pom.xml(Excerpt)


<plugin>
	<groupId>org.apache.maven.plugins</groupId>
	<artifactId>maven-jar-plugin</artifactId>
	<version>3.1.0</version>
	<configuration>
		<archive>
			<manifestEntries>
				<Build-Timestamp>${maven.build.timestamp}</Build-Timestamp>
			</manifestEntries>
		</archive>
	</configuration>
</plugin>

To change the format, specify the format with the maven.build.timestamp.format property.

pom.xml(Excerpt)


<properties>
	<maven.build.timestamp.format>yyyyMMhhmmss</maven.build.timestamp.format>
</properties>

If you do this, MANIFEST.MF will appear like this.

MANIFEST.MF


Build-Timestamp:20181129115959

Rakuchin ... But in Maven 3.2.2 or later, the output time is UTC. https://issues.apache.org/jira/browse/MNG-5452 It is inconvenient to work normally in Japan. I wish I could set the time zone, but I couldn't find anything like that.

Use Build Helper Maven Plugin

I searched for something else like that and tried using the Build Helper Maven Plugin. See below. https://stackoverflow.com/questions/28281988/how-to-have-maven-show-local-timezone-in-maven-build-timestamp

pom.xml(Excerpt)


<plugin>
	<groupId>org.codehaus.mojo</groupId>
	<artifactId>build-helper-maven-plugin</artifactId>
	<version>3.0.0</version>
	<executions>
		<execution>
			<id>timestamp-property</id>
			<goals>
				<goal>timestamp-property</goal>
			</goals>
			<configuration>
				<name>build.time</name>
				<pattern>yyyyMMddHHmmss</pattern>
				<locale>ja_JP</locale>
				<timeZone>Asia/Tokyo</timeZone>
			</configuration>
		</execution>
	</executions>
</plugin>

Set the setting value of name in the description of the output part.

pom.xml(Excerpt)


<plugin>
	<groupId>org.apache.maven.plugins</groupId>
	<artifactId>maven-jar-plugin</artifactId>
	<version>3.1.0</version>
	<configuration>
		<archive>
			<manifestEntries>
				<Build-Timestamp>${build.time}</Build-Timestamp>
			</manifestEntries>
		</archive>
	</configuration>
</plugin>

Now, the build execution time according to Japan time is output to MANIFEST.MF.

reference

https://www.mojohaus.org/build-helper-maven-plugin/usage.html It seems to be convenient, so you may want to check it out a little more.

Recommended Posts

Output system time to MANIFEST.MF with Maven
Output log to external file with slf4j + logback with Maven
How to set JAVA_HOME with Maven appassembler-maven-plugin
Deploy Java web app to Azure with maven
I tried to read and output CSV with Outsystems
How to output standard from an array with forEach
How to boot by environment with Spring Boot of Maven
How to enable submit button every time with jquery
Whether to make the server side at the time of system rebuild with Kotlin or Java
Output FizzBuzz with stream
Output embedded Tomcat access log to standard output with Spring Boot
Output time stamp for humans with JSON Layout of log4j2
How to get values in real time with TextWatcher (Android)
Sample code to parse date and time with Java SimpleDateFormat
Set watermark to be output only when printing with iText
Flow until output table data to view with Spring Boot
Even in Java, I want to output true with a == 1 && a == 2 && a == 3
Now is the time to get started with the Stream API
[Java] I want to test standard input & standard output with JUnit