TeamCity
 
You are viewing the documentation for an earlier version of TeamCity.

Maven

Last modified: 20 April 2023

Note that you can create a new Maven-based build configuration automatically from URL, and set up a dependency build trigger, if a specific Maven artifact has changed.

 Maven runner settings



Maven Home



In Maven selection field, choose the Maven version you want to use. By default, the path to Maven installation is taken from the M2_HOME environment variable, otherwise the bundled Maven 3 is used. Alternatively, you can set it as %\MAVEN_HOME% environment variable right on a build agent.

User Settings



Specify what kind of user settings to use here. This is equivalent to the Maven command line option -s or --settings. The available options are:

Java Parameters



Local Artifact Repository Settings



Select Use own local repository for this build configuration to isolate this build configuration's artifacts repository from other local repositories.

Incremental Building



Select the Build only modules affected by changes check box to enable incremental building of Maven modules. The general idea is that if you have a number of modules interconnected by dependencies, a change most probably affects (directly or transitively) only some of them; so if we build only the affected modules and take the result of building the rest of the modules from the previous build, we will get the overall result equal to the result of building the whole project from scratch with less effort and time.

Since Maven itself has very limited support for incremental builds, TeamCity uses its own change impact analysis algorithm for determining the set of affected modules and uses a special preliminary phase for making dependencies of the affected modules.

First TeamCity performs own change impact analysis taking into account parent relationship and different dependency scopes and determines affected modules. Then the build is split into two sequential Maven executions.

The first Maven execution called preparation phase is intended for building the dependencies of the affected modules. The preparation phase is to assure there will be no compiler or other errors during the second execution caused by the absence or inconsistency of dependency classes.

The second Maven execution called main phase executes the main goal (for example, test), thus performing only those tests affected by the change.

Also check a related blog post on the topic.

Code Coverage



Coverage support based on IDEA coverage engine is added to Maven runner. To learn about configuring code coverage options, please refer to the Configuring Java Code Coverage page.

If you have several build agents installed on the same machine, by default they use the same local repository. However, there are two ways to allocate a custom local repository to each build agent:

  • Specify the following property in the teamcity-agent/conf/buildAgent.properties:

    system.maven.repo.local=%system.agent.work.dir%/<subdirectory name>

    For instance, %\system.agent.work.dir%/m2-repository

  • Run each build agent under different user account.

Using Maven Release with Perforce



To run the release:prepare maven task with Perforce VCS, do the following:

Check the following:

1. Make sure you're using at least 2.0 version of Maven Release Plugin. 2. Use ticket-based authentication for Maven Release plugin. 3. Make sure that your release:prepare maven task works when it is run from the command line without TeamCity.

In the Perforce VCS Root Settings of your build configuration in TeamCity:

1. Enable the checkout on agent.2. Enable Use ticket-based authentication in Perforce VCS root settings. 3. Make sure your build agent environment doesn't have any occasional P4 variables which can interfere with the execution of Maven Release Plugin. 4. Specify release:prepare in the Goals field of the Maven build step and run the build.