【发布时间】:2011-01-11 16:12:48
【问题描述】:
我目前正在为 Maven 苦苦挣扎:我有一个由多个嵌套模块组成的复杂项目,对于其中一些模块,我在 POM 中有类似的配置。
我想让它干净。其实我想定义一个“runnable-jar”通用配置,并在一些模块中激活它。
这是我想在几个项目之间分享的 POM 片段:
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<!-- Use a custom descriptor, with suffix "bin" -->
<descriptors>
<descriptor>src/main/assembly/runnable-jar-assembly.xml</descriptor>
</descriptors>
<!-- Add main class to manifest -->
<archive>
<manifest>
<mainClass>${mainClass}</mainClass>
</manifest>
</archive>
</configuration>
<!-- Add build of this package to lifecycle -->
<executions>
<execution>
<id>make-runnable-jar</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
在某些 POMS 中,我希望能够执行以下操作:
<!-- Set the main class -->
<properties>
<mainClass>my.main.Class</mainClass>
</properties>
<!-- Activate runnable jar build -->
<import>src/main/pom/runnable-jar-pom.xml</import>
我已经寻找了一种将一些 XML 片段导入 POM 或定义整个 XML 节点集宏的方法。
对于我所发现的,最接近的解决方案是在父 POM 中定义一个配置文件,并通过测试文件的存在来在某些子模块中激活它。 See this related question。但我面临{basedir} 属性未正确设置继承/设置的问题。
我发现需要一个 hack 来做一些如此基本的事情(=通常)是非常令人惊讶的。在 Maven 中你通常如何处理这个问题?
【问题讨论】: