Building a maven2 project

Skip to end of metadata
Go to start of metadata

Jenkins provides a job type dedicated to Maven 2/3. This job type integrates Jenkins deeply with Maven 2/3 and provides the following benefits compared to the more generic free-style software project.

  • Jenkins parses Maven POMs to obtain much of the information needed to do its work. As a result, the amount of configuration is drastically reduced.
  • Jenkins listens to Maven execution and figures out what should be done when on its own. For example, it will automatically record the JUnit report when Maven runs the test phase. Or if you run the javadoc goal, Jenkins will automatically record javadoc.
  • Jenkins automatically creates project dependencies between projects which declare SNAPSHOT dependencies between each other. See below.

Thus mostly you just need to configure SCM information and what goals you'd like to run, and Jenkins will figure out everything else.

TODO
Talk about how maven modules gets represented in sub projects, and how build numbers among sub-projects are controlled. Use some screenshots.

Automatic build chaining from module dependencies

Jenkins reads dependencies of your project from your POM, and if they are also built on Jenkins, triggers are set up in such a way that a new build in one of those dependencies will automatically start a new build of your project. Jenkins understands all kinds of dependencies in POM. Namely,

  • parent POM
  • <dependencies> section of your project
  • <plugins> section of your project
  • <extensions> section of your project
  • <reporting> section of your project

This process takes versions into account, so you can have multiple versions/branches of your project on the same Jenkins and it will correctly determine dependencies. Note that dependency version ranges are not supported, see https://issues.jenkins-ci.org/browse/JENKINS-2787 for the reason.

This feature can be disabled on demand - see configuration option Build whenever a SNAPSHOT dependency is built

Environment Variables (since 2.1)

Maven project type exposes the following environment variables, allowing you to use them as variable expansions in build configuration. The sampe values are the values of the variables if you are building [this tree](https://github.com/jenkinsci/jenkins/tree/jenkins-1.536)

Name Example Meaning
POM_DISPLAYNAME Jenkins main module Taken from <name> in POM
POM_VERSION 1.536 Taken from <version> in POM
POM_GROUPID org.jenkins-ci.main Taken from <groupId> in POM
POM_ARTIFACTID pom Taken from <artifactId> in POM
POM_PACKAGING pom Taken from <packaging> in POM

The Maven Integration Plugin

The Maven 2 project type is contained in the Maven Integration plugin, which is bundled with Jenkins. If you are running any version of Jenkins earlier than the current release, it may show up in the list of plugins having available updates. It is recommended not to upgrade the Maven Integration plugin separately from Jenkins itself. While it is technically a plugin, it is developed, tested, and released as part of the Jenkins core.

Labels

maven2 maven2 Delete
pom pom Delete
Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.
  1. Jun 15, 2009

    Carolyn Teo says:

    I have a project that has this setup in a project parent POM Module 1 <d...

    I have a project that has this setup in a project
    parent POM
    Module 1

    • <dependencies> section of your project
    • <extensions> section of your project
    • <reporting> section of your project
      Module 2
    • <dependencies> section of your project
    • <extensions> section of your project
    • <reporting> section of your project
      Module 3
    • <dependencies> section of your project
    • <extensions> section of your project
    • <reporting> section of your project

    Each module creates its own reporting section. However Hudson only display the reporting section in the Module 1. Module 2 and 3 are not accessible.

    Is there any way to get Hudson to display all 3?

    Thanks!

    1. Feb 24, 2010

      Gaston Gamietea says:

      Hi Carolyn, I've the same structure but I'm not able to build anything... it ke...

      Hi Carolyn,

      I've the same structure but I'm not able to build anything... it keeps saying that there is a missing dependency... can you add some example of your parent pom and at least one module pom ?

      I'm using Eclipse Galileo, M2 plugin to create parent projects and modules...

      Thanks in advance

      GASTON

  2. Jul 01, 2009

    tpijl - says:

    If a maven2 job is triggered by SCM it logs in with user "anonymous". When solvi...

    If a maven2 job is triggered by SCM it logs in with user "anonymous". When solving dependencies it uses a local repository.

    Where is that located in this case? And if I have a specific settings.xml where should I place this in this case

    I use Javawrapper to start my Hudson as a daemon on an OpenSuse 10.3 Linux server.

  3. Mar 25, 2010

    mmorizot - says:

    hi, I was wondering if there was a way of trigerring the reloading of a pom fil...

    hi,

    I was wondering if there was a way of trigerring the reloading of a pom file by hudson?

    the idea behind this is to modify in my workspace, the pom files (pre-build task) and then ask hudson to consider my newly modified pom, and not the initial one.

    I'm trying to implement a release process (without using release:*).

  4. Jul 28, 2010

    bombjack says:

    Hello everyone. We have a problem with Hudson and maven . We want to use Hudso...

    Hello everyone.
    We have a problem with Hudson and maven

    .
    We want to use Hudson outsourcing all configuration files (hudson_home) on another server.
    We configured the hudson_home in web.xml:
    \\ServerName\hudson

    When Hudson starts, it created all the files on the server. Therefore, the address is correct.
    But when will perform an initial build (maven in our case), it no longer works. Hudson displays the following message:

    OutputConsole
    [trunk] $ \\pcdsi547\int-continue\jdk\jdk1.5.0_07/bin/java -Xmx1024m -XX:MaxPermSize=256m -cp D:int-continue\hudson\plugins\maven-plugin\WEB-INF\lib\maven-agent-1.358.jar;\\pcdsi547\int-continue\maven\boot\classworlds-1.1.jar hudson.maven.agent.Main \\pcdsi547\int-continue\maven D:\P747\tomcat\tomcat-6-su\webapps\hudson\WEB-INF\lib\remoting-1.358.jar D:int-continue\hudson\plugins\maven-plugin\WEB-INF\lib\maven-interceptor-1.358.jar 3522 D:\int-continue\hudson\plugins\maven-plugin\WEB-INF\lib\maven2.1-interceptor-1.2.jar
    java.lang.NoClassDefFoundError: hudson/maven/agent/Main
    Exception in thread "main" ERROR: Failed to launch Maven. Exit code = 1 Finished: FAILURE

    It was noticed in the console output, it replaces some jars network address
    MyServer with D:\ (the letter is located where the application server).
    There is more then some jars (whose address is changed). We should not have D:\ *** but all the time
    pcdsi547****.
    What do you think? Did you encounter this error?
    We tested on Tomcat and Weblo (and therefore jdk and jrockit), we get the same error.

    edit: it works on a Windows environment I think the problem is adress UNC.

  5. Nov 02, 2010

    Nathan Bragg says:

      I can't figure out when I'm running a Maven build using Hudson it would h...

      I can't figure out when I'm running a Maven build using Hudson it would hang on 'Parsing POMs' however when I set up the project for freestyle it builds correctly.  What could possibly be different between how the two are set up that is causing my Hudson Server to not get past 'Parsing POMs'?

    Any ideas?

  6. Oct 15, 2011

    denys hordeyev says:

    I am using maven 2/3 type pf project. But when it tries to build maven does not ...

    I am using maven 2/3 type pf project. But when it tries to build maven does not receives any property values from the job configuration and profiles i am using does not get activated

    When set goals like " -Denv=dev1 deploy " maven receives env property and associated profile gets set.

    But when i use job parameter named "env" and goals set to just "deploy" , maven do not get env variable set and the build fails parsing POMs   

    Please advise

  7. Mar 30, 2013

    Stephane Odul says:

    I'm having an issue on my master where the artifacts retention policy does not s...

    I'm having an issue on my master where the artifacts retention policy does not seem to be applied the sub-modules. I have a job with a very short retention policy (Discard Old Builds: keep 10 builds max, 10 artifacts max). On the jenkins UI this is respected for the job itself, but the 'modules' kept on growing, eventually almost filling up my master's disk.

    By modules, I mean under the jobs directory on the master:

    jobs/some-job-name/modules/com.company$modulename/builds/

    Any idea what is happening? Interestingly I can reach the url for the modules and there is even a /config url for it but the 'Discard Old Builds' checkbox is not present there.

    I could write a script the would scan all the jenkins jobs on the master, read the retention policy from config.xml and then apply it to the modules, but Jenkins should have taken care of that.

    1. Apr 19, 2013

      Henrik Horneber says:

      Same issue here.... https://issues.jenkins-ci.org/browse/JENKINS-17553
  8. Jun 17, 2013

    Andrey Belyaevskiy says:

    Hi All! Can I setup Jenkins to launch Maven task vis javaw instead of java?

    Hi All!

    Can I setup Jenkins to launch Maven task vis javaw instead of java?

  9. Jun 26, 2013

    roger persson says:

    In the Jenkins maven-build config-page, there is an option: "Maven Validation Le...

    In the Jenkins maven-build config-page, there is an option: "Maven Validation Level".

    Is there documentation for this anywhere?

    What does the avaliable options mean exactly?

  10. Sep 27, 2013

    John Zerbe says:

    Are there any plans by anyone to fix this issue with the maven plugin? https://...

    Are there any plans by anyone to fix this issue with the maven plugin?

    https://issues.jenkins-ci.org/browse/JENKINS-19352

    The whole idea behind using Jenkins is for continuous integration where you know right away when someone commits something to SCM that breaks your project. If the maven plugin fails the job but doesn't tell you what broke, its somewhat close to being useless.

  11. Nov 19

    Jacob Rhoda says:

    Anyone know why my Maven environment variables aren't being set? I'm trying to a...

    Anyone know why my Maven environment variables aren't being set? I'm trying to access them from a post-build script but they're not set.

    1. Dec 10

      Leif Janzik says:

      any news on this comment? the variables are not being set.

      any news on this comment? the variables are not being set.