Java 我在 Maven 构建中收到“构建无法读取 1 个项目”,因为未定义版本
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20424245/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
I get "The build could not read 1 project" in maven build because undefined versions
提问by
I've a parent-pom and a integration-pom:
integration pom
我有一个 parent-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>
parent pom
父 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>
Now when I will do a clean install on the parent, I get the following error:
现在,当我在父级上进行全新安装时,出现以下错误:
[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
But when I take a look to the Effective POM of the integration pom, there are the version written.
So why I can't build it?
但是当我查看集成 pom 的 Effective POM 时,有写的版本。
那为什么我不能建立它?
Edit:
Here is a snip of the EFFECTIVE POMview:
编辑:
这是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>
采纳答案by DB5
The problem is to do with your project structure and how you have defined the parent
in the child poms.
问题与您的项目结构以及您如何parent
在子 poms.xml 中定义有关。
Your child modules are actually in folders that are one level up from where your parent pom resides rather than in the same level (judging from <module>../example-business</module>
). When maven tries to build the child modules it can not find the parent pom as it is not available in the maven repository (it is currently in the process of building it so it has not yet been uploaded).
您的子模块实际上位于父 pom 所在位置的上一级文件夹中,而不是在同一级别(从 判断<module>../example-business</module>
)。当 maven 尝试构建子模块时,它无法找到父 pom,因为它在 maven 存储库中不可用(它目前正在构建过程中,因此尚未上传)。
To fix this you simply need to change the parent
definition in the child poms to define a real relativePath
to the location of the parent pom so that maven can find it. So change it to be something like the following:
要解决此问题,您只需更改parent
子relativePath
pom 中的定义,以定义父 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>
Obviously you'll need to change name-of-folder-containing-parent-pom
to be whatever the folder is.
显然,您需要更改name-of-folder-containing-parent-pom
为任何文件夹。
回答by Vineela Thonupunuri
Check why parent dependency is not getting solved in your local. You might be missing something in settings.xml which resides in c:Users/name/.m2 Check if the credentials are correct and you have added all the artifactory links in case if they are not public.
检查为什么本地的父依赖没有得到解决。您可能在位于 c:Users/name/.m2 的 settings.xml 中遗漏了一些内容,请检查凭据是否正确,并添加了所有人工链接,以防它们不公开。
回答by Mani P
I too had similar issue and is solved by adding missed close tag below
我也有类似的问题,并通过在下面添加错过的关闭标签来解决
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-jexl</artifactId>
<version>2.1.1</version>
<dependency>
Same resolved as below:
同样解决如下:
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-jexl</artifactId>
<version>2.1.1</version>
</dependency>