抽风的Maven、maven插件及配置
阅读原文时间:2023年07月08日阅读:1

Idea 配合 Maven使用中有时遇到莫名奇妙的问题,又莫名奇妙的恢复正常。整理如下:

1、删除系统环境变量Maven_Home,只需在IDEA中指定Maven及settings.xml即可。

有时,系统环境变量中的Maven和IDEA中指定Maven地址不一致时,IDEA会加载系统环境变量中的Maven settings.xml配置。

2、Invalidate Caches 清理缓存。

  有时错误的缓存,或者在控制台手动执行过mvn命令,却未指定正确的settings.xml 导致依赖下载失败。

3、mirrorOf 排除

aliyunmaven !central,* 阿里云公共仓库 https://maven.aliyun.com/repository/public

合理排除其他repository,避免*全走阿里云。

4、删除apache-maven/conf 下默认的settings.xml配置。

5、maven插件Lifecycle下clean成功,install失败,依赖不去本地仓库找,非要上远程仓库找,各种无解。。。

"D:\Program Files\Java\jdk1.8.0_171\bin\java.exe" -Dmaven.multiModuleProjectDirectory=D:\project\RuoYi\ruoyi-system -Dmaven.home=D:\Software\apache-maven\apache-maven\apache-maven-3.6.1 -Dclassworlds.conf=D:\Software\apache-maven\apache-maven\apache-maven-3.6.1\bin\m2.conf "-Dmaven.ext.class.path=D:\Program Files\JetBrains\ideaIU-2021.1.3.win\plugins\maven\lib\maven-event-listener.jar" "-javaagent:D:\Program Files\JetBrains\ideaIU-2021.1.3.win\lib\idea_rt.jar=63782:D:\Program Files\JetBrains\ideaIU-2021.1.3.win\bin" -Dfile.encoding=UTF-8 -classpath D:\Software\apache-maven\apache-maven\apache-maven-3.6.1\boot\plexus-classworlds-2.6.0.jar org.codehaus.classworlds.Launcher -Didea.version=2021.1.3 -s D:\maven_repository\ruoyi_settings.xml install
[INFO] Scanning for projects…
[INFO]
[INFO] -----------------------< com.ruoyi:ruoyi-system >-----------------------
[INFO] Building ruoyi-system 4.7.5
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.753 s
[INFO] Finished at: 2022-12-27T13:40:45+08:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal on project ruoyi-system: Could not resolve dependencies for project com.ruoyi:ruoyi-system:jar:4.7.5: Failed to collect dependencies at com.ruoyi:ruoyi-common:jar:4.7.5: Failed to read artifact descriptor for com.ruoyi:ruoyi-common:jar:4.7.5: Failure to find com.ruoyi:ruoyi:pom:4.7.5 in https://maven.aliyun.com/repository/public was cached in the local repository, resolution will not be reattempted until the update interval of public has elapsed or updates are forced -> [Help 1]
[ERROR]
[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

Process finished with exit code 1

在 idea terminal 项目路径下执行

"D:\Program Files\Java\jdk1.8.0_171\bin\java.exe" -Dmaven.multiModuleProjectDirectory=D:\project\RuoYi\ruoyi-system -Dmaven.home=D:\Software\apache-maven\apache-maven\apache-maven-3.6.1 -Dclassworlds.conf=D:\Software\apache-maven\apache-maven\apache-maven-3.6.1\bin\m2.conf "-Dmaven.ext.class.path=D:\Program Files\JetBrains\ideaIU-2021.1.3.win\plugins\maven\lib\maven-event-listener.jar" "-javaagent:D:\Program Files\JetBrains\ideaIU-2021.1.3.win\lib\idea_rt.jar=63782:D:\Program Files\JetBrains\ideaIU-2021.1.3.win\bin" -Dfile.encoding=UTF-8 -classpath D:\Software\apache-maven\apache-maven\apache-maven-3.6.1\boot\plexus-classworlds-2.6.0.jar org.codehaus.classworlds.Launcher -Didea.version=2021.1.3 -s D:\maven_repository\ruoyi_settings.xml install -e

其实就是手动执行第一行,后面加参数 -e 可打印错误信息,没想到这就成功了。。看来maven插件这东西不靠谱多半有问题,还是手动执行实在。