我有这样的父maven pom.xml:
<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>mygroup</groupId>
<artifactId>mygroup-sharing</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>
<profiles>
<profile>
<id>linux-i386</id>
<activation>
<os>
<family>linux</family>
<arch>x86</arch>
</os>
<property>
<name>platform.suffix</name>
<value>linux-i386</value>
</property>
</activation>
</profile>
<profile>
<id>solaris-i386</id>
<activation>
<os>
<family>solaris</family>
<arch>x86</arch>
</os>
<property>
<name>platform.suffix</name>
<value>solaris-i386</value>
</property>
</activation>
</profile>
...
</profiles>
<properties>
<depr.version>3.6.1-${platform.suffix}</depr.version>
</properties>
</project>
我在子目录中有孩子(我会有更多)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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>mygroup-submodule</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<parent>
<groupId>mygroup</groupId>
<artifactId>mygroup-sharing</artifactId>
<version>1.0-SNAPSHOT</version>
<relativePath>../</relativePath>
</parent>
...
<dependencies>
...
<dependency>
<groupId>mygroup</groupId>
<artifactId>depr</artifactId>
<version>${depr.version}</version>
</dependency>
...
</dependencies>
</project>
问题是,在尝试编译子项目时,该版本使用得很糟糕:
Downloading: http://myserver/nexus/content/groups/public//mygroup/depr/3.6.1-${platform.suffix}/depr-3.6.1-${platform.suffix}.pom
...
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD ERROR
[INFO] ------------------------------------------------------------------------
[INFO] Failed to resolve artifact.
Missing:
----------
1) mygroup:depr:jar:3.6.1-${platform.suffix}
Try downloading the file manually from the project website.
Then, install it using the command:
mvn install:install-file -DgroupId=mygroup -DartifactId=depr -Dversion=3.6.1-${platform.suffix} -Dpackaging=jar -Dfile=/path/to/file
Alternatively, if you host your own repository you can deploy the file there:
mvn deploy:deploy-file -DgroupId=mygroup -DartifactId=depr -Dversion=3.6.1-${platform.suffix} -Dpackaging=jar -Dfile=/path/to/file -Durl=[url] -DrepositoryId=[id]
Path to dependency:
1) mygroup:mygroup-submodule:jar:1.0-SNAPSHOT
2) mygroup:depr:jar:3.6.1-${platform.suffix}
----------
....
...正如您所看到的,使用父pom时,属性platform.suffix被严重应用。
运行mvn -X install
时也会出现警告
[警告]覆盖配置文件:'linux-i386'(来源:pom),来自source:pom的新实例
但是在子pom文件中没有配置文件的定义。
如果我在每个pom.xml文件中使用它,它可以正常工作。但是我不想复制粘贴pom.xml这么长的部分,因为它也可以扩展(使用更多平台)。
有没有其他方法可以跨其他模块共享此类型(平台后缀)配置?