【问题标题】:Regarding updating pom file关于更新pom文件
【发布时间】:2016-09-28 11:13:47
【问题描述】:

我正在开发一个持续集成工具,在这里我需要在签出后集成 jacoco 插件。我不想强制开发人员在签入时添加 jacoco 插件,而是我想在运行基于 jenkins 的持续集成工具时添加它。 是否有可能实现这些选项中的任何一个?: 1.修改开发者签入的pom文件,注入jacoco需要的依赖和插件?

  1. 添加 jacoco 插件 super pom 并在 jenkins 配置中提及。

我尝试了这种超级 pom 方法,它正在从一个公共存储库中读取超级 pom,但没有生成 jacoco-exec 文件。我在 super pom 下面用过。

http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 呸

<dependencies>
    <dependency>
        <groupId>org.jacoco</groupId>
        <artifactId>jacoco-maven-plugin</artifactId>
        <version>0.7.6.201602180812</version>
    </dependency>

</dependencies>
<build>
    <plugins>
        <plugin>
            <groupId>org.jacoco</groupId>
            <artifactId>jacoco-maven-plugin</artifactId>
            <version>0.7.6.201602180812</version>
            <configuration>
                <destFile>${basedir}/target/jacoco-unit.exec</destFile>
                <dataFile>${basedir}/target/jacoco-unit.exec</dataFile>
            </configuration>
            <executions>
                <execution>
                    <goals>
                        <goal>prepare-agent</goal>
                    </goals>
                </execution>
                <execution>
                    <id>report</id>
                    <phase>prepare-package</phase>
                    <goals>
                        <goal>report</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

任何帮助将不胜感激。谢谢

【问题讨论】:

    标签: maven pom.xml jacoco


    【解决方案1】:

    您可以在 pom.xml 中创建一个单独的配置文件,将其命名为 jenkins 配置文件并在该配置文件中包含 jacoco 插件。然后,您可以在 jenkins 作业中配置 mvn 命令以包含 -P jenkins_profile_name。所以构建将使用 jenkins 配置文件完成。

    将现有配置文件标记为默认配置,开发人员无需执行任何特定操作。

    有关更多详细信息,请参阅构建配置文件的 maven 文档:

    http://maven.apache.org/guides/introduction/introduction-to-profiles.html

    【讨论】:

    • 感谢 ritesh 的回复,我还有一个问题,在这种情况下,它将单独执行 jenkins_profile_name 还是在 jenkins_profile_name 之后执行项目 pom。我问的原因是,jenkins_profile_name 只会说 jacoco 插件和依赖项,而其他项目 pom 将具有所有其他依赖项。 -P 或 -F 只会执行不是吗?赞赏..
    • 这取决于你如何配置你的 pom.xml 文件。如果是这样:&lt;profiles&gt; &lt;profile&gt; &lt;id&gt;jenkins&lt;/id&gt; &lt;activation&gt; &lt;activeByDefault&gt;false&lt;/activeByDefault&gt; &lt;/activation&gt; &lt;build&gt; &lt;plugins&gt; . . &lt;!-- Jacoco plugin --&gt; &lt;/plugins&gt; &lt;/build&gt; &lt;/profile&gt; &lt;profile&gt; &lt;id&gt;default&lt;/id&gt; &lt;activation&gt; &lt;activeByDefault&gt;true&lt;/activeByDefault&gt; &lt;/activation&gt; &lt;/profile&gt; &lt;/profiles&gt; &lt;build&gt; &lt;!-- Existing plugins and dependencies --&gt; &lt;/build&gt; 配置文件将为项目定义配置文件特定属性,并且构建配置将应用于两个配置文件
    猜你喜欢
    • 1970-01-01
    • 2013-10-02
    • 1970-01-01
    • 2019-08-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-04-12
    • 1970-01-01
    相关资源
    最近更新 更多