Maven FAQ

Tips and hits for using maven. For other FAQ please check GeneralDev & DeveloperFaq

Adding a bundle to a maven repository

Local

In order to install a file (e.g. a JAR) in you local repositry:

mvn install:install-file \
      -DgroupId=<group-id> \
      -DartifactId=<artifact-id> \
      -Dversion=<version> \
      -Dfile=<path-to-file> \
      -Dpackaging=<packaging> (i.e. jar) \
      -DgeneratePom=true

e.g. To install aspectjrt version 1.6.2 in your local repositry:

mvn install:install-file  -DgroupId=aspectj -DartifactId=aspectjrt -Dversion=1.6.2 -Dfile=aspectjrt.jar -Dpackaging=jar -DgeneratePom=true

Remote

In order to deploy a jar to a remote repository deploy:deploy-file should be used, since this plugin will also create the *.sha files with a hash. Example: Prepare aspectjrt version 1.6.2 for a remote repository. With this command you in fact create the artifact in local temporary repository and then copy the resulting files to the remote repository:

mvn deploy:deploy-file -DgroupId=aspectj -DartifactId=aspectjrt -Dversion=1.6.2 -Dpackaging=jar -Dfile=aspectjrt.jar -Durl=file:///D:/tmp/repo

It is also possible to directy deploy to the remote repository via scp:

mvn deploy:deploy-file -DgroupId=aspectj -DartifactId=aspectjrt -Dversion=1.6.2 -Dpackaging=jar -Dfile=aspectjrt.jar -Durl=scp://you@192.168.1.17/var/www/wp5.e-taxonomy.eu/cdmlib/mavenrepo/org/aspectj/aspectjrt -DgeneratePom=true

Of course the server must be configured in the ~/.m2/settings.xml file or in the {maven-home}/conf/settings.xml. The repository is accessed with SCP, authentication is done with public/private key.

Setting for windows using pageant in order to provide the key to, so no key is specified explicitely in this configuration:

<server>
      <id>wp5.e-taxonomy.eu</id>
      <username>root</username>
    <!-- == Cygwin Configuration == -->
    <!--
      <configuration>
        <sshExecutable>ssh</sshExecutable>
        <scpExecutable>scp</scpExecutable>
      </configuration>
    -->
    <!-- == Putty Configuration == -->
      <configuration>
        <sshExecutable>plink</sshExecutable>
        <scpExecutable>pscp</scpExecutable>
      </configuration>
    </server>
  </servers>

Also see: How do I install a file in my local repository along with a generic POM

Creating maven artifacts from eclipse bundles

The taxeditor poms require access to the latest eclipse bundles as maven artifacts. Luckily the maven-eclipse-plugin has a feature for that.

Please make sure that you have the deltapack installed before doing this.

$ mvn eclipse:to-maven -DeclipseDir=<path to your eclipse installation or target platform>/eclipse \
                    -DdeployTo=<repository server id as in settings.xml>::default::<your maven repository as configured in parent pom.xml> \
                    -DstripQualifier=true

If you do not want to deploy to the maven repository skip the deployTo option.

For further information please refer to http://maven.apache.org/plugins/maven-eclipse-plugin/to-maven-mojo.html

Please note that this is a rather lengthy operation.

Using the maven release plugin

Test run release:prepare while editing the pom.xml files:

mvn -DdryRun=true -Dmaven.test.skip=true --batch-mode -DcheckModificationExcludeList=pom.xml release:prepare

prepare a release (non interactive)

mvn --batch-mode release:prepare

The release:prepare failed, what should I do now?

Usually you can re-execute release:prepare to resume the failed build. If you are about to change something in the code or in the pom.xml's you should clean up the working space:

  1. remove all files which have been created by release:prepare
    mvn release:clean
    
  2. Revert your local copy of the svn repository
     svn revert
    

mvn release:prepare failes with "The svn command failed" when using cygwin

detailed example output of this error:

[INFO] Working directory: D:\workspaces\cdmlib-trunk
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Unable to commit files
Provider message:
The svn command failed.
Command output:
svn: '/cygdrive/d/workspaces/cdmlib-trunk/D:/workspaces/cdmlib-trunk' is not a working copy
svn: '/cygdrive/d/workspaces/cdmlib-trunk/D:/workspaces/cdmlib-trunk' does not exist

This is due to a bug which is currently unsolved: http://jira.codehaus.org/browse/SCM-481 So it seems as if you cannot use the release plugin if you have cygwin installed.

Maven and svn

how can I configure maven to use my svn credentials

in maven 1 it was possible to store the credentials in $USER-HOME./scm/svn-settings.xml but this option is not further supported by maven 2, since credentials are usually stored by svn automatically unless not configured differently in $USER-HOME\.subversion\config So in order to use a specific svn account with maven first perform a commit manually by svn ci -m "commit message" and answer the question wether to store the credential with yes. There is no specific maven configuration required for svn to work with maven!