具有与配置文件相关的子模块的Maven发布插件

时间:2010-10-21 13:34:39

标签: maven-2 maven-release-plugin

我正在尝试使用多模块maven项目执行发布。我的目标是修改所有pom的版本,并在SCM中创建一个标签,这就是我使用maven发布插件的原因。

此项目的层次结构我简化为:

example/
    module1/
    module2/
        module-jni-linux/
        module-jni-macosx/

example的pom.xml包含如下模块:

<modules>
  <module>module1</module>
  <module>module2</module>
</modules>

module2的pom.xml包含依赖于操作系统类型确定的配置文件的模块:

<profiles>
<!-- profile for linux -->
<profile>
  <id>linux</id>
  <activation>
    <os>
      <name>linux</name>
    </os>
  </activation>
  <modules>
    <module>module-jni-linux</module>
  </modules>
</profile>
<!-- profile for mac os -->    
<profile> 
  <id>macosx</id>
  <activation>
    <os>
      <name>mac os x</name>
    </os>
  </activation>
  <modules> 
    <module>module-jni-macosx</module> 
  </modules> 
</profile> 

最后,每个module-jni-*使用native-maven-plugin编译一些C / C ++源并生成一个共享库。


问题:

当我在Mac OS X框中尝试mvn release:prepare -DdryRun=true时,我意识到发布过程不会考虑module-jni-linux。这意味着虽然所有模块都传递到1.0.0 / 1.0.1-SNAPSHOT版本,但module-jni-linux未被修改。在执行release:prepare时我想要的是,即使其配置文件尚未激活,所有子模块也会更新。

我尝试使用mvn -P linux,macosx ...激活这两个配置文件,但module-jni-linux不会在mac下构建(反之亦然)。

如何执行更新两个子模块版本的版本?

2 个答案:

答案 0 :(得分:1)

好的,我找到了办法:

为了创建版本,maven-release-plugin在提交到SCM之前运行cleanverify目标。 verify目标尝试编译每个模块。

我现在所做的是配置插件,使其仅运行verify目标。但由于verify无论如何都很重要,我在不同环境下进行发布之前手动运行它。我的发布程序如下:

  1. 在Mac和Linux环境中运行mvn clean verify。为此,我配置了一个多节点哈德森作业。
  2. 运行mvn release:prepare -P macosx,linux -DdryRun=true -DpreparationGoals=clean,这会激活两个配置文件,但会跳过编译
  3. 检查干运行结果是否令人满意
  4. 使用-DdryRun=false
  5. 执行第2步

答案 1 :(得分:0)

对于父pom.xml中的Maven版本插件配置,您是否尝试使用<arguments>参数指定要启用的配置文件?

您可以在此处详细了解:http://maven.apache.org/plugins/maven-release-plugin/prepare-mojo.html

基本上,它允许您将其他参数传递给Maven调用,包括配置文件,例如-P linux,macosx。

相关问题