在多模块项目中,我想重新使用父pom中的项目名称作为每个模块的项目名称的一部分。我设法找到的唯一信息是在/ project /(groupId | artifactId | version)中不允许属性替换,这表明它在/ project / name中是允许的。
我已尝试在pom中为子模块设置/ project / name为${project.parent.name} - Some Module
,但似乎只选择性地替换此属性:有时使用文字字符串${project.parent.name} - Some Module
,有时候替代工作。
例如,在reactor摘要中,使用了文字字符串:
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO]
[INFO] Glorious Parent .................................... SUCCESS [ 0.016 s]
[INFO] ${project.parent.name} - Some Module ............... SUCCESS [ 2.482 s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
使用<addDefaultSpecificationEntries>
或<addDefaultImplementationEntries>
创建清单文件时,归档程序也是如此。
但是,如果我手动添加清单条目,则会发生替换:
<manifestEntries>
<Project-Name>${project.name}</Project-Name>
</manifestEntries>
Project-Name: Glorious Parent - Some Module
有没有办法知道替换何时或何地发生,或者 - 最好 - 让它始终在任何地方发生?
示例pom.xml :(父)
<?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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>dummy-group-id</groupId>
<artifactId>dummy-parent</artifactId>
<version>1.0</version>
<packaging>pom</packaging>
<name>Glorious Parent</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<modules>
<module>child</module>
</modules>
</project>
示例子/ pom.xml :(模块)
<?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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>dummy-group-id</groupId>
<artifactId>dummy-parent</artifactId>
<version>1.0</version>
</parent>
<artifactId>dummy-test-artifact</artifactId>
<name>${project.parent.name} - Some Module</name>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.6</version>
<configuration>
<archive>
<manifest>
<addDefaultSpecificationEntries>true</addDefaultSpecificationEntries>
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
</manifest>
<manifestEntries>
<Project-Name>${project.name}</Project-Name>
</manifestEntries>
</archive>
</configuration>
</plugin>
</plugins>
</build>
</project>
结果清单:
Manifest-Version: 1.0
Implementation-Title: ${project.parent.name} - Some Module
Project-Name: Glorious Parent - Some Module
Implementation-Version: 1.0
Archiver-Version: Plexus Archiver
Built-By: developer
Specification-Title: ${project.parent.name} - Some Module
Implementation-Vendor-Id: dummy-group-id
Created-By: Apache Maven 3.2.5
Build-Jdk: 1.8.0_31
Specification-Version: 1.0
文件结构:
myproject/
pom.xml
child/
pom.xml
Maven版本: 3.2.5