Skip to content

Instantly share code, notes, and snippets.

@573
Last active December 14, 2015 15:38
Show Gist options
  • Save 573/5108969 to your computer and use it in GitHub Desktop.
Save 573/5108969 to your computer and use it in GitHub Desktop.
Play with maven2 and version numbering automagic ...

To deploy call...

The artifact is deployed "staged" - meaning first to your local file system into a folder you declare to be maven repository, this folder is given as command line parameter to maven:

-Drelease-repository-path=h:/.homedir/Asynchronous-Maven-2-Repository

where h:/.homedir/Asynchronous-Maven-2-Repository is the path to your local maven repository versionised with git. I use the "Parameter Name" / "Value" table in the Eclipse launch dialog (m2eclipse) instead of the -D switch.

To really deploy (for sharing with the public) you'll have to commit/push (git commands) the new state your maven repository (which at the same time is a git repository) has, to the git repository. So use one of that two commands from time to time to have new artifact versions remotely together with additional useful commit messages.

For time stamped builds...

To get the time-stamped jar file, you had to run mvn timestamp:create jar:jar. The buildnumber-maven-plugin I preferred to use earlier (with svn) doesn't yet work with git repositories to get it's required data so I temporary abandon this approach.

For further reading/trying...

For very good experience about integration maven 2 and github.com have a look at that pom and referred plugins please.

Repository Usage

This is how an initial artifact enrolled to this repository would look (for more information see here and the referred sites):

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>573</groupId>
    <artifactId>project-exercises-numbers-parent</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>pom</packaging>

    <name>Exercises in Mavenised Version Numbering, Parent Module</name>

    <description>
    Calling convention (MS windows example):
    -Drelease-repository-path=h:/.homedir/Asynchronous-Maven-2-Repository

    where h:/.homedir/Asynchronous-Maven-2-Repository is the path
    to your local maven repository versionised with git. I use the
    Parameter Name / Value table in Eclipse launch dialog (m2eclipse)
    instead of -D switch.
    </description>

    <repositories>
	    <repository>
		    <id>573-releases</id>
		    <name>Github repository for 573 Maven artifacts</name>
		    <url>http://github.com/573/Asynchronous-Maven-2-Repository/raw/master/releases</url>
		    <snapshots>
			    <enabled>false</enabled>
		    </snapshots>
	    </repository>
	    <repository>
		    <id>573-snapshots</id>
		    <name>Github repository for 573 Maven snapshot artifacts</name>
		    <url>http://github.com/573/Asynchronous-Maven-2-Repository/raw/master/snapshots</url>
		    <snapshots>
			    <enabled>true</enabled>
		    </snapshots>
	    </repository>
    </repositories>

    <distributionManagement>
	    <repository>
		    <id>573-releases</id>
		    <name />
		    <url>file://${release-repository-path}/releases</url>
	    </repository>
	    <snapshotRepository>
		    <id>573-snapshots</id>
		    <name />
		    <url>file://${release-repository-path}/snapshots</url>
		    <uniqueVersion>false</uniqueVersion>
	    </snapshotRepository>
	    <!--
		    <site> <id>573-sites</id> <name />
		    <url>dav:https://svn.xyz.com/project/maven-site</url> </site>
	    -->
    </distributionManagement>
</project>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>573</groupId>
<artifactId>play-with-version-numbering-automagic</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<name>Exercises in Mavenised Version Numbering, Parent Module</name>
<description />
<scm>
<connection>scm:git:git://github.com/573/play-with-version-numbering-automagic.git</connection>
<developerConnection>scm:git:[email protected]:573/play-with-version-numbering-automagic.git</developerConnection>
<url>http://github.com/573/play-with-version-numbering-automagic/tree/master/</url>
</scm>
<build>
<extensions>
<extension>
<groupId>org.apache.maven.scm</groupId>
<artifactId>maven-scm-provider-gitexe</artifactId>
<version>1.4</version>
</extension>
<extension>
<groupId>org.apache.maven.scm</groupId>
<artifactId>maven-scm-manager-plexus</artifactId>
<version>1.4</version>
</extension>
</extensions>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.3.1</version>
</plugin>
<plugin>
<groupId>com.keyboardsamurais.maven</groupId>
<artifactId>maven-timestamp-plugin</artifactId>
<version>0.1</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-scm-plugin</artifactId>
<version>1.4</version>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<addDefaultImplementationEntries>true
</addDefaultImplementationEntries>
</manifest>
<manifestEntries>
<Implementation-Build>${buildNumber}</Implementation-Build>
<buildtime>${timestamp}</buildtime>
<description>${project.description}</description>
</manifestEntries>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>com.keyboardsamurais.maven</groupId>
<artifactId>maven-timestamp-plugin</artifactId>
<configuration>
<propertyName>timestamp</propertyName>
<timestampPattern>EEE, d MMM yyyy HH:mm:ss Z</timestampPattern>
</configuration>
<executions>
<execution>
<goals>
<goal>create</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-scm-plugin</artifactId>
<configuration>
<goals>install</goals>
<checkoutDirectory>${project.basedir}</checkoutDirectory>
</configuration>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>573-releases</id>
<name>Github repository for 573 Maven artifacts</name>
<url>http://github.com/573/Asynchronous-Maven-2-Repository/raw/master/releases</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
<repository>
<id>573-snapshots</id>
<name>Github repository for 573 Maven snapshot artifacts</name>
<url>http://github.com/573/Asynchronous-Maven-2-Repository/raw/master/snapshots</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<issueManagement>
<system>github</system>
<url>http://github.com/573/play-with-version-numbering-automagic/issues#issue/</url>
</issueManagement>
<distributionManagement>
<repository>
<id>573-releases</id>
<name />
<url>file://${release-repository-path}/releases</url>
</repository>
<snapshotRepository>
<id>573-snapshots</id>
<name />
<url>file://${release-repository-path}/snapshots</url>
<uniqueVersion>false</uniqueVersion>
</snapshotRepository>
<!--
<site> <id>573-sites</id> <name />
<url>dav:https://svn.xyz.com/project/maven-site</url> </site>
-->
</distributionManagement>
<pluginRepositories>
<pluginRepository>
<id>maven-timestamp</id>
<url>
http://maven-timestamp-plugin.googlecode.com/svn/trunk/repository
</url>
</pluginRepository>
</pluginRepositories>
</project>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment