GVKun编程网logo

Jenkins无法构建多模块Maven项目(jenkins构建失败)

13

本文将分享Jenkins无法构建多模块Maven项目的详细内容,并且还将对jenkins构建失败进行详尽解释,此外,我们还将为大家带来关于Idea创建多模块maven聚合项目、Idea创建多模块mav

本文将分享Jenkins无法构建多模块Maven项目的详细内容,并且还将对jenkins构建失败进行详尽解释,此外,我们还将为大家带来关于Idea创建多模块maven聚合项目、Idea创建多模块maven聚合项目的实现、java – 如何从多模块maven项目中构建可执行jar?、java – 无法将多模块maven项目导入Eclipse(STS 2.5.2)的相关知识,希望对你有所帮助。

本文目录一览:

Jenkins无法构建多模块Maven项目(jenkins构建失败)

Jenkins无法构建多模块Maven项目(jenkins构建失败)

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

<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

<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在本地运行时,按预期方式在module5,6被调用之前,module7但是在詹金斯中,它正在尝试构建module 5然后module7使构建失败说:

[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有什么不同?感谢对此的任何帮助。

答案1

小编典典

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

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

詹金斯配置

Idea创建多模块maven聚合项目

Idea创建多模块maven聚合项目

1.怎么理解maven的继承和聚合
maven多模块项目通常由一个父模块和若干个子模块构成,每个模块都对应着一个pom.xml。它们之间通过继承和聚合(也称作多模块)相互关联。多模块适用于一些比较大的项目,通过合理的模块拆分,实现代码的复用,便于维护和管理。
继承:和java中的继承有点类似,就是父pom.xml声明的版本和引用的jar,子模块可以不用再引用直接调用。
聚合:父模块包含多个子模块就是聚合,多个子模块之间可以调用,但是要注意关系,不要两个互相依赖,这样做的好处就是可以通过一条命令进行构建

注意:
groupId是项目组织唯一的标识符,实际对应JAVA的包的结构,artifactId是项目的唯一的标识符,实际对应项目的名称,就是项目根目录的名称。groupId一般分为多个段,一般第一段为域,第二段为公司名称,第三段通常为项目名称。

2.Idea创建多模块项目

  • 2.1创建父模块(空的maven项目)

    image.png
    image.png
    image.png
    image.png

pom.xml配置
<modelVersion>4.0.0</modelVersion>  
<parent>  
 <groupId>org.springframework.boot</groupId>  
 <artifactId>spring-boot-starter-parent</artifactId>  
 <version>2.1.6.RELEASE</version>  
</parent>  
  
<groupId>cn.yskcoder.fire</groupId>  
<artifactId>fire</artifactId>  
<packaging>pom</packaging>  
<version>v1.0</version>  
  
  
<modules>  
 <module>fire-common</module>  
 <module>fire-dao</module>  
 <module>fire-service</module>  
 <module>fire-web</module>  
</modules>  
  
<properties>  
 <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>  
 <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>  
 <java.version>1.8</java.version>  
 <spring-boot.version>2.1.6.RELEASE</spring-boot.version>  
  
</properties>
  • 2.2.创建工具类(common)模块(dao、service同这个操作一样)

    image.png
    image.png
    image.png

pom.xml配置
<modelVersion>4.0.0</modelVersion>  
<parent>  
 <artifactId>fire</artifactId>  
 <groupId>cn.yskcoder.fire</groupId>  
 <version>v1.0</version>  
</parent>  
  
<!--模块信息-->  
<packaging>jar</packaging>  
<name>fire-common</name>  
<artifactId>fire-common</artifactId>  
<description>fire 通用工具类模块</description>  
  
<!--模块依赖-->  
<dependencies>  
  
</dependencies>
  • 2.3.创建数据库访问(dao)模块(只贴pom.xml代码)
<modelVersion>4.0.0</modelVersion>  
<parent>  
 <artifactId>fire</artifactId>  
 <groupId>cn.yskcoder.fire</groupId>  
 <version>v1.0</version>  
</parent>  
  
<!--模块信息-->  
<packaging>war</packaging>  
<name>fire-web</name>  
<artifactId>fire-web</artifactId>  
<description>fire web模块</description>  
  
<!--模块依赖-->  
<dependencies>  
 <dependency> <groupId>cn.yskcoder.fire</groupId>  
 <artifactId>fire-service</artifactId>  
 <version>v1.0</version>  
 </dependency>  
 <dependency> <groupId>org.springframework.boot</groupId>  
 <artifactId>spring-boot-starter-web</artifactId>  
 </dependency>  
 <dependency> <groupId>org.springframework.boot</groupId>  
 <artifactId>spring-boot-starter-aop</artifactId>  
 </dependency>  
 <dependency> <groupId>org.springframework.boot</groupId>  
 <artifactId>spring-boot-starter-test</artifactId>  
 <scope>test</scope>  
 </dependency>  
</dependencies>


<build>  
 <plugins>  
     <plugin> 
         <groupId>org.apache.maven.plugins</groupId>  
         <artifactId>maven-compiler-plugin</artifactId>  
         <version>3.1</version>  
         <configuration> 
             <source>${java.version}</source>  
             <target>${java.version}</target>  
         </configuration> 
     </plugin>
 </plugins>
  <resources>  
     <resource> 
        <directory>src/main/webapp</directory>  
        <filtering>false</filtering>  
     </resource> 
     <resource> 
         <directory>src/main/resources</directory>  
         <filtering>true</filtering>  
     </resource> 
 </resources>
</build>

3.Idea打包多模块项目
clean package -Dmaven.test.skip=true

接下来有空会继续更新这个项目
https://github.com/yskcoder/Fire

Idea创建多模块maven聚合项目的实现

Idea创建多模块maven聚合项目的实现

这篇文章主要介绍了Idea创建多模块maven聚合项目的实现,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧

1.怎么理解maven的继承和聚合

maven多模块项目通常由一个父模块和若干个子模块构成,每个模块都对应着一个pom.xml。它们之间通过继承和聚合(也称作多模块)相互关联。多模块适用于一些比较大的项目,通过合理的模块拆分,实现代码的复用,便于维护和管理。继承:和java中的继承有点类似,就是父pom.xml声明的版本和引用的jar,子模块可以不用再引用直接调用。聚合:父模块包含多个子模块就是聚合,多个子模块之间可以调用,但是要注意关系,不要两个互相依赖,这样做的好处就是可以通过一条命令进行构建注意:groupId是项目组织唯一的标识符,实际对应JAVA的包的结构,artifactId是项目的唯一的标识符,实际对应项目的名称,就是项目根目录的名称。groupId一般分为多个段,一般第一段为域,第二段为公司名称,第三段通常为项目名称。2.Idea创建多模块项目2.1创建父模块(空的maven项目)

pom.xml配置 4.0.0org.springframework.bootspring-boot-starter-parent2.1.6.RELEASEcn.yskcoder.firefirepomv1.0fire-commonfire-daofire-servicefire-webUTF-8UTF-81.82.1.6.RELEASE2.2.创建工具类(common)模块(dao、service同这个操作一样)

pom.xml配置 4.0.0firecn.yskcoder.firev1.0jarfire-commonfire-commonfire 通用工具类模块2.3.创建数据库访问(dao)模块(只贴pom.xml代码)4.0.0firecn.yskcoder.firev1.0warfire-webfire-webfire web模块cn.yskcoder.firefire-servicev1.0org.springframework.bootspring-boot-starter-weborg.springframework.bootspring-boot-starter-aoporg.springframework.bootspring-boot-starter-testtestorg.apache.maven.pluginsmaven-compiler-plugin3.1${java.version}${java.version}src/main/webappfalsesrc/main/resourcestrue3.Idea打包多模块项目clean package -Dmaven.test.skip=true接下来有空会继续更新这个项目https://github.com/yskcoder/Fire以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持小编。

java – 如何从多模块maven项目中构建可执行jar?

java – 如何从多模块maven项目中构建可执行jar?

我是初学者,不懂很多东西.我可以构建简单的可执行jar,但是如何将multimodule maven项目构建成可执行的jar对我而言是魔术.所以我有三个项目.
家长:
<?xml version="1.0" encoding="UTF-8"?>
<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>org.example</groupId>
    <artifactId>Test</artifactId>
    <packaging>pom</packaging>
    <version>1.0-SNAPSHOT</version>
    <modules>
        <module>Main</module>
        <module>Dep</module>
    </modules>
</project>

和两个孩子项目:

<?xml version="1.0" encoding="UTF-8"?>
<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">
    <parent>
        <artifactId>Test</artifactId>
        <groupId>org.example</groupId>
        <version>1.0-SNAPSHOT</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <artifactId>Main</artifactId>

    <dependencies>
        <dependency>
            <groupId>org.example</groupId>
            <artifactId>Dep</artifactId>
            <version>1.0-SNAPSHOT</version>
        </dependency>
    </dependencies>
</project>

和:

<?xml version="1.0" encoding="UTF-8"?>
<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">
    <parent>
        <artifactId>Test</artifactId>
        <groupId>org.example</groupId>
        <version>1.0-SNAPSHOT</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <artifactId>Dep</artifactId>
</project>

主模块主要有main方法(lol)

public class Main {
    public static void main(String[] args) {
        Hello hello = new Hello();
        System.out.println(hello.sayHello());
    }
}

“类别”在“Dep”模块中定义.我应该添加到我的poms来构建可执行jar与Main类从主模块作为入口点?

解决方法

你需要改变你的pom为人造物主.
您需要添加maven-assembly-plugin

在配置中,您可以选择在清单中指定mainClass.这应该是Main类的完全限定名称.

<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>
    <parent>
        <groupId>org.example</groupId>
        <artifactId>Test</artifactId>
        <version>1.0-SNAPSHOT</version>
    </parent>
    <artifactId>Main</artifactId>

    <properties>
        <!-- plugins -->
        <maven.assembly.plugin.version>2.4</maven.assembly.plugin.version>
        <!-- dependencies -->
        <dep.version>1.0-SNAPSHOT</dep.version>
    </properties>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-assembly-plugin</artifactId>
            </plugin>
        </plugins>

        <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-assembly-plugin</artifactId>
                    <version>2.4</version>
                    <configuration>
                        <descriptorRefs>
                            <descriptorRef>jar-with-dependencies</descriptorRef>
                        </descriptorRefs>
                        <archive>
                            <manifest>
                                <mainClass>Main</mainClass>
                            </manifest>
                        </archive>
                    </configuration>
                    <executions>
                        <execution>
                            <id>make-assembly</id>
                            <phase>package</phase>
                            <goals>
                                <goal>single</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </pluginManagement>
    </build>

    <dependencies>
        <dependency>
            <groupId>org.example</groupId>
            <artifactId>Dep</artifactId>
            <version>${dep.version}</version>
        </dependency>
    </dependencies>
</project>

在父项目上启动构建之后,应该在模块Main的目标子文件夹中创建可执行jar. (一个名为Main-1.0-SNAPSHOT-jar-with-dependencies.jar的jar是我得到的)

java – 无法将多模块maven项目导入Eclipse(STS 2.5.2)

java – 无法将多模块maven项目导入Eclipse(STS 2.5.2)

我刚刚花了最后一小时在Stackoverflow.com上查看线程,尝试将Maven项目导入 Spring ToolSuite 2.5.2.

Maven项目有多个模块,当我使用STS中的Import …向导导入项目时,Package Explorer中列出了所有模块,并且未解析某些模块依赖项.

可以建议将多模块Maven项目导入STS / Eclipse的正确方法,以便所有模块都出现在Parent目录下吗?
所有模块依赖关系都解决了吗?

该项目位于文件系统的层次结构中,
我已经尝试了各种更新依赖项,项目配置选项,但都无济于事.
我在IDE中安装了嵌入式Maven版本.

谢谢你的时间.

解决方法

M2Eclipse在解决项目间依赖关系方面做得很好.如果它不起作用,也许您的项目结构有错误.检查:

>每个子项目都引用父项目的正确版本
>每个依赖项都具有与工作空间中当前项目版本对应的版本
>每个子项目都注册为< module>在父pom中(如果在配置文件中定义模块,则配置文件必须处于活动状态).

如果这些版本不匹配,则引用的工件将从本地存储库中提取,而不是从eclipse工作空间中提取.

关于常见的根项目:我认为拥有一个通用项目不是一个好主意,但我想到的Eclipse概念(以及我用于多模块项目)是一个工作集.

在Package Explorer中,将顶级元素切换为工作集:

现在从同一菜单中选择配置工作集….

这是一个工作集,其中包含maven3主干和所有子模块作为单独的项目:

今天关于Jenkins无法构建多模块Maven项目jenkins构建失败的分享就到这里,希望大家有所收获,若想了解更多关于Idea创建多模块maven聚合项目、Idea创建多模块maven聚合项目的实现、java – 如何从多模块maven项目中构建可执行jar?、java – 无法将多模块maven项目导入Eclipse(STS 2.5.2)等相关知识,可以在本站进行查询。

本文标签: