【问题标题】:In-project Maven Repository causing dependency errors项目内 Maven 存储库导致依赖错误
【发布时间】:2014-10-17 07:59:22
【问题描述】:

这个 Maven 错误让我很困惑,所以我需要一些帮助。 我有一个项目,它声明了一个这样的项目内 repo:

<parent>
    <groupId>ca.gc.agr.common</groupId>
    <artifactId>drydock-parent</artifactId>
    <relativePath>../DryDockPOM/pom.xml</relativePath>
</parent>
<artifactId>CognosReportService</artifactId>
<packaging>jar</packaging>
<version>2.0</version>

<name>CognosReportService</name>

<!-- In Project repository  -->
<repositories>
    <repository>
        <id>in-project</id>
        <name>In Project Repo</name>
        <url>file://${project.basedir}/libs</url>
    </repository>
</repositories> 

<dependencies>
    ... stuff ...

    <dependency>
        <groupId>cognos-sdk</groupId>
        <artifactId>cognos-client</artifactId>
        <version>8.4.1</version>
    </dependency>

    <dependency>
        <groupId>cognos-sdk</groupId>
        <artifactId>cognos-axis</artifactId>
        <version>8.4.1</version>
    </dependency>

    ... stuff ...

</dependencies>

还有另一个项目像这样使用这个:

<parent>
    <groupId>ca.gc.agr.common</groupId>
    <artifactId>common-web-parent</artifactId>
    <relativePath>../DryDockWebPOM/pom.xml</relativePath>
</parent>
<artifactId>CognosReportWeb</artifactId>
<packaging>jar</packaging>
<version>2.0</version>

<name>CognosReportWeb</name>

<dependencies>

    ... stuff ....

    <dependency>
        <groupId>ca.gc.agr.common</groupId>
        <artifactId>CognosReportService</artifactId>    
        <version>[1.0,)</version>
    </dependency>

    ... stuff ....

</dependencies>

如果我转到父项目并从那里执行mvn install,则一切正常。但是,如果我尝试自己构建CognosReportWeb,我会得到:

[ERROR] Failed to execute goal on project CognosReportWeb: Could not resolve dependencies for project ca.gc.agr.common:CognosReportWeb:jar:2.0: 
Failed to collect dependencies for [ca.gc.agr.common:CognosReportService:jar:[1.0,) (compile),
 ca.gc.agr.common:CommonWebJar:jar:[1.0,) (compile),
 org.apache.tomcat:tomcat-servlet-api:jar:7.0.16 (provided),
 javax.servlet.jsp:jsp-api:jar:2.2 (provided),
 javax.el:el-api:jar:2.2 (provided),
 org.glassfish.web:el-impl:jar:2.2 (provided),
 com.sun.faces:jsf-api:jar:2.1.7 (compile),
 com.sun.faces:jsf-impl:jar:2.1.7 (compile),
 org.apache.myfaces.tomahawk:tomahawk20:jar:1.1.10 (compile),
 org.richfaces:richfaces-bom:pom:4.2.0.Final (compile),
 org.richfaces.ui:richfaces-components-ui:jar:4.2.0.Final (compile),
 org.richfaces.core:richfaces-core-impl:jar:4.2.0.Final (compile),
 org.primefaces:primefaces:jar:5.0 (compile),
 org.springframework:spring-web:jar:4.0.0.RELEASE (compile),
 com.cybozu.labs:langdetect:jar:1.1-20120112 (compile),
 org.apache.myfaces.test:myfaces-test20:jar:1.0.7 (test),
 org.aspectj:aspectjweaver:jar:1.7.4 (compile),
 org.springframework:spring-context:jar:4.0.0.RELEASE (compile),
 org.springframework:spring-aspects:jar:4.0.0.RELEASE (compile),
 org.springframework:spring-tx:jar:4.0.0.RELEASE (compile),
 org.springframework:spring-test:jar:4.0.0.RELEASE (compile),
 org.springframework:spring-orm:jar:4.0.0.RELEASE (compile),
 org.springframework:spring-oxm:jar:4.0.0.RELEASE (compile),
 org.springframework:spring-jdbc:jar:4.0.0.RELEASE (compile),
 org.hibernate:hibernate-core:jar:4.1.7.Final (compile),
 commons-io:commons-io:jar:1.3.2 (compile),
 commons-lang:commons-lang:jar:2.4 (compile),
 commons-beanutils:commons-beanutils:jar:1.8.3 (compile),
 commons-validator:commons-validator:jar:1.3.1 (compile),
 log4j:log4j:jar:1.2.17 (compile),
 org.slf4j:slf4j-log4j12:jar:1.7.6 (compile),
 junit:junit:jar:4.11 (compile),
 junit-addons:junit-addons:jar:1.4 (compile),
 com.googlecode.log4jdbc:log4jdbc:jar:1.2 (compile),
 org.reflections:reflections:jar:0.9.9-RC1 (compile),
 oro:oro:jar:2.0.8 (compile),
 dbunit:dbunit:jar:2.1 (compile),
 com.h2database:h2:jar:1.3.175 (compile)]: 

 Failed to read artifact descriptor for org.aspectj:aspectjweaver:jar:1.8.0.M1: 
    Could not transfer artifact org.aspectj:aspectjweaver:pom:1.8.0.M1 from/to in-project (file://${project.basedir}/libs): 
        Repository path /libs does not exist, and cannot be created. -> [Help 1]

乍一看,org.aspectj:aspectjweaver:pom:1.8.0.M1 似乎有问题,但如果我在CognosReportService 中注释掉我自己的项目内存储库(并重新安装),突然CognosReportWeb 开始工作.

我真的很难过。难道我做错了什么?

任何想法都将不胜感激!

【问题讨论】:

    标签: maven maven-3


    【解决方案1】:

    Re “如果我在 CognosReportService 中注释掉我自己的项目内存储库(并重新安装),突然 CognosReportWeb 开始工作。”

    然后使用您的本地 Maven 存储库(默认 ~/.m2/repository 或根据您的 settings.xmls),并且已知它可以可靠地工作。所以,它不是突然起作用,它是按设计起作用的。 ;-)

    最后的信息给出了一个重要的提示。 org.aspectj:aspectjweaver:pom:1.8.0.M1 在 file://${project.basedir}/libs 中吗?

    使用这个额外存储库的原因是什么?

    【讨论】:

    • 使用额外 repo 的原因是我可以使用一些 3rd 方 jar 作为 maven 依赖项。我想不出另一种方法来确保人们可以在查看我的源代码后运行 Maven 构建,而无需手动将这些 jar 插入到他们的本地 repo 中。
    【解决方案2】:

    如果依赖项在 Maven Central 中不可用,并且您希望确保签出您的代码的任何人都能够在不进行额外配置或安装 jar 的情况下构建您的源代码,然后找到任何替代公共存储库,其中包含该依赖项托管。

    并像您所做的那样将其添加到您的项目中(使用基于本地文件的 repo 除外)。

    <repositories>
        <repository>
            <id>opencastproject</id>
            <url>http://repository.opencastproject.org/nexus/content/repositories/public/</url>
        </repository>
    </repositories>
    

    但在您的情况下,类似或更新版本的 org.aspectj:aspectjweaver 库在 Maven 中心 - http://central.maven.org/maven2/org/aspectj/aspectjweaver/ 中可用,因此您可能只需使用

    <dependency>
        <groupId>org.aspectj</groupId>
        <artifactId>aspectjweaver</artifactId>
        <version>1.8.2</version>
    </dependency>
    

    改为?

    【讨论】:

    • 我认为问题与 aspectjweaver 无关。 Hibernate 或 Spring 中的其他一些 pom 请求了有问题的版本,因此我总是看到该警告,但构建成功。我试图放入项目内 repo 的 jar 在任何公共 repo 中都不可用,b/c 它们用于一个非常模糊的专有系统。我通过在我们的组织中安装 Nexus 并将专有 jar 放在那里解决了这个问题,所以现在构建工作。不过,我在项目内回购中遇到的错误似乎仍然是一个错误。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-10
    • 2011-03-26
    • 1970-01-01
    • 2020-10-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多