使用jenkins的Maven构建未从本地.m2存储库中提取jar [英] maven build with jenkins not picking up jar from local .m2 repository

查看:56
本文介绍了使用jenkins的Maven构建未从本地.m2存储库中提取jar的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个jenkins工作来构建我的Maven项目(例如项目A),该项目依赖于另一个本地项目(例如项目B)创建的jar.该jar存在于我的本地.m2存储库中,但Jenkins未能在本地存储库中找到它,而是在中央进行搜索(

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. 从属项目和独立项目中工件的版本匹配
  2. 我的计算机的本地.m2存储库具有所需的依赖项jar版本
  3. 编写了一个单独的jenkins作业来构建项目B,它成功构建,并且jar存在于Jenkins主页的.m2存储库中,以及/var/lib/jenkins/.m2的路径(如果jenkins是尝试在其自己的.m2存储库中找到该罐子)
  4. 将用于Maven安装的Jenkins全局工具配置"从手动"(我已经手动设置了maven home)更改为自动安装"(版本3.3.9).真不走运,问题依旧.
  5. 未对Maven settings.xml进行任何更改.
  6. 如果我尝试通过使用 mvn clean install 手动构建没有Jenkins的Project A,它将成功构建.
  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.

因此,只有Jenkins才能构建该项目.

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

这是我针对项目A的POM

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>

项目B的POM为

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

推荐答案

将jenkins与maven集成的方式不正确.您必须使用人工工厂

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. 在您的项目配置中,选中了私有存储库选项.这将为每个jenkins执行程序创建单独的存储库.如果您在jenkins master中的执行者对于A和B不同,那么您将看不到jar文件.
  2. 在您的设置中,您无法添加任何从属.所有构建都应在主版本上运行.希望您不要在单独的从站中运行它们.
  3. 我假设您已经使用 mvn install 运行了项目"B".在项目"A"中,使用-U标志运行maven命令. mvn -U install .
  4. 查看您的jenkins作业命令行.确保它没有运行带有-s标志的Maven.这是一种传递不同的setting.xml的方法.示例 mvn -s/home/jenkins/setting.xml安装.有一个选项可以在jenkins项目配置中定义其他设置文件.
  5. 查看您的Maven安装路径.它应该在jenkins-workspace/tools位置.检查/conf中的setting.xml.确保未定义本地存储库.如果jenkins正在安装它,则不应设置它.
  6. 检查您的.m2文件夹中是否有具有不同回购路径的setting.xml文件.
  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.

让我知道怎么回事.

由于您现在已经在工作流程中添加了工件,并且面临未找到插件的问题,因此请在settings.xml中添加以下内容

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.

这篇关于使用jenkins的Maven构建未从本地.m2存储库中提取jar的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆