我遇到一个问题,当且仅当定义了父 pom 时,maven 才无法正确地将属性替换到我的存储库 URL 中。这尤其是一个问题,因为父 pom 位于远程存储库中,所以我需要定义父 pom。
最小可重现示例:
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.group</groupId>
<artifactId>parent-artifact</artifactId>
<version>1.0.0</version>
<relativePath/>
</parent>
<groupId>com.group</groupId>
<artifactId>project-artifact</artifactId>
<version>1.0.0-SNAPSHOT</version>
<name>project</name>
<description>test project</description>
<properties>
<nexus.url>https://nexus.myorganization.net</nexus.url>
</properties>
<repositories>
<repository>
<id>nexus-server</id>
<url>${nexus.url}/repository/maven-releases/</url>
</repository>
</repositories>
</project>
Run Code Online (Sandbox Code Playgroud)
使用这个 pom,我得到了错误消息,Cannot access ${nexus.url}/repository/maven-snapshots/...
很明显它没有用实际值替换属性。
如果我删除<parent>
POM 的部分,那么属性替换突然开始正常工作:
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.group</groupId>
<artifactId>project-artifact</artifactId>
<version>1.0.0-SNAPSHOT</version>
<name>project</name>
<description>test project</description>
<properties>
<nexus.url>https://nexus.myorganization.net</nexus.url>
</properties>
<repositories>
<repository>
<id>nexus-server</id>
<url>${nexus.url}/repository/maven-releases/</url>
</repository>
</repositories>
<!-- adding this dependency so that Maven is forced to download from the repository -->
<dependencies>
<!-- some dependency here -->
</dependencies>
</project>
Run Code Online (Sandbox Code Playgroud)
我知道它工作正常,因为我可以在 Maven 的输出中看到该行Downloading from nexus-server: https://nexus.myorganization.net/repository/maven-releases/...
有任何想法吗?
归档时间: |
|
查看次数: |
2520 次 |
最近记录: |