假设我有一个模块A:jar,其依赖项的运行时和编译集取决于JDK版本.在我的示例中,我有一个pre-jdk6-profilefor JAXB API:在JDK 1.6.0之前,我需要包含jaxb-api-nnn.jar作为编译依赖项.此个人资料被放置A.pom.
我也有模块B:war,这取决于A:jar.我希望能够在构建服务器上激活此配置文件以构建JDK 1.5.x可交付项.当我在激活给定配置文件的情况下执行Maven时,我收到消息:
mvn -Ppre-jdk6-profile -o install
[WARNING]
Profile with id: 'pre-jdk6-profile' has not been activated.
Run Code Online (Sandbox Code Playgroud)
并且jaxb-api-nnn.jar在结果中缺失B.war.但是,如果我在从父级构建时激活此配置文件pom.xml,则一切正常.这意味着配置文件不是从依赖项继承的,并且父多模块pom.xml能够正确构建所有内容,因为它似乎所有配置文件都在reactor中合并.
将配置文件转换为父pom会使事情变得更糟,因为依赖关系应用于所有其他项目(例如C:ear).对于此任务是否有很好的解决方案,即,如果任何模块A依赖于模块B,那么由配置文件激活的所有编译和运行时依赖关系是否都能正确处理?
项目简介A:jar如下:
<project ...>
<artifactId>A</artifactId>
<packaging>jar</packaging>
...
<parent>
<artifactId>P</artifactId>
...
</parent>
<profiles>
<profile>
<id>pre-jdk6-profile</id>
<activation>
<jdk>(,1.6.0)</jdk>
</activation>
<dependencies>
<dependency>
<groupId>javax.xml.ws</groupId>
<artifactId>jaxws-api</artifactId>
</dependency>
</dependencies>
</profile>
</profiles>
...
</project>
Run Code Online (Sandbox Code Playgroud)
Sea*_*oyd 12
a)在多模块构建中,您应始终从顶部pom构建,而不是从单个模块构建.如果您只想构建一个模块,请使用高级reactor选项(请参阅mvn --help),如下所示:
mvn -pl mymodule
Run Code Online (Sandbox Code Playgroud)
b)定义并激活父pom中的配置文件,但在子pom中添加配置.
父pom.xml
<profiles>
<profile>
<id>pre-jdk-6</id>
<activation>
<jdk>(,1.6.0)</jdk>
</activation>
</profile>
</profiles>
Run Code Online (Sandbox Code Playgroud)
孩子pom.xml
<profiles>
<profile>
<id>pre-jdk-6</id>
<dependencies>
<dependency>
<groupId>javax.xml.ws</groupId>
<artifactId>jaxws-api</artifactId>
</dependency>
</dependencies>
</profile>
</profiles>
Run Code Online (Sandbox Code Playgroud)
事后的几个注意事项:
-P profName,它会激活一个名为“profName”的配置文件<activation>标签的配置文件。它们是由 java 版本激活(如示例中所示),还是默认情况下或 env 值或任何其他内容都没有关系。解决方案:要么使用<activation><jdk>...</jdk></activation>要么使用-P但不要同时使用。
| 归档时间: |
|
| 查看次数: |
15045 次 |
| 最近记录: |