Maven Tips

Maven has a fair few tricks and tips associated with its use. The major benefit is with a consistent project structure (and pom.xml description) a number of plugins can be used.

Really Building All Modules

GeoTools plays host to a number of experiment “unsupported” modules; if you would like to help out on any of these modules (or get a preview of new features):

mvn install -Dall

The -Dall acts as a switch to part engages several profiles; you can also do this by hand with -P

The following “profiles” are included by the -Dall:

Profile

-Dall

Builds

-Ppending

included

several experimental modules

-Praster

included

builds coverage tools

-Pgeometry

included

builds ISO 19107 geometry implementations

-Pswing

included

-Pwps

included

WPS client

-Pprocess

included

geometry, raster and feature processes

-Parchive

modules that no longer work

For more details see unsupported/pom.xml (or try mvn help:all-profiles for the complete list).

Parallel Builds

Maven 3 allows you to control your computing resources a bit more:

mvn install -Dall -T 2C

The above command builds using two threads for each CPU core available.

You can also set an exact number of threads to use:

mvn install -Dall -T 3

You can experiment with different settings to determine what works best for your machine.

Building Offline

When working offline, you can bypass the checking of md5 and downloading files.

To do this use the following:

C:\java\geotools\trunk>mvn -o install

By avoiding the check of md5 files you can take drastically reduce build time.

No Snapshot Updates

To work online, but just avoid checking SNAPSHOT dependencies:

C:\java\geotools\trunk>mvn -nsu install

Building an Individual module

Provided you have done at least one complete build you should be able to build individual modules one-at-a-time.

  1. Change to the modules home directory:

    cd modules/library/cql
    
  2. Use Maven to compile - it should do a complete build:

    mvn compile
    
  3. Use Maven to update the local repository - it should run the test cases and install the jar in the local repository for other modules (or applications) to use when they build.:

    mvn install
    

If you have not done a full build yet then the build may fail because it can’t find the jar for a module it depends on.

  • An error caused by not having another GeoTools module installed can be a little misleading:

    Error: unable to download main-2.1.x.jar
    
  • Maven failed to find main-2.1,x.jar in the local repository where a full build should have put it

  • Maven tried to download the file from the internet (and failed)

  • If you see an error like that, either do a full build or change into the module which is missing (main in this case) and type.:

    maven install
    

Avoiding Tests

You may also notice that running the tests takes a fair amount of time. While these tests need to be run before you commit for the day, you may want to forgo the wait while experimenting.

The following will build the tests - but not run them:

mvn -DskipTests install

This is useful for installing the PostGIS module test jar; which is used by the postgis-version module as a dependency.

The following will not even build the tests:

mvn -Dmaven.test.skip=true install

Resuming After a Failure

When doing a full build of GeoTools it can be disheartening when a build fails 90% of the way through causing you to fix and start again.

The -rf (resume from) parameter of is useful in these cases. It is used to resume a multi-module build such as GeoTools from a specific location to avoid rebuilding those modules you have already successfully build.

  1. For instance, consider quickly building offline:

    mvn install -o -Dall
    
  2. If modules/library/data failed due to a missing jar you can resume the build in online mode:

    mvn install -rf modules/library/data
    

This same technique can be used to restart a build after fixing a failed test in a module.

Generate a Web Site

Maven reports can be generated by the following command, to be executed from the directory that contains the parent pom.xml file:

mvn site:site

The site are created in target/site directory of every module. An aggregated javadoc is also created in the parent target/site/apidocs directory.