英文:
Different between mvn clean, mvn install and mvn clean install
问题
我正在使用Maven进行项目开发。如果我的项目不使用某些本地资源,那是没有问题的。
因此,我正在遵循这个指南:
https://stackoverflow.com/a/61576687/6720896
将我的本地JAR包复制到本地Maven仓库,并通过Maven进行验证。
正如你所见,在maven-install-plugin
中,我设置在clean
阶段安装到本地仓库。
这意味着通过运行mvn clean
,Maven将会把我的JAR包复制到Maven本地仓库。
问题是,如果我分别运行mvn clean
和mvn install
两个命令,就没有问题。
但是如果我运行mvn clean install
,构建就会失败,日志中显示:
Caused by: org.apache.maven.project.DependencyResolutionException: 无法为项目 xxxx:xxxx:war:0.0.1-SNAPSHOT 解析依赖项: 无法在 https://repo.maven.apache.org/maven2 中找到 org.xxxx:xxxx-ws:jar:1.0.0 ,它已被缓存在本地仓库中,只有在中央仓库的更新间隔过去或强制更新后才会重新尝试解析
看起来,默认情况下,Maven总是按照以下顺序执行:验证(validate) > 编译(compile) > 清理(clean) > 安装(install)。我还尝试过使用 mvn clean validate
,但错误仍然出现。
谢谢阅读。
英文:
I'm using Maven for my project. It is not an issue if my project doesn't use some local resources.
So that I'm following this guide
https://stackoverflow.com/a/61576687/6720896
to copy my local jar to local maven repository and validated by Maven.
As you can see, in the maven-install-plugin
, I'm setting to install local repository at clean
phase.
It means by mvn clean
, maven will copy my jar to maven local repository.
The problem is, if I run mvn clean
and mvn install
by two commands separately => there is no problem
If i run mvn clean install
=> the build is failed as the log
Caused by: org.apache.maven.project.DependencyResolutionException: Could not resolve dependencies for project xxxx:xxxx:war:0.0.1-SNAPSHOT: Failure to find org.xxxx:xxxx-ws:jar:1.0.0 in https://repo.maven.apache.org/maven2 was cached in the local repository, resolution will not be reattempted until the update interval of central has elapsed or updates are forced
Seem like by default, maven always execute following order: validate > compile > clean > install. I also tried with 'mvn clean validate' but the error still occurs.
Thank you for reading.
答案1
得分: 5
问题并不是很清楚,但我的解释如下:
楼主想要通过使用install:install-file
将一个依赖项自动添加到本地仓库。然后楼主想要使用那个依赖项。如果分别运行mvn clean
和mvn install
,这样是可以的,但如果运行mvn clean install
就不行。
原因如下:
Maven在进程开始时解析依赖关系。因此,在执行mvn clean install
的clean
之前,依赖关系已经被解析。
这尤其意味着你不能在同一次 Maven 运行中安装和解析一个依赖项。
然而,如果你首先运行mvn clean
(它会安装依赖项),然后再运行mvn install
(它会使用依赖项),一切都没问题。
英文:
The question is not really clear, but my interpretation is as follows:
The OP wants to automatically add a dependency to the local repository by using install:install-file
. Then the OP wants to use that dependency. This works if mvn clean
and mvn install
are run separately, but not if one runs mvn clean install
.
The reason is as follows:
Maven resolves dependencies at the beginning of the process. So dependencies are already resolved before the clean
of mvn clean install
is executed.
This especially implies that you cannot install and resolve a dependency in the same Maven run.
If, though, you first run mvn clean
(which installs the dependency) and then mvn install
(which uses the dependency), everything is fine.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论