有没有一种简单的方法来查找多模块 Maven 项目的根目录,类似于 Gradle 的 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
,这样最终就会得到:
And i want all the artifacts to be copied from the target-directories of their respective modules to my-project/../to-deploy
so i end up with
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>
但是,当我试图在模块POM中使用${myproject.root}
时,${basedir}
会解析为该模块的基础目录。
此外,我在http://labs.consol.de/lang/de/blog/maven/project-root-path-in-a-maven-multi-module-project/发现一篇文章,其中建议每个开发者和持续集成服务器都应该在profiles.xml文件中配置根目录,但我不认为这是一个解决方案。
那么有没有一种简单的方法来找到多模块项目的根目录呢?