我在 Maven 构建中得到“构建无法读取 1 个项目”,因为未定义的版本

新手上路,请多包涵

我有一个父 pom 和一个集成 pom:

集成pom

 <dependencies>
    <dependency>
        <groupId>org.json</groupId>
        <artifactId>json</artifactId>
    </dependency>

    <dependency>
        <groupId>commons-httpclient</groupId>
        <artifactId>commons-httpclient</artifactId>
    </dependency>

    <dependency>
        <groupId>com.example</groupId>
        <artifactId>example-model</artifactId>
    </dependency>

</dependencies>
<parent>
    <groupId>com.example</groupId>
    <artifactId>example-parent</artifactId>
    <version>0.0.1-SNAPSHOT</version>
</parent>

父母pom

 <modules>
    <module>../example-business</module>
    <module>../example-integration</module>
    <module>../example-model</module>
</modules>
<dependencyManagement>
    <dependencies>

        <dependency>
            <groupId>org.json</groupId>
            <artifactId>json</artifactId>
            <version>20131018</version>
        </dependency>

        <dependency>
            <groupId>commons-httpclient</groupId>
            <artifactId>commons-httpclient</artifactId>
            <version>3.1</version>
        </dependency>

        <dependency>
            <groupId>com.example</groupId>
            <artifactId>example-model</artifactId>
            <version>${project.version}</version>
        </dependency>

    </dependencies>
</dependencyManagement>

现在,当我在父级上进行全新安装时,出现以下错误:

 [INFO] Scanning for projects...
Downloading: http://www.example.com/content/groups/mirror/com/example/example-parent/0.0.1-SNAPSHOT/maven-metadata.xml
[ERROR] The build could not read 1 project -> [Help 1]
[ERROR]
[ERROR]   The project com.example:example-integration:0.0.1-SNAPSHOT (D:\dev\workspaces\example-git\example\example-integration\pom.xml) has 3 errors
[ERROR]     'dependencies.dependency.version' for org.json:json:jar is missing. @ line 22, column 15
[ERROR]     'dependencies.dependency.version' for commons-httpclient:commons-httpclient:jar is missing. @ line 27, column 15
[ERROR]     'dependencies.dependency.version' for com.example:example-model:jar is missing. @ line 32, column 15

但是当我查看集成pom的Effective POM时,有写的版本。

那么为什么我不能构建它呢?


编辑:

这是 EFFECTIVE POM 视图的片段:

 <dependencyManagement>
    <dependencies>
      <dependency>
        <groupId>org.json</groupId>
        <artifactId>json</artifactId>
        <version>20131018</version>
      </dependency>
      <dependency>
        <groupId>commons-httpclient</groupId>
        <artifactId>commons-httpclient</artifactId>
        <version>3.1</version>
      </dependency>
      <dependency>
        <groupId>com.example</groupId>
        <artifactId>example-model</artifactId>
        <version>0.0.1-SNAPSHOT</version>
      </dependency>
      <dependency>
        <groupId>com.example</groupId>
        <artifactId>example-integration</artifactId>
        <version>0.0.1-SNAPSHOT</version>
      </dependency>
      <dependency>
        <groupId>com.example</groupId>
        <artifactId>example-business</artifactId>
        <version>0.0.1-SNAPSHOT</version>
      </dependency>
    </dependencies>
  </dependencyManagement>
  <dependencies>
    <dependency>
      <groupId>org.json</groupId>
      <artifactId>json</artifactId>
      <version>20131018</version>
      <scope>compile</scope>
    </dependency>
    <dependency>
      <groupId>commons-httpclient</groupId>
      <artifactId>commons-httpclient</artifactId>
      <version>3.1</version>
      <scope>compile</scope>
    </dependency>
    <dependency>
      <groupId>com.example</groupId>
      <artifactId>example-model</artifactId>
      <version>0.0.1-SNAPSHOT</version>
      <scope>compile</scope>
    </dependency>
    <dependency>
      <groupId>com.example</groupId>
      <artifactId>example-business</artifactId>
      <version>0.0.1-SNAPSHOT</version>
      <scope>compile</scope>
    </dependency>
  </dependencies>

原文由 user2979186 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 768
2 个回答

问题在于您的项目结构以及您如何在子 pom 中定义 parent

您的子模块实际上位于比您的父 pom 所在的文件夹高一级的文件夹中,而不是在同一级别(从 <module>../example-business</module> 判断)。当 Maven 尝试构建子模块时,它找不到父 pom,因为它在 Maven 存储库中不可用(它当前正在构建它,因此尚未上传)。

要解决此问题,您只需更改子 pom 中的 parent 定义以将真实的 relativePath 更改为父 pom 的位置,以便 Maven 可以找到它。因此,将其更改为如下所示:

 <parent>
    <groupId>com.example</groupId>
    <artifactId>example-parent</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <relativePath>../name-of-folder-containing-parent-pom</relativePath>
</parent>

显然,您需要将 name-of-folder-containing-parent-pom 更改为任何文件夹。

原文由 DB5 发布,翻译遵循 CC BY-SA 3.0 许可协议

我遇到了同样的问题,请检查文件资源管理器中的实际文件夹名称,它应该与你在 pom.xml 中定义为模块的名称匹配。 eclipse 显示的项目名称可能与资源管理器中的实际项目名称不同。

原文由 U_R_Naveen UR_Naveen 发布,翻译遵循 CC BY-SA 4.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题