我有以下结构和以下依赖关系:child1->child2。
以及两者的父级,使用
${project.version}
来合并依赖管理中的所有版本。
文件夹结构:
+ parent
+ child1
+ child2
请参阅下面的 poms + 完整示例此处。
当 child2 的版本设置为 1.0-SNAPSHOT 时,一切正常。
尝试将 just child2 的版本更改为 2.0-SNAPSHOT 时,出现以下错误:
Failure to find ...:child1:jar:2.0-SNAPSHOT
为什么 Maven 试图查找版本 child1 2.0 而不是 1.0?
家长:
<?xml version="1.0" encoding="UTF-8"?>
<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>info.fastpace.issue.unknowversion</groupId>
<artifactId>parent</artifactId>
<packaging>pom</packaging>
<version>1.0-SNAPSHOT</version>
<modules>
<module>child1</module>
<module>child2</module>
</modules>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>info.fastpace.issue.unknowversion</groupId>
<artifactId>child1</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>info.fastpace.issue.unknowversion</groupId>
<artifactId>child2</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</dependencyManagement>
</project>
孩子1:
<?xml version="1.0" encoding="UTF-8"?>
<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>
<artifactId>child1</artifactId>
<parent>
<groupId>info.fastpace.issue.unknowversion</groupId>
<artifactId>parent</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
</project>
孩子2:
<?xml version="1.0" encoding="UTF-8"?>
<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>
<artifactId>child2</artifactId>
<version>2.0-SNAPSHOT</version>
<parent>
<groupId>info.fastpace.issue.unknowversion</groupId>
<artifactId>parent</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<dependencies>
<dependency>
<groupId>info.fastpace.issue.unknowversion</groupId>
<artifactId>child1</artifactId>
</dependency>
</dependencies>
</project>
似乎用硬编码的
${project.version}
替换父pom中的1.0-SNAPSHOT
解决了这个问题。
不知道为什么更改为硬编码值有效,但至少现在有效。
parent.version
取决于当前项目,并且在生成工件时不会自动替换,除非您使用类似 flatten-maven-plugin
的内容。这意味着在任何其他项目中使用这些工件作为依赖项将不起作用。这也意味着,如果 child2
被视为当前项目(例如更改到该子目录并从那里构建),则 it 指示 parent.version
是什么并影响 child1
的托管依赖项;这似乎是您看到的错误。
父项目不能全部是反应器(指定
<modules>
的根 POM)、父项目(被另一个 <parent>
引用的 POM)、和 项目 BOM(列出项目中其他模块的 POM) <dependencyManagement>
)如果您想拥有单独的版本,请同时进行。您需要两个甚至三个模块来代替一个,并且您不能使用 parent.version
。