Riyanka Dagaonkar
Riyanka Dagaonkar

Reputation: 33

maven build with jenkins not picking up jar from local .m2 repository

I have a jenkins job for building my maven project(say project A) which has a dependency on a jar created by another local project(say project B). The jar is present in my local .m2 repo but Jenkins fails to find it in the local repo and goes to search it in central (https://repo.maven.apache.org/maven2) which obviously it will not find and hence my job fails. I have performed the below checks before posting this question here :

  1. The version of the artifact in the dependent and independent projects match
  2. The local .m2 repository of my machine has the required dependency jar version
  3. Wrote a separate jenkins job to build project B, it built successfully and the jar is present in the .m2 repository of Jenkins home as well the path to which is /var/lib/jenkins/.m2 (In case jenkins is trying to find the jar in its own .m2 repository)
  4. Changed the Jenkins"Global Tools configuration" for Maven installation from Manual (I had manually set up the maven home) to Automatic Installation(Version 3.3.9). NO luck, the issue remained the same.
  5. NO change has been made to the maven settings.xml.
  6. If I try to build Project A manually without Jenkins by using mvn clean install, it builds successfully.

So, Its only with Jenkins that I am not able to build the project.

Here is my POM for Project A

<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>

    <groupId>com.akamai</groupId>
    <artifactId>cobra-tracer-api</artifactId>
    <version>1.0.2</version>
    <packaging>war</packaging>

    <name>cobra-tracer</name>
    <url>http://maven.apache.org</url>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>
    <build>
        <finalName>cobra-tracer</finalName>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.5.1</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
        </plugins>
    </build>

    <dependencies>
        //some dependencies here
        <dependency>
            <groupId>com.akamai.aps</groupId>
            <artifactId>logger-service</artifactId>
            <version>0.0.2</version>
        </dependency>

    </dependencies>
</project>

The POM for Project B is

<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>

    <groupId>com.akamai.aps</groupId>
    <artifactId>logger-service</artifactId>
    <version>0.0.3</version>
    <packaging>jar</packaging>

    <name>logger-service</name>
    <url>http://maven.apache.org</url>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>3.8.1</version>
            <scope>test</scope>
        </dependency>
    </dependencies>
</project>

Upvotes: 3

Views: 20955

Answers (1)

GauravJ
GauravJ

Reputation: 2272

The way you have integrated jenkins with maven is not correct. You have to use either artifactory or nexus, both of them have free versions that are sufficiently good to use. You build your project B and deploy them to above repository manager and your project A downloads it from repository manager.

For your specific problem, check

  1. In your project configuration, private repository option is checked. This will create separate repository for each jenkins executor. If your executor in jenkins master are different for A and B, you will not see your jar files.
  2. In your setup, you can't add any slaves. All build should run on master. I hope you are not running them in separate slaves.
  3. I am assuming that you have run your project 'B' using mvn install. In your project 'A' run maven command using -U flag. mvn -U install.
  4. Look at your jenkins job command line. Ensure that it is not running maven with -s flag. This is a way to pass different setting.xml. Example mvn -s /home/jenkins/setting.xml install. There is an option to define a different settings file in jenkins project configuration.
  5. Look at your maven installation path. It should be in jenkins-workspace/tools location. Check setting.xml inside /conf. Ensure that local repository is not defined. If jenkins is installing it, then it should not be set.
  6. Check if in your .m2 folder there is setting.xml file which has a different repo path.

Let me know how it goes.


Since you have added artifactory in your workflow now and facing plugin not found problem, add the following in your settings.xml

<mirrors>
  <mirror>
   <mirrorOf>*</mirrorOf>
   <name>remote-repos</name>
   <url>http://<artifactory-ip>:<artifactory-port>/artifactory/repo</url>
   <id>remote-repos</id>
  </mirror>
</mirrors>

<pluginRepositories>
  <pluginRepository>
   <snapshots>
     <enabled>false</enabled>
    </snapshots>
   <id>central</id>
   <name>plugins-release</name>
   <url>http://<artifactory-id>:<artifactory-port>/artifactory/plugins-release</url>
  </pluginRepository>
 <pluginRepository>
   <snapshots />
     <id>snapshots</id>
    <name>plugins-snapshot</name>
    <url>http://<artifactory-id>:<artifactory-port>/artifactory/plugins-snapshot</url>
 </pluginRepository>
</pluginRepositories>

I am assuming that you have already added repository tag.

Upvotes: 2

Related Questions