Difference between revisions of "Maven - Frequently Asked Questions"

(Add an entry about testing)
(The link to "imagej-maven-plugin" was broken, hope this is the right one...?)
Line 51: Line 51:
= What's this: ''Property 'imagej.app.directory' unset; Skipping copy-jars'' =
= What's this: ''Property 'imagej.app.directory' unset; Skipping copy-jars'' =
This is part of the [https://github.com/scijava/scijava-common/tree/master/imagej-maven-plugin imagej-maven-plugin] (enabled for you by pom-scijava). As you suspected, it copies your plugin's ''.jar'' file to your ImageJ plugins folder. But you have to specify where:
This is part of the [https://github.com/imagej/imagej-maven-plugin imagej-maven-plugin] (enabled for you by pom-scijava). As you suspected, it copies your plugin's ''.jar'' file to your ImageJ plugins folder. But you have to specify where:
<source lang="bash">
<source lang="bash">

Revision as of 07:26, 14 June 2013

What does the pom version mean?

The pom.xml of minimal-ij1-plugin inherits from a parent called pom-scijava. This parent POM defines and configures many things so that the POMs of individual plugin projects are shorter (i.e., so they don't have to repeat things).

The version of pom-scijava (1.27 as of this writing) indicates the version of that parent POM. We occasionally improve the parent POM, adding and tweaking it. When we do so, its version increases. I suggest leaving the version that same as what's in minimal-ij1-plugin, since that refers to the latest version. Future 1.x versions will be backwards compatible, so if you later notice that we have updated minimal-ij1-plugin to e.g. 1.43, you can (optionally) update your plugin to that version as well.

The version of minimal-ij1-plugin itself (1.0.0 as of this writing) is the version of your plugin. This string is appended to the JAR file name (e.g., minimal-ij1-plugin-1.0.0.jar), so that you can differentiate between multiple versions of your plugin. Use whatever versioning scheme you want.

However, once you become more comfortable with Maven, I suggest using a SNAPSHOT version during development, and a release (i.e., non-SNAPSHOT) version when distributing your plugin. The reason is to avoid two different JAR files both called my-plugin-1.2.3 but with different contents. (This is part of what Maven calls *build reproducibility*.)

For example, while you develop your plugin, you might use the version 1.0.0-SNAPSHOT to indicate that this is not the final 1.0.0 version but leads up to it. Once you are happy with the plugin in its current form, switch to 1.0.0. Note, however, that Maven will not like it too much if you change the sources of the final 1.0.0 version without advancing the version in the pom.xml file.

How is the imagej version determined?

In many pom.xml files, you can see that the version of the ij dependency is declared like this:


The string ${imagej1.version} is a property that gets replaced with the actual value. This value is defined in the pom-scijava parent configuration. Currently the value is [1.45s,) which means the latest release version you can find equal to or greater than 1.45s.

Browse the latest pom-scijava here.

Browse the available versions of ImageJ 1.x here.

As of this writing, 1.47n is the latest available version, so that's the one Maven will use with your plugin.

If you require an ImageJ 1.x version newer than 1.45s (e.g. due to the use of a method or class that was only introduced in a later version) you probably want to override the setting in your pom.xml file's <properties> section:


What's this: Property 'imagej.app.directory' unset; Skipping copy-jars

This is part of the imagej-maven-plugin (enabled for you by pom-scijava). As you suspected, it copies your plugin's .jar file to your ImageJ plugins folder. But you have to specify where:

mvn -Dimagej.app.directory=/Applications/ImageJ.app

One way to do that in NetBeans is to right-click your project, select Custom>Goals... which brings up the Run Maven dialog box. Then specify install for the Goals and -Dimagej.app.directory=/Applications/ImageJ.app for the Properties.

How to use my own, custom ImageJ version?

The dependencies specified in pom.xml are only used to compile your .jar file. If you set the imagej.app.directory property properly, it will copy things into the jars/ subdirectory of the location you pointed the property to.

My software depends on a .jar file that is not available via Maven!

The easiest way to do that would probably to install it locally for the moment. Please see Maven's console log for details how to do that after specifying a dependency, e.g.


It is advisable to look for the version number on the web site, as it was done here, and to construct the groupId from the web site, too.

Note that you will need to wrap the .class files in a .jar file like so:

jar cvf Particles8_.jar Particles8_.class

Then you can install that .jar file locally with a command like:

mvn install:install-file \
  -Dfile=/path/to/Particles8_.jar \
  -DgroupId=uk.ac.bham.dentistry -DartifactId=Particles8_ -Dversion=1.6 \
  -Dpackaging=jar -DgeneratePom=true

Can I call svnversion via Maven?

Typically you want to do that to put the current revision into an About box or something similar.

In general, you can call any needed Ant functionality using the maven-antrun-plugin. However, for the About box, there is a much better solution:

The pom-scijava parent uses the buildnumber-maven-plugin to embed the SCM revision and date in the JAR manifest. You can enable this behavior by adding the following lines to your POM:


Then, your About dialog box can access the information from the .jar file's manifest using the Manifest class of scijava-common.

You would need to add a dependency on scijava-common like this:


and then add code like this:

import org.scijava.util.Manifest;

    Manifest manifest = Manifest.getManifest(MyBeautifulPlugin.class);
    String version = manifest.getImplementationBuild();

Why isn't my plugin in src-plugins/ compiled by Build.sh?

Make sure your project lives in src-plugins/<artifactId>, that there is a correctly formatted pom.xml file inside that directory, and that the artifactId for your plugin has been added as a module in the modules section of src-plugins/pom.xml.

Also make sure that you do not have any circular dependencies. In other words, if your plugin is Plugin_A which depends on Plugin_B, be sure that Plugin_B does not depend on Plugin_A, or any other package that depends on Plugin_A.

How do I make my modified project available to a depending project using Maven?

For example, suppose you have made changes to TrakEM2 that you want to take advantage of in a plugin. Compiling with mvn may result in errors indicating that your modifications do not exist. In this case, run "mvn install" in the modules/TrakEM2 directory. This should install the relevant, fresh TrakEM2 jars into the correct locations.

Also make sure that the groupId, artifactId and version in the <dependencies> section of the dependencee match the settings in the dependency's pom.xml file.

How can I run individual tests with Maven?

As described here:

mvn -Dtest='TestCircle#mytest' test

Where can I find more information about Maven?