Configure the remote Maven repository in Jenkins project jobs

Issue

I have maven installed and configured on my Jenkins Enterprise master. I can build a project using “mvn install” without any problem. When I tried to build a project, it results in this error:

org.apache.maven.project.ProjectBuildingException: Some problems were encountered while processing the POMs: 
[FATAL] Non-resolvable parent POM: Failure to find com.acme.project.platform:app-one:pom:2016.5.2 in http://repo.maven.apache.org/maven2 was cached in the local repository, resolution will not be reattempted until the update interval of central has elapsed or updates are forced...

Hence, Jenkins is attempting to connect to the global maven.apache.org rather than my local repository.

Items to Consider:

The local maven repository defaults to ~/.m2. So if you did mvn install on the local machine as a different user to the one Jenkins runs as this won’t work.

Also, if you are running your job on a node/slave, it’s possible that the Jenkins job won’t be looking at the local M2 repo. This depends on what sort of job you are using (Maven Project vs Freestyle Project)

Environment

  • Cloudbees Jenkins Enterprise

# Resolution #

Solution 1:

Configure the settings.xml file globally (via Jenkins > Mange Jenkins > Configure System - Maven Configuration).

Solution 2:

If you need to define one Maven configuration per job (for Maven projects) you should use the Config File Provider Plugin
This is particularly useful for configuring multiple Maven configurations, such as one per environment (e.g. Dev, QA, etc)

Tip: If you configure the default settings after the creation of the job, the job configuration wont be automatically updated. The default settings as configured in “configure system” are used only at creation time such as this:

For a freestyle job…

For a maven job…

Hence, if you change the default settings they aren’t updated in existing jobs. The update needs to be applied manually (or with a script) in existing jobs.

If you create a new job after having registered your configuration file in the Config File Provider Plugin and configured it as default in Configure System, it should pick up the Maven repository settings without issue.

Have more questions? Submit a request

0 Comments

Please sign in to leave a comment.