有没有一种简单的方法可以找到像 Gradle 一样的多模块 Maven 项目的根rootDir
?
背景:
我想使用 maven-dependency-plugin 将我的多模块项目的所有子模块中的工件复制到与整个项目的根目录相关的目录中。
也就是说,我的布局看起来与此类似,名称已更改:
to-deploy/
my-project/
module-a/
module-b/
more-modules-1/
module-c/
module-d/
more-modules-2/
module-e/
module-f/
...
而且我希望从各自模块的目标目录中复制所有工件,my-project/../to-deploy
以便最终得到
to-deploy/
module-a.jar
module-b.jar
module-c.jar
module-d.jar
module-e.jar
module-f.jar
my-project/
...
我可以在每个模块中使用相对路径来做到这一点,如下所示:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy</id>
<phase>install</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>${project.groupId}</groupId>
<artifactId>${project.artifactId}</artifactId>
<version>${project.version}</version>
<type>jar</type>
<outputDirectory>../../to-deploy</outputDirectory>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
但我宁愿不在<outputDirectory>
元素中指定相对路径。我更喜欢类似的东西${reactor.root.directory}/../to-deploy
,但我找不到这样的东西。
另外,如果有某种方法可以继承此 maven-dependency-plugin 配置,我更愿意,这样我就不必为每个模块指定它。
我还尝试从根 pom 继承自定义属性:
<properties>
<myproject.root>${basedir}</myproject.root>
</properties>
但是当我尝试${myproject.root}
在模块 POM 中使用时,${basedir}
会解析为模块的 basedir。
另外,我发现http://labs.consol.de/lang/de/blog/maven/project-root-path-in-a-maven-multi-module-project/建议每个开发人员并且可能是连续的集成服务器应该在profiles.xml 文件中配置根目录,但我不认为这是一个解决方案。
那么有没有一种简单的方法可以找到多模块项目的根?