简体   繁体   English

Jenkins和Maven多模块项目缺少工件

[英]Jenkins and maven multi module Projects missing artifacts

This is a simplified example of an ear project, the parent pom aggregates the EAR, the EJBs, and the jars. 这是Ear项目的简化示例,父pom聚合EAR,EJB和jar。

I have this structure in a Maven project, stored in SVN: 我在Maven项目中具有以下结构,存储在SVN中:

parent/
|- pom.xml
|- modulA/
|  |- pom.xml
|- modulB/
|  |- pom.xml

modulB has a Dependency of modulA modulB具有modulA的依赖关系

The pom.xml have the modules section pom.xml具有“模块”部分

<modules>
  <module>modulA</module>
  <module>modulB</module>
</modules>

And a Dependency Management section 还有一个依赖管理部分

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>group</groupId>
            <artifactId>modulA</artifactId>
            <version>0.0.2-SNAPSHOT</version>
        </dependency>
        <dependency>
            <groupId>group</groupId>
            <artifactId>modulB</artifactId>
            <version>0.0.2-SNAPSHOT</version>
        </dependency>
    </dependencies>
</dependencyManagement>

The sub-modules reference the parent 子模块引用父级

<parent>
    <groupId>group</groupId>
    <artifactId>parent</artifactId>
    <version>0.0.2-SNAPSHOT</version>
    <relativePath>..</relativePath>
</parent>

in my PC when I compile for the first time with maven 2.2.1 (windows) 在我第一次使用Maven 2.2.1进行编译时(Windows)在PC中

mvn clean compile

I don't have any problems 我没问题

but.... when Jenkins try to compile for first time (Maven 2.2.1 Linux RedHat) 但是...当Jenkins首次尝试进行编译时(Maven 2.2.1 Linux RedHat)

Missing:
----------
 1) modulA:jar:0.0.2-SNAPSHOT

   Try downloading the file manually from the project website.

   Then, install it using the command: 
      mvn install:install-file -DgroupId=group -DartifactId=modulA -Dversion=0.0.2-   SNAPSHOT -Dpackaging=jar -Dfile=/path/to/file

   Alternatively, if you host your own repository you can deploy the file there: 
      mvn deploy:deploy-file -DgroupId=group -DartifactId=modulA -Dversion=0.0.2-SNAPSHOT -Dpackaging=jar -Dfile=/path/to/file -Durl=[url] -DrepositoryId=[id]

   Path to dependency: 
      1) modulB:ejb:0.0.2-SNAPSHOT
 2) modulA:jar:0.0.2-SNAPSHOT


   ----------
   1 required artifacts are missing.

Why???????? 为什么????????

After that if I deploy the project from my pc to Artifactory, Jenkins doesn't have problems, because Jenkins downloads the artifact from the repository... but why does Jenkins depend on the artifacts in the repository? 之后,如果我将项目从我的PC部署到Artifactory,则Jenkins不会出现问题,因为Jenkins从存储库下载了工件...但是Jenkins为什么要依赖存储库中的工件?

:( :(

Thanks in Advance 提前致谢

EDIT: 编辑:

I thought the dependencyManagement section only "defines" the dependencies, but if a submodule doesn't use the dependency, the dependency isn't added to the submodule. 我以为dependencyManagement部分仅“定义”了依赖关系,但是如果子模块不使用依赖关系,则该依赖关系不会添加到子模块中。 I drop the dependencyManagement section and the problem in Jenkins still occurs. 我删除了dependencyManagement部分,Jenkins中的问题仍然出现。

It works on my PC without problems. 它可以在我的PC上正常工作。

The first time you build parent project, your Jenkins user's maven repository won't have modulA installed. 首次构建父项目时,您的Jenkins用户的maven存储库将不会安装modulA。 clean compile is then run successfully in modulA, but nothing is installed. 然后在modulA中成功运行clean compile ,但未安装任何内容。 When it is run in modulB, the dependency on modulA can't be resolved. 在modulB中运行时,无法解决对modulA的依赖性。

If your Jenkins job's goal was clean install instead of clean compile , then modulA's artifacts would be installed to the Jenkins user's repository before the modulB build begins, and all would work. 如果您的Jenkins工作的目标是全新clean install而不是clean compile ,那么在开始modulB构建之前,将modulA的工件安装到Jenkins用户的存储库中,并且一切都会正常进行。

Presumably this worked on your own machine because either you had run mvn install at least once in modulA, or because your IDE's classpath resolved the problem for you. 大概这可以在您自己的机器上工作,因为您在modulA中运行了mvn install至少一次,或者因为您IDE的类路径为您解决了该问题。

I hope above dependency management section is inside the parent pom. 我希望上面的依赖管理部分位于父pom中。 According to your requirement modulB has a Dependency of modulA. 根据您的要求,modulB具有modulA的依赖关系。 So I suggest you to include dependency in moduleB instead of having it in the parent pom. 因此,我建议您将依赖项包含在moduleB中,而不要在父pom中包含它。 I think when it runs in first time maven is looking for both dependencies since you have mentioned in in the parent pom.Look at your project build order. 我认为当它第一次运行时,maven正在查找两个依赖项,因为您已经在父pom中提到过了。请查看您的项目构建顺序。 First it builds module A and then B. In your case I hope you have include all other dependencies in moduleA's pom file and once it built it will deploy a jar file in to m2 repository. 首先,它构建模块A,然后构建模块B。在您的情况下,我希望您将所有其他依赖项都包含在模块A的pom文件中,一旦构建,它将把jar文件部署到m2存储库中。 And then moduleB start to build and since your dependency is already in the m2 repository it wont shout and project will build successfully. 然后,moduleB开始构建,并且由于您的依赖项已经在m2存储库中,因此它不会大喊大叫,并且项目将成功构建。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM