尝试使用 $parent.groupid 从子 pom 引用父 pom 时出现“不可解析的父 POM:无法传输工件”

Posted

技术标签:

【中文标题】尝试使用 $parent.groupid 从子 pom 引用父 pom 时出现“不可解析的父 POM:无法传输工件”【英文标题】:"Non-resolvable parent POM: Could not transfer artifact" when trying to refer to a parent pom from a child pom with $parent.groupid尝试使用 $parent.groupid 从子 pom 引用父 pom 时出现“不可解析的父 POM:无法传输工件” 【发布时间】:2012-11-10 02:55:01 【问题描述】:

我正在关注 maven 的教程。我有一个非常简单的项目,里面有几个模块。在模块 pom 上,我想通过 $parent.groupid 和 $parent.version 引用主项目 pom 版本和组,所以如果我更改其中任何一个,我就不必在子 pom 中搜索和更改它们,但我得到不可解析的父 POM:无法传输工件错误

我在 *** 上阅读了几个“不可解析的父 POM:”问题,但我阅读的内容没有任何帮助。

我的目录结构如下:

tutorial_maven(dir)
 --> pom.xml(file)
 --> tutorial_maven_jar(dir)
     --> pom.xml(file)

我收到以下错误:

Apache Maven 3.0.4 (r1232337; 2012-01-17 03:44:56-0500)
Maven home: C:\Program Files (x86)\apache-maven-3.0.4
Java version: 1.7.0_09, vendor: Oracle Corporation
Java home: C:\Program Files\Java\jdk1.7.0_09\jre
Default locale: es_EC, platform encoding: UTF-8
OS name: "windows 7", version: "6.1", arch: "amd64", family: "windows"
[INFO] Error stacktraces are turned on.
[DEBUG] Reading global settings from C:\Program Files (x86)\apache-maven-3.0.4\conf\settings.xml
[DEBUG] Reading user settings from C:\Users\fureta.DESARROLLO03\.m2\settings.xml
[WARNING] Command line option -npr is deprecated and will be removed in future Maven versions.
[DEBUG] Using local repository at C:\Users\fureta.DESARROLLO03\.m2\repository
[DEBUG] Using manager EnhancedLocalRepositoryManager with priority 10 for C:\Users\fureta.DESARROLLO03\.m2\repository
[INFO] Scanning for projects...
[DEBUG] Using connector WagonRepositoryConnector with priority 0 for http://repo.maven.apache.org/maven2
Downloading: http://repo.maven.apache.org/maven2/$parent/groupId/tutorial_maven/$parent.version/tutorial_maven-$parent.version.pom
[DEBUG] Writing resolution tracking file C:\Users\fureta.DESARROLLO03\.m2\repository\$parent\groupId\tutorial_maven\$parent.version\tutorial_maven-$parent.version.pom.lastUpdated
[DEBUG] Extension realms for project org.felipe:tutorial_maven:pom:1.0-SNAPSHOT: (none)
[DEBUG] Looking up lifecyle mappings for packaging pom from ClassRealm[plexus.core, parent: null]
[DEBUG] Extension realms for project org.felipe:tutorial_maven_webapp:war:1.0-SNAPSHOT: (none)
[DEBUG] Looking up lifecyle mappings for packaging war from ClassRealm[plexus.core, parent: null]
[ERROR] The build could not read 1 project -> [Help 1]
org.apache.maven.project.ProjectBuildingException: Some problems were encountered while processing the POMs:
[WARNING] 'parent.relativePath' points at org.felipe:tutorial_maven instead of $parent.groupId:tutorial_maven, please verify your project structure @ line 3, column 13
[FATAL] Non-resolvable parent POM: Could not transfer artifact $parent.groupId:tutorial_maven:pom:$parent.version from/to central (http://repo.maven.apache.org/maven2): Illegal character in path at index 37: http://repo.maven.apache.org/maven2/$parent/groupId/tutorial_maven/$parent.version/tutorial_maven-$parent.version.pom and 'parent.relativePath' points at wrong local POM @ line 3, column 13

at org.apache.maven.project.DefaultProjectBuilder.build(DefaultProjectBuilder.java:363)
at org.apache.maven.DefaultMaven.collectProjects(DefaultMaven.java:636)
at org.apache.maven.DefaultMaven.getProjectsForMavenReactor(DefaultMaven.java:585)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:234)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:156)
at org.apache.maven.cli.MavenCli.execute(MavenCli.java:537)
at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:196)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:141)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:290)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:230)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:409)
at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:352)
at org.codehaus.classworlds.Launcher.main(Launcher.java:47)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
[ERROR]   
[ERROR]   The project $parent.groupId:tutorial_maven_jar:$parent.version (C:\Users\fureta.DESARROLLO03\IdeaProjects\tutorial_maven\tutorial_maven_jar\pom.xml) has 1 error
[ERROR]     Non-resolvable parent POM: Could not transfer artifact  $parent.groupId:tutorial_maven:pom:$parent.version from/to central  (http://repo.maven.apache.org/maven2): Illegal character in path at index 37:  http://repo.maven.apache.org/maven2/$parent/groupId/tutorial_maven/$parent.version/tuto rial_maven-$parent.version.pom and 'parent.relativePath' points at wrong local POM @ line  3, column 13 -> [Help 2]
org.apache.maven.model.resolution.UnresolvableModelException: Could not transfer  artifact $parent.groupId:tutorial_maven:pom:$parent.version from/to central  (http://repo.maven.apache.org/maven2): Illegal character in path at index 37:  http://repo.maven.apache.org/maven2/$parent/groupId/tutorial_maven/$parent.version/tuto rial_maven-$parent.version.pom
at  org.apache.maven.project.ProjectModelResolver.resolveModel(ProjectModelResolver.java:159)
at org.apache.maven.model.building.DefaultModelBuilder.readParentExternally(DefaultModelBuilder.java:813)
at org.apache.maven.model.building.DefaultModelBuilder.readParent(DefaultModelBuilder.java:664)
at org.apache.maven.model.building.DefaultModelBuilder.build(DefaultModelBuilder.java:310)
at org.apache.maven.model.building.DefaultModelBuilder.build(DefaultModelBuilder.java:232)
at org.apache.maven.project.DefaultProjectBuilder.build(DefaultProjectBuilder.java:410)
at org.apache.maven.project.DefaultProjectBuilder.build(DefaultProjectBuilder.java:379)
at org.apache.maven.project.DefaultProjectBuilder.build(DefaultProjectBuilder.java:495)
at org.apache.maven.project.DefaultProjectBuilder.build(DefaultProjectBuilder.java:379)
at org.apache.maven.project.DefaultProjectBuilder.build(DefaultProjectBuilder.java:343)
at org.apache.maven.DefaultMaven.collectProjects(DefaultMaven.java:636)
at org.apache.maven.DefaultMaven.getProjectsForMavenReactor(DefaultMaven.java:585)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:234)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:156)
at org.apache.maven.cli.MavenCli.execute(MavenCli.java:537)
at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:196)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:141)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:290)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:230)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:409)
at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:352)
at org.codehaus.classworlds.Launcher.main(Launcher.java:47)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
Caused by: org.sonatype.aether.resolution.ArtifactResolutionException: Could not  transfer artifact $parent.groupId:tutorial_maven:pom:$parent.version from/to central  (http://repo.maven.apache.org/maven2): Illegal character in path at index 37:  http://repo.maven.apache.org/maven2/$parent/groupId/tutorial_maven/$parent.version/tuto rial_maven-$parent.version.pom
at  org.sonatype.aether.impl.internal.DefaultArtifactResolver.resolve(DefaultArtifactResolver.java:538)
at org.sonatype.aether.impl.internal.DefaultArtifactResolver.resolveArtifacts(DefaultArtifactResolver.java:216)
at org.sonatype.aether.impl.internal.DefaultArtifactResolver.resolveArtifact(DefaultArtifactResolver.java:193)
at org.sonatype.aether.impl.internal.DefaultRepositorySystem.resolveArtifact(DefaultRepositorySystem.java:286)
at org.apache.maven.project.ProjectModelResolver.resolveModel(ProjectModelResolver.java:155)
... 30 more
Caused by: org.sonatype.aether.transfer.ArtifactTransferException: Could not transfer artifact $parent.groupId:tutorial_maven:pom:$parent.version from/to central (http://repo.maven.apache.org/maven2): Illegal character in path at index 37: http://repo.maven.apache.org/maven2/$parent/groupId/tutorial_maven/$parent.version/tutorial_maven-$parent.version.pom
at org.sonatype.aether.connector.wagon.WagonRepositoryConnector$4.wrap(WagonRepositoryConnector.java:951)
at org.sonatype.aether.connector.wagon.WagonRepositoryConnector$4.wrap(WagonRepositoryConnector.java:941)
at org.sonatype.aether.connector.wagon.WagonRepositoryConnector$GetTask.run(WagonRepositoryConnector.java:669)
at org.sonatype.aether.util.concurrency.RunnableErrorForwarder$1.run(RunnableErrorForwarder.java:60)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
at java.lang.Thread.run(Thread.java:722)
Caused by: java.lang.IllegalArgumentException: Illegal character in path at index 37: http://repo.maven.apache.org/maven2/$parent/groupId/tutorial_maven/$parent.version/tutorial_maven-$parent.version.pom
at java.net.URI.create(URI.java:859)
at org.apache.maven.wagon.providers.http.httpclient.client.methods.HttpGet.<init>(HttpGet.java:69)
at org.apache.maven.wagon.shared.http4.AbstractHttpClientWagon.fillInputData(AbstractHttpClientWagon.java:778)
at org.apache.maven.wagon.StreamWagon.getInputStream(StreamWagon.java:116)
at org.apache.maven.wagon.StreamWagon.getIfNewer(StreamWagon.java:88)
at org.apache.maven.wagon.StreamWagon.get(StreamWagon.java:61)
at      org.sonatype.aether.connector.wagon.WagonRepositoryConnector$GetTask.run(WagonRepositoryConnector.java:601)
... 4 more
Caused by: java.net.URISyntaxException: Illegal character in path at index 37: http://repo.maven.apache.org/maven2/$parent/groupId/tutorial_maven/$parent.version/tutorial_maven-$parent.version.pom
at java.net.URI$Parser.fail(URI.java:2829)
at java.net.URI$Parser.checkChars(URI.java:3002)
at java.net.URI$Parser.parseHierarchical(URI.java:3086)
at java.net.URI$Parser.parse(URI.java:3034)
at java.net.URI.<init>(URI.java:595)
at java.net.URI.create(URI.java:857)
... 10 more
[ERROR] 
[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

我已阅读帮助 1 和帮助 2 中的链接,但没有发现任何帮助。 从日志中我可以了解到,maven 正在 maven 存储库中寻找我的主要 pom...

我错过了什么?

我的主要 pom.xml

<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>

  <groupId>org.felipe</groupId>
  <artifactId>tutorial_maven</artifactId>
  <version>1.0-SNAPSHOT</version>
    <modules>
        <module>tutorial_maven_jar</module>
        <module>tutorial_maven_webapp</module>
    </modules>
    <packaging>pom</packaging>

  <name>tutorial_maven</name>
  <url>http://maven.apache.org</url>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <!--<log4j.version>1.2.17</log4j.version>-->
  </properties>

  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
  </dependencies>
</project>

我的模块 pom.xml:

<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">
    <parent>
        <artifactId>tutorial_maven</artifactId>
        <groupId>$parent.groupId</groupId>
        <version>$parent.version</version>
        <relativePath>../pom.xml</relativePath>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <artifactId>tutorial_maven_jar</artifactId>
    <packaging>jar</packaging>

    <name>tutorial_maven_jar</name>
    <url>http://maven.apache.org</url>

    <properties>
         <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.3.2</version>
                <configuration>
                    <source>1.7</source>
                    <target>1.7</target>
                </configuration>
            </plugin>
        </plugins>
    </build>

    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>3.8.1</version>
            <scope>test</scope>
            <!--<optional>true</optional>-->
        </dependency>

        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.17</version>
        </dependency>
    </dependencies>
</project>

最好的问候, 费利佩

【问题讨论】:

【参考方案1】:

看起来您正在尝试从父级继承 groupId,并同时使用继承的 groupId 指定父级!

在子 pom 中,使用如下内容:

<modelVersion>4.0.0</modelVersion>

<parent>
  <groupId>org.felipe</groupId>
  <artifactId>tutorial_maven</artifactId>
  <version>1.0-SNAPSHOT</version>
  <relativePath>../pom.xml</relativePath>
</parent>

<artifactId>tutorial_maven_jar</artifactId>

使用$project.groupId 之类的属性将无法使用。如果这样指定parent,那么可以继承child pom中的groupId和version。因此,您只需要在子 pom 中指定 artifactId。

【讨论】:

您好,Martin,我最初就是这样拥有它的,我正在按照教程进行操作,也许我误解了教程。从我所见,如果我更改父 pom 中的版本,那么我必须手动更改子 pom 上的 de 版本? 是的,但是您可以使用版本插件来自动执行此操作,因此您不必手动编辑每一个。如果您从*** pom 运行 mvn versions:set -DnewVersion=x.y.z,那么它将在所有子模块的*** pom 上设置此版本。欲了解更多信息,请参阅:mojo.codehaus.org/versions-maven-plugin/set-mojo.html【参考方案2】:

我假设问题已经得到解答。如果上述解决方案无法解决问题,则可以使用以下解决方案。

如果有时您的 maven 用户设置未反映正确的 settings.xml 文件,则会出现此问题。

要更新设置文件,请转到 Windows > Preferences > Maven > User Settings 并将 settings.xml 更新到正确的位置。

一旦重新构建项目,这些应该可以解决问题。 谢谢。

【讨论】:

好建议。我检查了一下,不幸的是我的 settings.xml 文件的位置是正确的。【参考方案3】:

我遇到了同样的问题。通过在列出 &lt;modules&gt; 的父文件夹中添加 pom.xml 来修复。

【讨论】:

【参考方案4】:

正如 Nayan 所说,路径必须正确更新 在我的情况下,apache-maven 安装在 C:\apache-mavensettings.xmlC:\apache-maven\conf\settings.xml

中找到

如果这不起作用,请转到您的本地仓库 在我的情况下 C:\Users\>.m2\ 并搜索 .lastUpdated 并删除它们 然后构建 ma​​ven

【讨论】:

以上是关于尝试使用 $parent.groupid 从子 pom 引用父 pom 时出现“不可解析的父 POM:无法传输工件”的主要内容,如果未能解决你的问题,请参考以下文章

DevExpress TabbedView : 从子窗体创建子窗体

使用 php 从子目录中获取 azure blob 文件

Mongoose & Express:从子文档发布数据

Mongoose & Express:从子文档发布数据

尝试将数据从子活动返回到 MainActivity 时获取 NullPointerException

从子上下文分配对象时非法尝试建立关系