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 addotopma; geometry, raster and feature processes
-Parchive   modules that no longer work

Fore 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.

Oracle ojdbc jar

We are not in position to publish everything in a public maven repository. The ojdbc7 JDBC driver (required to run oracle online tests) will need to be installed by hand.

If you have access to the real driver you can rebuild the jdbc-oracle plugin with ojdbc driver. –>

  1. Download the ojdbc jar from oracle

  2. Install the ojdbc jar into your local maven repository:

    mvn install:install-file -Dfile=ojdbc7.jar \ -DartifactId=ojdbc7 \
        -Dversion= -Dpackaging=jar -DgeneratePom=true

    Producing output similar to the following:

    [INFO] Scanning for projects...
    [INFO] ------------------------------------------------------------------------
    [INFO] Building Maven Stub Project (No POM) 1
    [INFO] ------------------------------------------------------------------------
    [INFO] --- maven-install-plugin:2.3.1:install-file (default-cli) @ standalone-pom ---
    [INFO] Installing ojdbc7.jar
           to .m2/repository/com/oracle/ojdbc7/
    [INFO] ------------------------------------------------------------------------
    [INFO] ------------------------------------------------------------------------
    [INFO] Total time: 0.935s
    [INFO] Finished at: Tue Nov 27 16:20:16 EST 2015
    [INFO] Final Memory: 3M/81M
    [INFO] ------------------------------------------------------------------------
  3. You can then supply -Doracle=true on the command line when building:

    cd modules/plugins/jdbc/jdbc-oracle
    mvn clean install -Doracle=true

    The gt-jdbc-oracle plugin is now deployed in your repository with a dependency on the ojdbc oracle driver.

  4. Or when setting up eclipse:

    mvn eclipse:eclipse -Dall -Doracle=true

    The eclipse .project and .classpath generated now includes a reference to the ojdbc oracle driver.

  5. Or when running online tests:

    cd modules/plugin/jdbc/jdbc-oracle/
    mvn test -Doracle=true -P online