解决 Maven 报错 Non-resolvable parent POM ... was cached in the local repository, resolution will not be
解決 Maven 報錯 Non-resolvable parent POM ... was cached in the local repository, resolution will not be reattempted until the update interval of central has elapsed or updates are forced and 'parent.relativePath' points at wrong local POM
??筆者使用 IntelliJ IDEA 對以前的項目作重構時,發現一個匪夷所思的問題:明明使用 IntelliJ IDEA 運行項目時,項目正常運行,但使用 Maven 命令進行 clean、compile、install 時,對項目中的每一個模塊,均發生如下的報錯。
筆者報錯時的運行環境:
JDK 13.0.2
Maven 3.6.3
IntelliJ IDEA 2020.1.2 (Ultimate Edition)
??這個報錯的信息如下:
"C:\Program Files\Java\jdk-13.0.2\bin\java.exe" -Dmaven.multiModuleProjectDirectory=XXX -Xms128m -Xmx512m "-Dmaven.home=XXX\plugins\maven\lib\maven3" "-Dclassworlds.conf=XXX\plugins\maven\lib\maven3\bin\m2.conf" "-Dmaven.ext.class.path=XXX\plugins\maven\lib\maven-event-listener.jar" "-javaagent:XXX\lib\idea_rt.jar=25353:XXX\bin" -Dfile.encoding=UTF-8 -classpath "XXX\plugins\maven\lib\maven3\boot\plexus-classworlds-2.6.0.jar;XXX\plugins\maven\lib\maven3\boot\plexus-classworlds.license" org.codehaus.classworlds.Launcher -Didea.versionXXXorg.apache.maven.plugins:maven-clean-plugin:2.5:clean [INFO] Scanning for projects... [ERROR] [ERROR] Some problems were encountered while processing the POMs: [WARNING] 'artifactId' contains an expression but should be a constant. @ line 17, column 17 [WARNING] 'dependencies.dependency.(groupId:artifactId:type:classifier)' must be unique: org.junit.jupiter:junit-jupiter:jar -> duplicate declaration of version (?) @ line 35, column 21 [WARNING] 'artifactId' contains an expression but should be a constant. @ XXX:${project_artifactId}:${project_version}, XXX\pom.xml, line 13, column 17 [WARNING] 'version' contains an expression but should be a constant. @ XXX:${project_artifactId}:${project_version}, XXX\pom.xml, line 14, column 14 [WARNING] 'parent.relativePath' of POM XXX:${project_artifactId}:XXX (XXX\XXX\pom.xml) points at XXX:${project_artifactId} instead of XXX:XXX-project, please verify your project structure @ line 9, column 13 [FATAL] Non-resolvable parent POM for XXX:${project_artifactId}:XXX: Failure to find XXX:XXX-project:pom:XXX 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 and 'parent.relativePath' points at wrong local POM @ line 9, column 13 [WARNING] 'artifactId' contains an expression but should be a constant. @ line 17, column 17 [WARNING] 'dependencies.dependency.(groupId:artifactId:type:classifier)' must be unique: org.junit.jupiter:junit-jupiter:jar -> duplicate declaration of version (?) @ line 29, column 21 [WARNING] 'artifactId' contains an expression but should be a constant. @ XXX:${project_artifactId}:${project_version}, XXX\pom.xml, line 13, column 17 [WARNING] 'version' contains an expression but should be a constant. @ XXX:${project_artifactId}:${project_version}, XXX\pom.xml, line 14, column 14 [WARNING] 'parent.relativePath' of POM XXX:${project_artifactId}:XXX (XXX\XXX-exception\pom.xml) points at XXX:${project_artifactId} instead of XXX:XXX-project, please verify your project structure @ line 9, column 13 [FATAL] Non-resolvable parent POM for XXX:${project_artifactId}:XXX: Failure to find XXX:XXX-project:pom:XXX 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 and 'parent.relativePath' points at wrong local POM @ line 9, column 13 [WARNING] 'artifactId' contains an expression but should be a constant. @ XXX:${project_artifactId}:${project_version}, XXX\pom.xml, line 13, column 17 [WARNING] 'version' contains an expression but should be a constant. @ XXX:${project_artifactId}:${project_version}, XXX\pom.xml, line 14, column 14@ [ERROR] The build could not read 2 projects -> [Help 1] [ERROR] [ERROR] The project XXX:${project_artifactId}:XXX (XXX\XXX\pom.xml) has 1 error [ERROR] Non-resolvable parent POM for XXX:${project_artifactId}:XXX: Failure to find XXX:XXX-project:pom:XXX 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 and 'parent.relativePath' points at wrong local POM @ line 9, column 13 -> [Help 2] [ERROR] [ERROR] The project XXX:${project_artifactId}:XXX (XXX\XXX-exception\pom.xml) has 1 error [ERROR] Non-resolvable parent POM for XXX:${project_artifactId}:XXX: Failure to find XXX:XXX-project:pom:XXX 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 and 'parent.relativePath' points at wrong local POM @ line 9, column 13 -> [Help 2] [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/ProjectBuildingException [ERROR] [Help 2] http://cwiki.apache.org/confluence/display/MAVEN/UnresolvableModelException??在筆者不斷地新建工程,不斷地隔離模塊的努力下,終于發現了原因所在。(當然,每個遇到這個問題的讀者可能原因不同,這里僅供參考。)
??為了偷懶,筆者編寫了一個愚蠢的代碼。這段代碼類似如下:
<properties><project_artifactId>demo-project</project_artifactId><project_version>1.2</project_version></properties><groupId>org.demo</groupId><artifactId>${project_artifactId}</artifactId><version>${project_version}</version><packaging>pom</packaging><name>{project_artifactId}</name>??上述代碼的問題在于,對 Maven 項目的坐標使用了 <properties/...> 中的元素來代替。但實際上,<properties/...> 應該在依賴(<dependencies/...>)中使用。Maven 并未在坐標中識別出 <properties/...>,因為坐標解析發生在解析 <properties/...> 之前。同樣地,對于子 pom,雖然父 pom 中的 <properties/...> 可以被子 pom 繼承,不過在子 pom 中的 <parent/...> 坐標里同樣不能解析父 pom 中的 <properties/...>,因為必須要先明確地指定它的父 pom 坐標,然后繼承才會發生。終于知道真相的筆者眼淚掉下來。希望讀者引以為戒。
總結
以上是生活随笔為你收集整理的解决 Maven 报错 Non-resolvable parent POM ... was cached in the local repository, resolution will not be的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 在 Java 中,为什么需要创建内部类对
- 下一篇: 在 IntelliJ IDEA 中误添加