Build.version
Med hjälp av MANIFEST
<build><plugins><plugin> <groupid>org.codehaus.mojo</groupid> <artifactid>maven-buildnumber-plugin</artifactid> <version>0.9.6</version> <executions> <execution> <phase>validate</phase> <goals> <goal>create</goal> </goals> </execution> </executions> </plugin> </plugins></build>
Denna plugin kräver att man satt upp SCM ordentligt så att versionnummer kan hämtas därifrån!
<build><plugins><plugin> <groupid>org.apache.maven.plugins</groupid> <artifactid>maven-war-plugin</artifactid> <version>2.0</version> <configuration> <archive> <manifestentries> <implementation -Build>${buildNumber}</implementation> </manifestentries> </archive> </configuration> </plugin> </plugins></build>
private String readBuildNumber(ServletContext servletContext) { try { URL resource = servletContext.getResource("/META-INF/MANIFEST.MF"); InputStream manifestStream = resource.openStream(); Manifest mf = new Manifest(manifestStream); Attributes atts = mf.getMainAttributes(); String value = atts.getValue("Implementation-Build"); if (value == null) { throw new IllegalArgumentException("Implementation-Build attribute is not set in MANIFEST " + resource.toExternalForm()); } manifestStream.close(); return value; } catch (Exception e) { throw new IllegalStateException("Failed to read Implementation-Build attribute from MANIFEST.MF"); } }
Eller som vanlig resource (properties)
<build> <resources> <resource> <directory>src/main/resources</directory> <filtering>true</filtering> </resource> </resources> </build>
