Maven项目无法在本地仓库中找到依赖项。

6

我有一个Maven项目的设置。

在我的Maven 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>

    <parent>
        <groupId>com.myProject</groupId>
        <artifactId>basePOM</artifactId>
        <version>1.0</version>
        <relativePath>../../../shared/common/pom.xml</relativePath>
    </parent>

    <groupId>com.myProject.services</groupId>
    <artifactId>orderservice</artifactId>
    <version>developer</version>
    <packaging>war</packaging>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-resources-plugin</artifactId>
                <version>2.3</version>
                <configuration>
                    <encoding>UTF-8</encoding>
                </configuration>
            </plugin>
        </plugins>
    </build>

    <dependencies>
        <!--Internal dependencies-->
        <dependency>
            <groupId>com.myProject.shared</groupId>
            <artifactId>model</artifactId>
        </dependency>
        <dependency>
            <groupId>org.jboss.resteasy</groupId>
            <artifactId>resteasy-jaxrs</artifactId>
        </dependency>

        <dependency>
            <groupId>org.jboss.resteasy</groupId>
            <artifactId>resteasy-spring</artifactId>
        </dependency>
    </dependencies>
</project>

我有一个父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>

    <name>Base POM</name>
    <groupId>com.myProject</groupId>
    <artifactId>basePOM</artifactId>
    <version>1.0</version>
    <packaging>pom</packaging>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>com.myProject.shared</groupId>
                <artifactId>model</artifactId>
                <version>developer</version>
            </dependency>

            <dependency>
                <groupId>org.jboss.resteasy</groupId>
                <artifactId>resteasy-jaxrs</artifactId>
                <version>1.2.GA</version>
                <exclusions>
                    <exclusion>
                        <groupId>org.slf4j</groupId>
                        <artifactId>slf4j-simple</artifactId>
                    </exclusion>
                </exclusions>
            </dependency>

            <dependency>
                <groupId>org.jboss.resteasy</groupId>
                <artifactId>resteasy-spring</artifactId>
                <version>1.2.GA</version>
            </dependency>
        </dependencies>
    </dependencyManagement>
</project>

当我运行时,
mvn clean install

我已经成功将resteasy-jaxrs和resteasy-spring下载到本地仓库。

然而,它后来出现了一个错误:

**[ERROR] Failed to execute goal on project orderservice: Could not resolve dependencies for
 project com.mxyy.services:orderservice:war:developer: Failed to collect dependencies for
[com.mxyy.shared:model:jar:developer (compile), org.jboss.resteasy:resteasy-jaxrs:jar:1.2.
GA (compile), org.jboss.resteasy:resteasy-spring:jar:1.2.GA (compile), org.testng:testng:j
ar:jdk15:5.8 (test)]: Failed to read artifact descriptor for com.mxyy.shared:model:jar:dev
eloper: Failure to find com.mxyy:basePOM:pom:1.0 in http://repo.maven.apache.org/maven2 wa
s cached in the local repository, resolution will not be reattempted until the update inte
rval of central has elapsed or updates are forced -> [Help 1]**

看起来项目无法使用本地存储库中已有的依赖项。

可以有人告诉我如何解决这个问题吗?

非常感谢。

更多信息:

我暂时删除了依赖项com.myProject.shared。现在错误消息变成了:

[ERROR] Failed to execute goal on project orderservice: Could not resolve dependencies for project com.mxyy.services:orderservice:war:developer: Faile
d to collect dependencies for [org.jboss.resteasy:resteasy-jaxrs:jar:1.2.GA (compile), org.jboss.resteasy:resteasy-spring:jar:1.2.GA (compile)]: Faile
d to read artifact descriptor for org.scannotation:scannotation:jar:1.0.2: Could not transfer artifact org.scannotation:scannotation:pom:1.0.2 from/to
 jboss (http://repository.jboss.org/maven2): Access denied to: http://repository.jboss.org/maven2/org/scannotation/scannotation/1.0.2/scannotation-1.0
.2.pom, ReasonPhrase:Forbidden. -> [Help 1]
4个回答

12

6

mvn clean install 命令需要先对你的 model 项目进行操作,将其构建并安装到本地仓库中,以便后续的构建过程能够找到相关的构件。

编辑:

如果仍然无法解决问题,可以使用 -X 开关来显示更多的错误/调试信息:

mvn -X clean install

1
谢谢您的回复。问题并没有解决,因为我的模型已经在存储库中了,但它无法获取这三个依赖项。 - Kevin

0

仅仅看一下你的错误输出(我猜测你没有手动输入),似乎你将组ID从myProject误输为了mxProject。


哦,对不起。我手动键入了那部分内容以隐藏我的公司名称。对此我感到抱歉。这不是原因。 :) - Kevin
哦,我明白了 :) 下载/构建的依赖项的pom文件正确吗? - jmluy
我已经添加了项目中使用的两个POM。我有一个包含一些公共部分的父POM。请参见原始问题。 - Kevin

-1

请仔细检查依赖声明(artifactId和groupId),可能只是一个打字错误;)


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接