Jenkins无法构建多模块Maven项目 [英] Jenkins fails to build multi-module Maven project

查看:1170
本文介绍了Jenkins无法构建多模块Maven项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个多模块Maven项目,其中有多个微服务作为模块,因此我的父级pom.xml中列出了一些模块,如下所示:

I have a multi-module Maven project where I have multiple micro services as modules so I have modules listed in my parent pom.xml like below:

<modules>
    <module>core</module>
    <module>model-base</module>
    <module>module1</module>
    <module>module2</module>
    ...
    <module>module5</module>
    <module>module7</module>
    <module>module6</module>
</modules>

这里module7依赖于module5, 6,所以我在module7 pom.xml中具有如下所列的依赖关系:

Here the module7 is dependent on module5, 6 so I have dependencies listed like below in my module7 pom.xml:

<parent>
    <artifactId>pojectA</artifactId>
    <groupId>com.domain</groupId>
    <version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>module7</artifactId>
<dependencies>
    <dependency>
        <groupId>com.domain</groupId>
        <artifactId>core</artifactId>
        <version>1.0-SNAPSHOT</version>
    </dependency>
    <dependency>
        <groupId>com.domain</groupId>
        <artifactId>module5</artifactId>
        <version>1.0-SNAPSHOT</version>
    </dependency>
    <dependency>
        <groupId>com.domain</groupId>
        <artifactId>module6</artifactId>
        <version>1.0-SNAPSHOT</version>
    </dependency>
</dependencies> 

当我在本地运行mvn clean package时,按预期在module7之前调用module5, 6,但是在Jenkins中,它正在尝试构建module 5,然后module7使得构建失败:

When I run mvn clean package in my local the module5, 6 called before the module7 as expected but in Jenkins it is trying to build module 5 then module7 making build fail saying:

[ERROR] Failed to execute goal on project module7: Could not resolve dependencies for project module7:jar:1.0-SNAPSHOT: Could not find artifact module6:jar:1.0-SNAPSHOT -> [Help 1]

我是否还需要运行其他作业或重新排序pom.xml中的模块,从本地到Jenkins有什么不同?感谢任何帮助.

Do I need to run any other jobs or re-order the modules in my pom.xml, how is it differ from local to Jenkins? Appreciate any help on this.

推荐答案

众所周知,问题在于子模块之间的依赖关系失败,因为它们尚未安装在本地存储库中(因为它们是尚未建立).导致此问题(无论如何对我而言)的目标是mvn test,由mvn package调用.您的本地版本可能有效,因为在某些时候您已经完成了mvn install,这已经引导了您的系统.

As is probably quite well understood, the issue is that the dependencies between the child modules fail because they aren't installed in the local repository yet (because they are yet to be built). The goal that causes this (for me anyway) is mvn test, which is invoked by mvn package. Your local build probably works because at some point you've done a mvn install and this has bootstrapped your system.

在Jenkins中,我发现使这些构建起作用的唯一方法是使用预构建步骤调用Maven安装目标,然后照常构建主要步骤.

In Jenkins the only way I've found to make these builds work is to use the Pre-build step invoking a Maven target of install, and then build the main step as usual.

这篇关于Jenkins无法构建多模块Maven项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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