彻底解决Failed to execute goal on project xxxxx

1、错误内容:Could not resolve dependencies for project

今天在使用mvn clean package命令对一个子项目打包的时候出现如下错误(但是使用maven插件却没有问题)

Failed to execute goal on project xxxx: Could not resolve
dependencies for project xxxx:jar:0.0.1-SNAPSHOT:
Could not find artifact 公共包:jar:0.0.1-SNAPSHOT

在网上找了很多资料都没有找到相应的解决方法,有的说不要在公共模块添加maven插件,有的说在公共模块添加

<skip>true</skip>

但是都无济于事。

2、解决方案

通过控制台给出的建议

[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/DependencyResolutionException

看到这里头都大了,然后我自己思考了一下,为什么我引用的中心仓库的依赖打包时没有问题,但是引用我本地仓库的依赖(公共包)却有问题(提前需要对公共包进行mvn clean install,保证本地仓库有公共jar包)。然后就想到当时配置maven的时候配置了阿里云的远程仓库,如果我配置一下本地的仓库是不是也可以?因此,加入以下配置就解决了无法处理本地依赖包的问题

<localRepository>D:\maven\apache-maven-3.8.4\repository</localRepository>

添加的位置在mirrors标签前面

3、解决原理

我认为在没有配置本地仓库的情况下,使用命令进行打包的时候先找配置的仓库,找不到的话再寻找maven中心仓库,再找不到就报错。配置过本地仓库的情况下,就可以直接在本地仓库查找,因此就可以找到本地的公共包。

4、疑问

由于我需要使用函数计算对项目进行部署,想在部署前运行mvn clean package命令,结果出现了报错,但是使用maven插件如下进行打包却没有问题,希望大佬进行指点。

<build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <version>2.6.4</version>
                <configuration>
                    <excludes>
                        <exclude>
                            <groupId>org.projectlombok</groupId>
                            <artifactId>lombok</artifactId>
                        </exclude>
                    </excludes>
                </configuration>
            </plugin>
        </plugins>
    </build>
posted @ 2022-04-22 23:34  Java僧  阅读(3135)  评论(0编辑  收藏  举报