在多个生命周期中运行Maven目标

11
我有一个情况,我想在verify阶段和reporting阶段都运行cobertura插件。我有两个profiles,它们都应该运行cobertura插件,但是在A profile中,我只想创建xml/html输出,而在B profile中,我会生成包含这些结果的完整站点文档。
我已经将cobertura配置为作为verify阶段的插件运行,但是如果我这样做,即使我运行mvn verify site,cobertura报告也不会出现在站点文档中。看起来我需要在插件和报告部分都列出它(因为如果我只在插件中列出它,在A profile中不会运行site,所以不会调用它)。到目前为止,我的POM的插件部分包括:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>cobertura-maven-plugin </artifactId>
<version>2.2</version>
<configuration>
    <instrumentation>
        <excludes>
            <exclude>com/somepkg/**</exclude>
        </excludes>
    </instrumentation>
    <formats>
        <format>xml</format>
        <format>html</format>
    </formats>
</configuration>        
<executions>
    <execution>
        <phase>verify</phase>
        <goals>
            <goal>cobertura</goal>
        </goals>
    </execution>
</executions>
</plugin>

我不想在报告部分中复制这个内容,因为这样会重复很多。有没有其他好的方法可以实现呢?

谢谢,

Jeff

1个回答

11

请定义此内容:

<executions>
        <execution>
                <phase>verify</phase>
                <goals>
                        <goal>cobertura</goal>
                </goals>
        </execution>
        <execution>
                <phase>pre-site</phase>
                <goals>
                        <goal>cobertura</goal>
                </goals>
        </execution>
</executions>

仔细看,Maven 是否有一个名为 reporting 的阶段?http://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html#Lifecycle_Reference。它似乎没有按照我预期的那样工作... - Jeff Storey
据我所知,报告正在站点生成中发生。 - David Rabinowitz
我发现如果我只是将插件放在报告部分和其他的构建中,然后从命令行运行目标,会得到最好的效果。唯一的问题是,我似乎无法在从命令行执行时指定要使用的版本。我希望它能从报告插件中获取,但它没有。有什么解决方法吗? - Jeff Storey
FYI - 我已经创建了属性来管理版本。我仍然需要在两个地方(插件和报告)列出插件,但配置会自动从报告部分获取,但版本不会。因此,我在两个地方列出了插件的groupId,artifactId和version(而版本是一个属性)。 - Jeff Storey

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接