如何在詹金斯建立一个多模块的maven项目

时间:2013-04-21 21:42:16

标签: maven jenkins

我的项目结构如下:

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

ProjectModels/ProjectsServicesProjectAPI/ProjectApp中的依赖项。

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

  2. 我为ProjectAPP创建了一个作业,但在下面收到以下错误(已将目标和操作设置为“清理安装”:

  3.   

    [INFO]扫描项目......       [INFO]
          [INFO] ----------------------------------------------- -------------------------       [INFO]构建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-entities/0.0.1-SNAPSHOT/myproject-entities-0.0.1-SNAPSHOT.pom       [警告] com.myproject的POM:myproject-entities:jar:0.0.1-SNAPSHOT丢失,没有   可用的依赖信息       正在下载:http://maven.springframework.org/snapshot/com/myproject/myproject-services/0.0.1-SNAPSHOT/myproject-services-0.0.1-SNAPSHOT.pom       [警告] com.myproject的POM:myproject-services:jar:0.0.1-SNAPSHOT丢失,没有   可用的依赖信息       正在下载:http://maven.springframework.org/snapshot/com/myproject/myproject-persistence/0.0.1-SNAPSHOT/myproject-persistence-0.0.1-SNAPSHOT.pom       [警告] com.myproject的POM:myproject-persistence:jar:0.0.1-SNAPSHOT缺失,没有   可用的依赖信息       正在下载: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:The   以下工件无法解决:   com.myproject:MyProject的,共配置中:jar:0.0.1 - 快照   com.myproject:MyProject的实体中:jar:0.0.1 - 快照   com.myproject:MyProject的服务中:jar:0.0.1 - 快照   com.myproject:myproject-persistence:jar:0.0.1-SNAPSHOT:找不到   artifact com.myproject:myproject-common-config:jar:0.0.1-SNAPSHOT in   org.springframework.maven.snapshot   (http://maven.springframework.org/snapshot


    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

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


    我使用了错误的目标吗?我需要链接一些命令吗?即先建立其他模块?

    我正在使用Maven 3。

    注意:我针对ParentProject Pom将目标更改为“clean install”,所有内容都正确构建。

    由于

2 个答案:

答案 0 :(得分:4)

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

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

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

答案 1 :(得分:1)

遇到同样的问题,SpaceTrucker的回答帮助了我。

因此,我只是运行:

.../ProjectParent$ mvn -am -pl ProjectApp test