Maven – Jenkins can’t find local maven dependancies

Jenkinsmavenmaven-2

I'm having some trouble getting my maven project to build in jenkins. The project builds fine on my local machine, but not when Jenkins tries to build it

I have 2 dependancies that are local and not hosted on any repo. They are:

  • first.jar
  • second.jar

Here is the structure of my project:

 - -MyProject/
 - ---images/...
 - ---resources/...
 - ---src/...
 - ---first.jar
 - ---second.jar
 - ---pom.xml
 - ---...

Maven cannot seem to find "first.jar" and "second.jar" and tries to download them remotely.

I have installed them with

install:install-file -Dfile=first.jar -DgroupId=first -DartifactId=first -Dversion=1.0.0 -Dpackaging=jar

install:install-file -Dfile=second.jar -DgroupId=second -DartifactId=second -Dversion=1.0.0 -Dpackaging=jar

========================

POM.XML

Here is my pom.xml:

<!-- This pom is now operational.-->
<!--  ****Compile with****: mvn compile -->
<!--  ****Create Executable with****: mvn package -->
<!--  ****Run with****: java -jar MYPROJECT-0.0.1-beta-jar-with-dependencies.jar [args]-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <!-- MYPROJECT INFO -->
    <groupId>Main</groupId>
    <artifactId>MyProject</artifactId>
    <version>0.0.1-beta</version>
    <name>MyProject</name>
    <packaging>jar</packaging>
    <!-- DEPENDANCIES -->
    <dependencies>
        <dependency>
        <groupId>first</groupId>
        <artifactId>first</artifactId>
        <version>1.0.0</version>
    </dependency>    
        <dependency>
          <groupId>second</groupId>
          <artifactId>second</artifactId>
          <version>1.0.0</version>
    </dependency>   
    </dependencies>

    <build>
        <sourceDirectory>src</sourceDirectory>
    <!-- RESOURCES -->
        <resources>
          <resource>
            <directory>src</directory>
            <filtering>true</filtering>
          </resource>
          <resource>
            <directory>${basedir}/images</directory>
        <filtering>false</filtering>
        <targetPath>images</targetPath>
          </resource>
        <resource>
            <directory>${basedir}/resources</directory>
        <filtering>false</filtering>
        <targetPath>resources</targetPath>
          </resource>
        </resources>
        <testResources>
          <testResource>
            <directory>src</directory>
          </testResource>
        </testResources>
        <plugins>
    <!--  For Java 6, you need to configure the maven-compiler-plugin. Add this to your pom.xml: -->
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <configuration>
              <source>1.6</source>
              <target>1.6</target>
            </configuration>
          </plugin>
    <!-- CREATE EXECUTABLE JAR WITH DEPENDANCIES in target/MYPROJECT -->
        <plugin>
          <artifactId>maven-assembly-plugin</artifactId>
          <version>2.4</version>
          <configuration>
            <archive>
              <manifest>
            <mainClass>Main.Main</mainClass>
              </manifest>
            </archive>
            <descriptorRefs>
              <descriptorRef>jar-with-dependencies</descriptorRef>
            </descriptorRefs>
            <outputDirectory>${project.build.directory}/MYPROJECT</outputDirectory> 
          </configuration>
          <executions>
            <execution>
              <id>make-assembly</id> <!-- this is used for inheritance merges -->
              <phase>package</phase> <!-- bind to the packaging phase -->
              <goals>
            <goal>single</goal>
              </goals>
            </execution>
          </executions>
        </plugin>
    <!-- COPY RESOURCES to target/MYPROJECT -->
        <plugin>
        <artifactId>maven-resources-plugin</artifactId>
        <version>2.6</version>
        <executions>
          <execution>
            <id>copy-resources</id>
            <!-- here the phase you need -->
            <phase>package</phase>
            <goals>
              <goal>copy-resources</goal>
            </goals>
            <configuration>
              <outputDirectory>${basedir}/target/MYPROJECT</outputDirectory>
              <resources>          
                  <resource>
                <directory>${basedir}/images</directory>
                <filtering>false</filtering>
                <targetPath>images</targetPath>
                  </resource>
                <resource>
                <directory>${basedir}/resources</directory>
                <filtering>false</filtering>
                <targetPath>resources</targetPath>
                  </resource>
              </resources>              
            </configuration>            
          </execution>
        </executions>
          </plugin>

        </plugins>
    </build>
</project>

========================

JENKINS

And here is my Jenkins configuration:

  • "Build"
    • "Invoke top-level Maven Targets"
      • install:install-file -Dfile=first.jar -DgroupId=first -DartifactId=first -Dversion=1.0.0 -Dpackaging=jar
        • originally didn't have these included, but I thought maybe if I installed them within the build it might work… but it doesn't.
    • "Invoke top-level Maven Targets"
      • install:install-file -Dfile=second.jar -DgroupId=second -DartifactId=second -Dversion=1.0.0 -Dpackaging=jar
    • "Invoke top-level Maven Targets"
      • compile
        • I have also tried compile -gs /usr/share/maven2/conf/settings.xml -s /usr/share/maven2/conf/settings.xml )
        • I have also tried selecting "Use private Maven repository" and setting "Global Settings file" and "Settings file"
    • "Invoke top-level Maven Targets"
      • package
        • (have also tried package -gs /usr/share/maven2/conf/settings.xml -s /usr/share/maven2/conf/settings.xml )

========================

OUTPUT

Building in workspace /var/lib/jenkins/workspace/MyProject
Checkout:MyProject / /var/lib/jenkins/workspace/MyProject - hudson.remoting.LocalChannel@65565eae
Using strategy: Default
Last Built Revision: Revision 72e4cfcdd55427078cb0fb2c799c99e96ecb4ad8 (origin/master)
Fetching changes from 1 remote Git repository
Fetching upstream changes from origin
Commencing build of Revision 72e4cfcdd55427078cb0fb2c799c99e96ecb4ad8 (origin/master)
Checking out Revision 72e4cfcdd55427078cb0fb2c799c99e96ecb4ad8 (origin/master)
[MyProject] $ mvn install:install-file -Dfile=first.jar -DgroupId=first -DartifactId=first -Dversion=1.0.0 -Dpackaging=jar
/usr/lib/jvm/java
[INFO] Scanning for projects...
*DEBUG*: Putting in plugin descriptor list org.apache.maven.plugins:maven-compiler-plugin:2.0.2 and goal prefix is compiler
*DEBUG*: Putting in plugin descriptor list org.apache.maven.plugins:maven-compiler-plugin:2.0.2 and goal prefix is compiler
*DEBUG*: Constructed plugin version key is org.apache.maven.plugins:maven-compiler-plugin:2.0.2
*DEBUG*: Constructed plugin version key is org.apache.maven.plugins:maven-compiler-plugin:2.0.2
*DEBUG*: Putting in plugin descriptor list org.apache.maven.plugins:maven-assembly-plugin:2.4 and goal prefix is assembly
*DEBUG*: Putting in plugin descriptor list org.apache.maven.plugins:maven-assembly-plugin:2.4 and goal prefix is assembly
*DEBUG*: Constructed plugin version key is org.apache.maven.plugins:maven-assembly-plugin:2.4
*DEBUG*: Constructed plugin version key is org.apache.maven.plugins:maven-assembly-plugin:2.4
*DEBUG*: Putting in plugin descriptor list org.apache.maven.plugins:maven-resources-plugin:2.6 and goal prefix is resources
*DEBUG*: Putting in plugin descriptor list org.apache.maven.plugins:maven-resources-plugin:2.6 and goal prefix is resources
*DEBUG*: Constructed plugin version key is org.apache.maven.plugins:maven-resources-plugin:2.6
*DEBUG*: Constructed plugin version key is org.apache.maven.plugins:maven-resources-plugin:2.6
[INFO] Searching repository for plugin with prefix: 'install'.
*DEBUG*: Putting in plugin descriptor list org.apache.maven.plugins:maven-install-plugin:2.2 and goal prefix is install
*DEBUG*: Putting in plugin descriptor list org.apache.maven.plugins:maven-install-plugin:2.2 and goal prefix is install
*DEBUG*: Constructed plugin version key is org.apache.maven.plugins:maven-install-plugin:2.2
*DEBUG*: Constructed plugin version key is org.apache.maven.plugins:maven-install-plugin:2.2
[INFO] ------------------------------------------------------------------------
[INFO] Building MyProject
[INFO]    task-segment: [install:install-file] (aggregator-style)
[INFO] ------------------------------------------------------------------------
[INFO] [install:install-file {execution: default-cli}]
[INFO] Installing /var/lib/jenkins/workspace/MyProject/first.jar to /home/jenkins/.m2/repository/first/first/1.0.0/first-1.0.0.jar
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3 seconds
[INFO] Finished at: Mon Aug 19 10:05:11 PDT 2013
[INFO] Final Memory: 7M/30M
[INFO] ------------------------------------------------------------------------
[MyProject] $ mvn install:install-file -Dfile=second.jar -DgroupId=second -DartifactId=second -Dversion=1.0.0 -Dpackaging=jar
/usr/lib/jvm/java
[INFO] Scanning for projects...
*DEBUG*: Putting in plugin descriptor list org.apache.maven.plugins:maven-compiler-plugin:2.0.2 and goal prefix is compiler
*DEBUG*: Putting in plugin descriptor list org.apache.maven.plugins:maven-compiler-plugin:2.0.2 and goal prefix is compiler
*DEBUG*: Constructed plugin version key is org.apache.maven.plugins:maven-compiler-plugin:2.0.2
*DEBUG*: Constructed plugin version key is org.apache.maven.plugins:maven-compiler-plugin:2.0.2
*DEBUG*: Putting in plugin descriptor list org.apache.maven.plugins:maven-assembly-plugin:2.4 and goal prefix is assembly
*DEBUG*: Putting in plugin descriptor list org.apache.maven.plugins:maven-assembly-plugin:2.4 and goal prefix is assembly
*DEBUG*: Constructed plugin version key is org.apache.maven.plugins:maven-assembly-plugin:2.4
*DEBUG*: Constructed plugin version key is org.apache.maven.plugins:maven-assembly-plugin:2.4
*DEBUG*: Putting in plugin descriptor list org.apache.maven.plugins:maven-resources-plugin:2.6 and goal prefix is resources
*DEBUG*: Putting in plugin descriptor list org.apache.maven.plugins:maven-resources-plugin:2.6 and goal prefix is resources
*DEBUG*: Constructed plugin version key is org.apache.maven.plugins:maven-resources-plugin:2.6
*DEBUG*: Constructed plugin version key is org.apache.maven.plugins:maven-resources-plugin:2.6
[INFO] Searching repository for plugin with prefix: 'install'.
*DEBUG*: Putting in plugin descriptor list org.apache.maven.plugins:maven-install-plugin:2.2 and goal prefix is install
*DEBUG*: Putting in plugin descriptor list org.apache.maven.plugins:maven-install-plugin:2.2 and goal prefix is install
*DEBUG*: Constructed plugin version key is org.apache.maven.plugins:maven-install-plugin:2.2
*DEBUG*: Constructed plugin version key is org.apache.maven.plugins:maven-install-plugin:2.2
[INFO] ------------------------------------------------------------------------
[INFO] Building MyProject
[INFO]    task-segment: [install:install-file] (aggregator-style)
[INFO] ------------------------------------------------------------------------
[INFO] [install:install-file {execution: default-cli}]
[INFO] Installing /var/lib/jenkins/workspace/MyProject/second.jar to /home/jenkins/.m2/repository/second/second/1.0.0/second-1.0.0.jar
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 4 seconds
[INFO] Finished at: Mon Aug 19 10:05:18 PDT 2013
[INFO] Final Memory: 7M/30M
[INFO] ------------------------------------------------------------------------
[MyProject] $ mvn compile
/usr/lib/jvm/java
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Building MyProject
[INFO]    task-segment: [compile]
[INFO] ------------------------------------------------------------------------
*DEBUG*: Putting in plugin descriptor list org.apache.maven.plugins:maven-resources-plugin:2.6 and goal prefix is resources
*DEBUG*: Putting in plugin descriptor list org.apache.maven.plugins:maven-resources-plugin:2.6 and goal prefix is resources
*DEBUG*: Constructed plugin version key is org.apache.maven.plugins:maven-resources-plugin:2.6
*DEBUG*: Constructed plugin version key is org.apache.maven.plugins:maven-resources-plugin:2.6
*DEBUG*: Putting in plugin descriptor list org.apache.maven.plugins:maven-compiler-plugin:2.0.2 and goal prefix is compiler
*DEBUG*: Putting in plugin descriptor list org.apache.maven.plugins:maven-compiler-plugin:2.0.2 and goal prefix is compiler
*DEBUG*: Constructed plugin version key is org.apache.maven.plugins:maven-compiler-plugin:2.0.2
*DEBUG*: Constructed plugin version key is org.apache.maven.plugins:maven-compiler-plugin:2.0.2
*DEBUG*: Constructed plugin version key is org.apache.maven.plugins:maven-compiler-plugin:2.0.2
*DEBUG*: Putting in plugin descriptor list org.apache.maven.plugins:maven-assembly-plugin:2.4 and goal prefix is assembly
*DEBUG*: Putting in plugin descriptor list org.apache.maven.plugins:maven-assembly-plugin:2.4 and goal prefix is assembly
*DEBUG*: Constructed plugin version key is org.apache.maven.plugins:maven-assembly-plugin:2.4
*DEBUG*: Constructed plugin version key is org.apache.maven.plugins:maven-assembly-plugin:2.4
*DEBUG*: Constructed plugin version key is org.apache.maven.plugins:maven-resources-plugin:2.6
[INFO] [resources:resources {execution: default-resources}]
[WARNING] File encoding has not been set, using platform encoding UTF-8, i.e. build is platform dependent!
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 35 resources
[INFO] Copying 126 resources to images
[INFO] Copying 18 resources to resources
Downloading: http://repo1.maven.org/maven2/first/first/1.0.0/first-1.0.0.pom
[INFO] Unable to find resource 'first:first:pom:1.0.0' in repository central (http://repo1.maven.org/maven2)
[WARNING] Skipping jpp repository file:///usr/share/maven2/repository in vanilla mode
Downloading: http://repo1.maven.org/maven2/second/second/1.0.0/second-1.0.0.pom
[INFO] Unable to find resource 'second:second:pom:1.0.0' in repository central (http://repo1.maven.org/maven2)
[WARNING] Skipping jpp repository file:///usr/share/maven2/repository in vanilla mode
[INFO] [compiler:compile {execution: default-compile}]
[INFO] Compiling 24 source files to /var/lib/jenkins/workspace/MyProject/target/classes
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Compilation failure
/var/lib/jenkins/workspace/MyProject/src/Actions/EditorActions.java:[119,15] error while writing Actions.EditorActions.ListCheckBox: /var/lib/jenkins/workspace/MyProject/target/classes/Actions/EditorActions$ListCheckBox.class (Permission denied)


[INFO] ------------------------------------------------------------------------
[INFO] For more information, run Maven with the -e switch
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 15 seconds
[INFO] Finished at: Mon Aug 19 10:05:35 PDT 2013
[INFO] Final Memory: 14M/53M
[INFO] ------------------------------------------------------------------------
Build step 'Invoke top-level Maven targets' marked build as failure
Finished: FAILURE

Any ideas?

Best Answer

  • the warnings you get

    [INFO] Unable to find resource 'first:first:pom:1.0.0' in repository central (http://repo1.maven.org/maven2)

    are about maven not finding the POM files for your dependencies in the central repo, not the jars. Maven will always look for POMs to check if a jar has itself more dependencies. If you install POMs for your dependencies, it will stop looking for them on the central repo.

  • the build problem you are having is different:

    /var/lib/jenkins/workspace/MyProject/src/Actions/EditorActions.java:[119,15] error while writing Actions.EditorActions.ListCheckBox: /var/lib/jenkins/workspace/MyProject/target/classes/Actions/EditorActions$ListCheckBox.class (Permission denied)

It looks like a permission issue in that workspace. Maybe you have run the build twice under different users. Or something else strange is happening.

Related Topic