我们正在优化Maven配置(从以前使用ant开始),我刚刚阅读了
Maven by Example
从Sonatype预订。重复配置在过去给我们带来了麻烦,所以我绝对想避免哪怕是最微小的一点。
上面的书提到在将其他同级子模块作为依赖项引用时使用父模块中的内置project.groupId和project.version属性:
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>model</artifactId>
<version>${project.version}</version>
</dependency>
很好,我喜欢。但这在pom.xml子模块的标记中不起作用:
<parent>
<groupId>${project.groupId}</groupId>
<artifactId>${project.artifactId}</artifactId>
<version>${project.version}</version>
<relativePath>../pom.xml</relativePath>
</parent>
我想没什么大不了的,似乎我可以为这些创建属性,但是对于许多模块,我真的很想完全理解这些问题的最佳实践。。
更新
到目前为止,最好的办法是这样做。有点难看,但消除了重复的硬编码值。
<groupId>${groupId}</groupId>
<artifactId>${artifactId}</artifactId>
<packaging>pom</packaging>
<version>${version}</version>
<properties>
<groupId>com.mycompany</groupId>
<artifactId>mycompany</artifactId>
<version>1.0</version>
</properties>
子pom.xml:
<parent>
<groupId>${groupId}</groupId>
<artifactId>${artifactId}</artifactId>
<version>${version}</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>child</artifactId>