如何在詹金斯中构建多模块Maven项目 [英] How to build a multi-module maven project in jenkins

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

问题描述

我的项目结构如下:

ProjectParent
 - pom.xml
 ProjectApp
   -pom.xml
 ProjectAPI
   -pom.xml
 ProjectModels
   -pom.xml
 ProjectServices
   -pom.xml
 Etc..

ProjectModels/ProjectsServicesProjectAPI/ProjectApp中的依赖项.

  1. 我应该在Jenkins中创建单独的作业来分别构建每个模块吗?

  1. Should I create separate jobs within Jenkins to build each module separately?

我为ProjectAPP创建了一个作业,但在下面得到了以下错误(已将目标和操作设置为全新安装":

I created a job for ProjectAPP but get the following error below (Have set goals and actions to "clean install":

[INFO]扫描项目... [INFO]
[INFO] ----------------------------------------------- ------------------------- [INFO]构建myproject-app 0.0.1-SNAPSHOT [INFO] ----------------------------------------------- -------------------------

[INFO] Scanning for projects... [INFO]
[INFO] ------------------------------------------------------------------------ [INFO] Building myproject-app 0.0.1-SNAPSHOT [INFO] ------------------------------------------------------------------------

Downloading: http://maven.springframework.org/snapshot/com/myproject/myproject-common-config/0.0.1-SNAPSHOT/myproject-common-config-0.0.1-SNAPSHOT.pom
[WARNING] The POM for com.myproject:myproject-common-config:jar:0.0.1-SNAPSHOT is missing,

没有相关性信息 下载: http://maven.springframework.org/snapshot/com/myproject/myproject-common-config/0.0.1-SNAPSHOT/myproject-common-config-0.0.1-SNAPSHOT.jar ...... org.apache.maven.lifecycle.LifecycleExecutionException:无法在项目myproject-app上执行目标:无法解决依赖关系 对于项目com.myproject:myproject-app:war:0.0.1-SNAPSHOT: 以下工件无法解决: com.myproject:myproject-common-config:jar:0.0.1-SNAPSHOT, com.myproject:myproject-entities:jar:0.0.1-SNAPSHOT, com.myproject:myproject-services:jar:0.0.1-SNAPSHOT, com.myproject:myproject-persistence:jar:0.0.1-SNAPSHOT:找不到 工件com.myproject:myproject-common-config:jar:0.0.1-SNAPSHOT在 org.springframework.maven.snapshot ( http://maven.springframework.org/snapshot )

no dependency information available Downloading: http://maven.springframework.org/snapshot/com/myproject/myproject-entities/0.0.1-SNAPSHOT/myproject-entities-0.0.1-SNAPSHOT.pom [WARNING] The POM for com.myproject:myproject-entities:jar:0.0.1-SNAPSHOT is missing, no dependency information available Downloading: http://maven.springframework.org/snapshot/com/myproject/myproject-services/0.0.1-SNAPSHOT/myproject-services-0.0.1-SNAPSHOT.pom [WARNING] The POM for com.myproject:myproject-services:jar:0.0.1-SNAPSHOT is missing, no dependency information available Downloading: http://maven.springframework.org/snapshot/com/myproject/myproject-persistence/0.0.1-SNAPSHOT/myproject-persistence-0.0.1-SNAPSHOT.pom [WARNING] The POM for com.myproject:myproject-persistence:jar:0.0.1-SNAPSHOT is missing, no dependency information available Downloading: http://maven.springframework.org/snapshot/com/myproject/myproject-common-config/0.0.1-SNAPSHOT/myproject-common-config-0.0.1-SNAPSHOT.jar ...... org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal on project myproject-app: Could not resolve dependencies for project com.myproject:myproject-app:war:0.0.1-SNAPSHOT: The following artifacts could not be resolved: com.myproject:myproject-common-config:jar:0.0.1-SNAPSHOT, com.myproject:myproject-entities:jar:0.0.1-SNAPSHOT, com.myproject:myproject-services:jar:0.0.1-SNAPSHOT, com.myproject:myproject-persistence:jar:0.0.1-SNAPSHOT: Could not find artifact com.myproject:myproject-common-config:jar:0.0.1-SNAPSHOT in org.springframework.maven.snapshot (http://maven.springframework.org/snapshot)


ProjectParent Pom


ProjectParent Pom

<?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>com.myproject</groupId>
    <artifactId>myproject-parent</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>pom</packaging>

    <modules>
        <module>myproject-entities</module>
        <module>myproject-services</module>
        <module>myproject-persistence</module>
        <module>myproject-app</module>
        <module>myproject-merchant</module>
        <module>myproject-common-config</module>
        <module>myproject-api</module>
    </modules>

    <dependencyManagement>
        <dependencies>
            ...
        </dependencies>
    </dependencyManagement>

    <repositories>      
        ...
    </repositories>

    <build>
        ...
    </build>

    <properties>
        ...

        <myproject-entities-version>0.0.1-SNAPSHOT</myproject-entities-version>
        <myproject-services-version>0.0.1-SNAPSHOT</myproject-services-version>
        <myproject-persistence-version>0.0.1-SNAPSHOT</myproject-persistence-version>
    </properties>

</project>


ProjectApp Pom


ProjectApp Pom

<?xml version="1.0"?>
<project
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
    xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>com.myproject</groupId>
        <artifactId>myproject-parent</artifactId>
        <version>0.0.1-SNAPSHOT</version>
    </parent>

    <artifactId>myproject-app</artifactId>
    <packaging>war</packaging>

    <version>0.0.1-SNAPSHOT</version>
    <name>myproject-app</name>
    <url>http://maven.apache.org</url>


    <dependencies>

        ...

        <dependency>
            <groupId>com.myproject</groupId>
            <artifactId>myproject-common-config</artifactId>
            <version>${myproject-common-config}</version>
        </dependency>

        <dependency>
            <groupId>com.myproject</groupId>
            <artifactId>myproject-entities</artifactId>
            <version>${myproject-entities-version}</version>
        </dependency>

        <dependency>
            <groupId>com.myproject</groupId>
            <artifactId>myproject-services</artifactId>
            <version>${myproject-services-version}</version>
        </dependency>

        <dependency>
            <groupId>com.myproject</groupId>
            <artifactId>myproject-persistence</artifactId>
            <version>${myproject-persistence-version}</version>
        </dependency>

    </dependencies>

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

        <myproject-common-config>0.0.1-SNAPSHOT</myproject-common-config>
        <myproject-entities-version>0.0.1-SNAPSHOT</myproject-entities-version>
        <myproject-services-version>0.0.1-SNAPSHOT</myproject-services-version>
        <myproject-persistence-version>0.0.1-SNAPSHOT</myproject-persistence-version>
    </properties>

</project>


我使用了错误的目标吗?我需要链接多个命令吗?即首先构建其他模块?


Am I using the wrong goals? Do I need to chain a number of commands? i.e. build other modules first?

我正在使用Maven 3.

I'm using Maven 3.

注意:我将目标更改为针对ParentProject Pom的全新安装",并且一切正常.

NOTE: I changed the target to "clean install" against the ParentProject Pom and everything builds correctly.

谢谢

推荐答案

问题是您不能仅为ProjectApp模块创建项目,因为它依赖于ProjectApp父级下的其他模块.如果您不将这些模块部署到您的maven存储库中,则maven无法在存储库或构建反应器中找到它们.

The problem is that you can't create a project solely for the ProjectApp module because it depends on the other modules below the ProjectApp parent. If you don't deploy those modules to your maven repository, maven is not able to find them in the repository nor in the build reactor.

相反,您应该为父级创建作业.这将构建必要的模块.

Instead you should create the job for the parent. This will build the necessary modules.

您还可以使用 also-make-dependants 当您有ProjectApp的工作时,但我对此没有任何经验.

You may also work with the option also-make-dependants when you have a job for ProjectApp, but I haven't any experience with this.

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

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