Skip to content

Introduce jgitver maven plugin in existing project

Matthieu Brouillard edited this page Dec 14, 2016 · 3 revisions

Introducing jgitver-maven-plugin into an existing project is easy.

Let's suppose you use SNAPSHOTS for your project and that your latest released version is 2.4.0 thus your master might be 2.4.1-SNAPSHOT (see bottom page for a project example).

Then introducing jgitver-maven-plugin is just few steps ahead:

  1. go to your project directory

    cd demo2

  2. create maven extension file to use jgitver-maven-plugin

    this step just consists in creating a .mvn directory whith an extensions.xml file, see README or use the following command:

    sh -c "$(wget https://raw.githubusercontent.com/jgitver/jgitver-maven-plugin/master/src/doc/scripts/install.sh -O -)"
    
  3. let's clarify that you now use jgitver-maven-plugin by forcing the version in POMs to 0

    mvn versions:set -DnewVersion=0 && mvn versions:commit
    
  4. let's commit the addition of jgitver-maven-plugin and the new version

    git add .mvn
    git add -u
    git commit -m "introduction of jgitver-maven-plugin, set version to 0"
    
  5. you're done

    mvn validate
    
    [INFO] Scanning for projects...
    [INFO] jgitver-maven-plugin is about to change project(s) version(s)
    [INFO]     fr.brouillard.jgitver.demos::demo2::0 -> 2.4.1-SNAPSHOT
    [INFO]                                                                         
    [INFO] ------------------------------------------------------------------------
    [INFO] Building demo2 2.4.1-SNAPSHOT
    [INFO] ------------------------------------------------------------------------
    [INFO] ------------------------------------------------------------------------
    [INFO] BUILD SUCCESS
    [INFO] ------------------------------------------------------------------------
    [INFO] Total time: 0.587 s
    [INFO] Finished at: 2016-12-14T20:42:54+01:00
    [INFO] Final Memory: 8M/198M
    [INFO] ------------------------------------------------------------------------
    

Project example

mvn archetype:generate -B \
  -DarchetypeCatalog=internal \
  -DarchetypeGroupId=org.apache.maven.archetypes \
  -DarchetypeArtifactId=maven-archetype-quickstart \
  -DarchetypeVersion=1.1 \
  -DgroupId=fr.brouillard.jgitver.demos \
  -DartifactId=demo2 \
  -Dpackage=fr.brouillard.jgitver.demos \
  -Dversion=1.0.0-SNAPSHOT

cd demo2
git init
git config user.name "Bob TheBuilder"
git config user.email bobthebuilder@nowhere.com
echo "target/" > .gitignore
echo "Init" > actions
git add .
git commit -m "initial commit"
mvn versions:set -DnewVersion=1.0.0 && mvn versions:commit
git add -u
git commit -m "release 1.0.0"
git tag -m "release 1.0.0" 1.0.0
mvn versions:set -DnewVersion=2.4.0-SNAPSHOT && mvn versions:commit
echo "Some action for 2.4.0-SNAPSHOT" >> actions
git add -u
git commit -m "switch to 2.4.0-SNAPSHOT"
mvn versions:set -DnewVersion=2.4.0 && mvn versions:commit
git add -u
git commit -m "release 2.4.0"
git tag -m "release 2.4.0" 2.4.0
mvn versions:set -DnewVersion=2.4.1-SNAPSHOT && mvn versions:commit
git add -u
git commit -m "switch to 2.4.1-SNAPSHOT"