Project

General

Profile

Actions

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/cybertaxonomy.eu/cdmlib/mavenrepo/org/aspectj/aspectjrt -DgeneratePom=true

maven settings.xml

The remote 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.

settings.xml for *NIX systems:

<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
                      http://maven.apache.org/xsd/settings-1.0.0.xsd">

  <servers>
    <server>
    <id>wp5.e-taxonomy.eu</id>
    <username>deploy</username>
    </server>
    <server>
      <id>cybertaxonomy.eu</id>
      <username>deploy</username>
      </server>
  </servers>
</settings>

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

<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
                      http://maven.apache.org/xsd/settings-1.0.0.xsd">

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

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
  1. 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!

Maven Deploy and Wagon (wagon-maven-plugin)

The wagon-maven-plugin for ssh uses the user account configured in the maven settings.xml

debugging problems which occur during deployment over ssh

helpful links:

example error messages:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy (default-deploy) on project cdmlib-parent: 
Failed to deploy artifacts: Could not transfer artifact eu.etaxonomy:cdmlib-parent:pom:3.4.0-20141205.121434-86 from/to 
wp5.e-taxonomy.eu (scpexe://wp5.e-taxonomy.eu/var/www/wp5.e-taxonomy.eu/mavenrepo/): 
Exit code: 1 - scp: /var/www/wp5.e-taxonomy.eu/mavenrepo//eu/etaxonomy/cdmlib-parent/3.4.0-SNAPSHOT/cdmlib-parent-3.4.0-20141205.121434-86.pom: 
Permission denied -> [Help 1]

commands which may help debugging

You may need to exchange the files and folder used in the examples below by valid values.

IMPORTANT: Do not forget to delete the uploaded artefacts from the repo!

1) test maven-deploy-plugin

mvn -e -X deploy:deploy-file -Dfile=/var/lib/jenkins/.m2/repository/log4j/log4j/1.2.17/log4j-1.2.17.jar \
  -DpomFile=/var/lib/jenkins/.m2/repository/log4j/log4j/1.2.17/log4j-1.2.17.pom -DrepositoryId=cybertaxonomy.eu \
  -Durl=scpexe://cybertaxonomy.eu/var/www/wp5.e-taxonomy.eu/mavenrepo/
ssh deploy@cybertaxonomy.eu "rm -rf /var/www/wp5.e-taxonomy.eu/mavenrepo/log4j"

2) test wagon-maven-plugin

Test for valid default configuration in the pom:

touch /tmp/testfile
mvn -X -e wagon:upload-single -Dwagon.fromFile=/tmp/testfile \
   -Dwagon.toFile=/var/www/wp5.e-taxonomy.eu/mavenrepo/
ssh deploy@cybertaxonomy.eu "rm -f /var/www/wp5.e-taxonomy.eu/mavenrepo/testfile"

If this command is failing with errors like

  • The parameters 'url' for goal org.codehaus.mojo:wagon-maven-plugin:1.0:upload-single are missing or invalid
  • Failed to execute goal org.codehaus.mojo:wagon-maven-plugin:1.0:upload-single (default-cli) on project xxx: Error handling resource: Error executing command for transfer: Exit code 255 - Permission denied (publickey)

the pom.xml most probably misses the default config for the wagon-maven-plugin.
Add the following to the plugins section:

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>wagon-maven-plugin</artifactId>
    <version>1.0</version>
    <configuration>
        <url>scpexe://cybertaxonomy.eu</url>
        <serverId>cybertaxonomy.eu</serverId>
    </configuration>
    <executions>
        <execution>
        <id>upload-reference-documentation</id>
        <phase>site-deploy</phase>
        <goals>
            <goal>upload</goal>
        </goals>
        </execution>
    </executions>
</plugin>

This command can be used to test the wagon ssh connectivity without default configuration.
If you get an error with this the ~/m2/settings.xml might be missing the entry for the serverID (see above).

touch /tmp/testfile
mvn -X -e wagon:upload-single -Dwagon.fromFile=/tmp/testfile \
  -Dwagon.url=scpexe://cybertaxonomy.eu/ -Dwagon.toFile=/var/www/wp5.e-taxonomy.eu/mavenrepo/ -Dwagon.serverId=cybertaxonomy.eu
ssh deploy@cybertaxonomy.eu "rm -f /var/www/wp5.e-taxonomy.eu/mavenrepo/testfile"

maven clean test is running successful on computer (A) but fails non (B)

(See also IntegrationTestWriting)

with exactly the same source code mvn clean test is running successful on computer (A) but fails non (B). This is most probably due to dependencies between to tests which ideally should nor exist, but in reality you can encounter situations when test X running after test Y succeeds whereas Y running after test X fails. In this case quite often X leaves some test data in the database which is not cleaned up after the test class ends and which id not overwritten by new testdata. There are two mechanisms which are doing the cleanup:

  1. Test are usually rolled back after the tests ends. This is frequently overwritten for specific tests.

  2. tables contains in new test data files (@@Data@ annotations) will cause existing data to be dropped.

The CleanSweepInsertLoadStrategy can be used as a third, explicit mechanism which will clean sweep the whole data base except for the terms. If you are interested into also drop all terms please take a look into the source code of this class.

public class SomethingTestTest extends CdmTransactionalIntegrationTest {
    @Test
    @DataSet(loadStrategy=CleanSweepInsertLoadStrategy.class, value="SomethingTest.xml")
    @ExpectedDataSet(value="FirstDataInserterTest.testBlankDB-result.xml")
    public void testSomething() {

     ....

Updated by Andreas Müller almost 2 years ago · 44 revisions