Skip to content

Maven tips

Richard Domander edited this page Sep 27, 2018 · 4 revisions

This page lists some tips on how to use Maven effectively, and solve common build problems.

Build errors

  • The first thing to try is to add the clean to the Maven goal you're trying to run, e.g. mvn clean install. It removes any artefacts left from the last run. Especially when switching branches there may be some incompatible versions left in the local Maven repository.

  • If clean doesn't help, try purging the local repository with mvn dependency:purge-local-repository. Purging solves problems with conflicting dependency versions. As a last resort you can manually delete all the files in the hidden .m2 folder. On Linux it's located by default at /home/user/.m2/. This doesn't do anything irreversible, Maven just has to download the dependencies again the next time it runs.

  • If mvn package succeeds, but your IDE shows errors, make sure it's been configured to automatically add Maven dependencies to the classpath.

Javadoc

  • You can check that the Javadoc in your files is valid by running mvn javadoc:javadoc. The build on the Travis show will fail if there's invalid Javadoc, e.g. bad HTML or missing @param tags. The goal javadoc:javadoc is not part of the default build configuration, because it takes a rather long time.

Wrapper tests

  • Maven has been configured to omit some tests when running the default build. These tests are slower integration tests that test the Commands in Modern/wrapperPlugins/. To include these tests, run Maven with the option -PallTests, e.g. mvn -PallTests package.

Dependencies

  • Most dependencies don't need a <version> tag, because BoneJ depends on pom-scijava. This parent POM declares the supported version numbers in its bill of materials (BOM). If for some reason you need to depend on a different version, then you need to declare it explicitly.

  • Maven enforcer throws an error if you have SNAPSHOT dependencies. Sometimes during development you need this, so to bypass this error you can run Maven with the flag -Denforcer.skip.

  • If you're trying to update to the newest SNAPSHOT version of a dependency, but Maven doesn't seem to find it, try the -U flag to update the references in the local repository.

  • The check whether you're missing dependencies, or have any extra ones you don't need, you can run mvn dependency:analyze.

  • mvn dependency:tree is handy especially when solving problems with conflicting versions of (transient) dependencies, i.e. if two of your dependencies try depending on different versions of the same 3rd party artefact.

  • When developing a SNAPSHOT artefact you may need to manually update the reference in your IDE. For example, if you're developing imagej-ops:0.99.0-SNAPSHOT and want to check it works with your wrapper plug-in, you first run mvn install on imagej-ops, which installs it into the local repository. Then in your IDE you check that BoneJ has this specific version in its external dependencies. In IntelliJ you right click the Modern module, and select Maven > Synchronize if it's not.

Miscellaneous

  • You can have several -D flags, e.g. mvn -Denforcer.skip=true -Dimagej.app.directory=/home/user/Fiji.app/ install.