java - 我在 Maven 构建中得到 "The build could not read 1 project"因为未定义的版本

标签 java maven pom.xml

我有一个父 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 View 的片段:

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

最佳答案

问题在于您的项目结构以及您如何定义 parent在 child POMS 中。

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

要解决此问题,您只需更改 parent在子 poms 中定义一个真正的 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无论文件夹是什么。

关于java - 我在 Maven 构建中得到 "The build could not read 1 project"因为未定义的版本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20424245/

相关文章:

java - maven pom : difference between application. main.class 和 exec.main.class

java hibernate Eclipse xml

java - 如何修复致命异常 : java. lang.IndexOutOfBoundsException 索引 : 0, 大小:1

java - 使用 Hibernate 归档数据的最佳方法

java - Heroku 编译 fatal error : invalid target release: 11

scala - sbt-仅在发布期间排除某些依赖项

java - 用于匹配不同浮点格式的正则表达式

java.lang.NoClassDefFoundError : org/hibernate/service/ServiceRegistry after building by Maven

maven - 我可以使用通配符从 Maven 依赖项插件的解包依赖项目标中包含/排除 groupID 吗?

java - Jboss 作为 maven 插件部署多模块 Maven 项目