首页 文章

如何阻止Maven 2.x尝试在每次构建时检索不存在的pom.xml文件以获取依赖项?

提问于
浏览
10

在我的项目中,有许多依赖项可传递地包含在其他依赖项中,这些依赖项没有任何公司存储库中提供的pom.xml文件 . 这些是由各个团队支持的内部jar专用库,为了方便起见,这些库已经上传到存储库中,但不幸的是,这些存储库不是我可以使用的 .

对于这些依赖项,Maven坚持每次运行构建时都尝试从每个存储库列表中检索poms,或 mvn dependency:list . 这意味着maven尝试从7个不同的存储库位置检索8x pom文件,并且这是通过全球企业WAN进行的;它真的很慢 .

例如对于一个特定的依赖

C:\Working\dev\workspace\project>mvn dependency:list
[INFO] Scanning for projects...
[INFO] Searching repository for plugin with prefix: 'dependency'.
[INFO] ------------------------------------------------------------------------
[INFO] Building project
[INFO]    task-segment: [dependency:list]
[INFO] ------------------------------------------------------------------------
[WARNING] Unable to get resource 'aGroupId:anArtifactId:pom:4.0.14i' from repository inhouse (http://someRepo1/proximity/repository/inhouse): While configuring wagon for 'inhouse': Unable to apply wagon configuration.
Downloading: http://someRepo1/proximity/repository/extFree/aGroupId/anArtifactId/4.0.14i/anArtifactId-4.0.14i.pom
[INFO] Unable to find resource 'aGroupId:anArtifactId:pom:4.0.14i' in repository extFree (http://someRepo1/proximity/repository/extFree)
Downloading: http://someRepo1/proximity/repository/externalNonFree/aGroupId/anArtifactId/4.0.14i/anArtifactId-4.0.14i.pom
[INFO] Unable to find resource 'aGroupId:anArtifactId:pom:4.0.14i' in repository extNonFree (http://someRepo1/proximity/repository/externalNonFree)
Downloading: http://someRepo2/efs/dist/maven/maven2-repository/incr/common/lib/aGroupId/anArtifactId/4.0.14i/anArtifactId-4.0.14i.pom
[INFO] Unable to find resource 'aGroupId:anArtifactId:pom:4.0.14i' in repository efsRepo (http://someRepo2/efs/dist/maven/maven2-repository/incr/common/lib)
Downloading: http://someRepo2/efs/dist/btijava/maven2-repository/incr/common/lib/aGroupId/anArtifactId/4.0.14i/anArtifactId-4.0.14i.pom
[INFO] Unable to find resource 'aGroupId:anArtifactId:pom:4.0.14i' in repository efsBTI (http://someRepo2/efs/dist/btijava/maven2-repository/incr/common/lib)
Downloading: http://someRepo3/maven/aGroupId/anArtifactId/4.0.14i/anArtifactId-4.0.14i.pom
[INFO] Unable to find resource 'aGroupId:anArtifactId:pom:4.0.14i' in repository internal.repo (http://someRepo3/maven)
Downloading: http://repo1.maven.org/maven2/aGroupId/anArtifactId/4.0.14i/anArtifactId-4.0.14i.pom
[INFO] Unable to find resource 'aGroupId:anArtifactId:pom:4.0.14i' in repository central (http://repo1.maven.org/maven2)`
...
etc
...
[INFO] [dependency:list {execution: default-cli}]
[INFO]
[INFO] The following files have been resolved:
... etc
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 20 seconds
[INFO] Finished at: Tue Jan 26 15:01:48 CST 2010
[INFO] Final Memory: 31M/74M
[INFO] ------------------------------------------------------------------------

另一方面,对于只是无效的POM(例如较旧的modelVersion,或者是腐败/无效的XML),它只检查我的本地仓库,抱怨它无效然后继续 . 哪个好;至少那不会在WAN上再试一次 .

有没有办法(设置,覆盖,存储库配置更改)我可以阻止Maven的依赖插件/工件解析器反复尝试找到丢失的POM,如果它已经在本地存储库中有jar文件?

规范:Maven 2.2.1(默认的superPOM插件定义)JDK 1.6.0_18

4 回答

  • 9

    Pascal的答案对于两个本地构建变通方法是正确的 . 但是,您最好的选择是请求这些项目的所有者为工件创建POM . 它们不需要复杂,Maven在内部使用的简单替代方案将起作用:

    <project>
      <modelVersion>4.0.0</modelVersion>
      <groupId>aGroupId</groupId>
      <artifactId>aArtifactId</artifactId>
      <version>4.0.14i</version>
    </project>
    
  • 2

    下载POM实际上是Maven中的一个核心概念,它支持传递依赖(实际上,依赖关系不仅仅是一个JAR,请参阅3.5.5. Maven's Dependency Management了解详情),所以我不知道你是否可以阻止它 .

    当然,正确的做法是解决问题的根本原因 . 但是,如果你不能,也许你可以在离线模式下运行你的构建(使用 -o 选项) . 或者也许您可以使用install:install-file在本地存储库中使用"install"并指示插件使用generatePom可选参数为它们生成pom(但这显然不是"scale"非常好) .

  • -1

    设置Nexus存储库(或类似)并在那里上传工件 . Nexus会自动为您上传的工件创建基本poms .

  • 4
    • 下载到本地回购

    • 设置nexus并上传

    • 离线工作

    也许最好的想法是一路摆脱maven,这是恐怖!

相关问题