Search code examples
javamavenjenkinsmaven-plugin

Jenkins doesn't use resolved maven's dependencies in Post-build Actions


I have a Maven job. In Build, for example, I use mvn compile with my settings.xml.

This settings.xml contains credentials to our Nexus Repository which stores some internal dependencies.

The problem is that when build will execute Post-build Actions (Post build task - Shell) with the same maven goal mvn compile it fails. It depends on build tries to download all dependencies and plugins again (but now it's without .

My question: How to share dependencies from Build step to step Post-build Actions


enter image description here


Solution

  • I found solution!

    At first you need to know the path to your maven local repository and pass it into maven cli via param maven.repo.local:

    mvn -Dmaven.repo.local=/home/jenkins/maven-repositories/0 compile
    

    And then the most important thing. For avoid download dependencies again you have to delete *.sha1 and *.repositories from your local maven repository. I don't why... but it how works Maven...

    It's an example of full script:

    find /home/jenkins/maven-repositories/0 -type f \( -iname "*.repositories" -o -iname "*.sha1" \) -exec rm -f {} \;
    
    mvn -Dmaven.repo.local=/home/jenkins/maven-repositories/0 compile