如何使用不同的属性两次执行Maven插件 [英] How to execute a maven plugin twice with different property

查看:89
本文介绍了如何使用不同的属性两次执行Maven插件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从运行同一插件的两个顺序执行的maven pom进行构建,在同一阶段中,区别仅在于单个属性,这将导致创建两个不同的存档.由于配置相当复杂,因此我不想复制它只是为了更改一个值,这将造成维护的噩梦.如果可以通过某种方式在插件配置的<executions>部分中定义这样的属性,则可以避免这种麻烦.

I would like to build from a maven pom running two sequential executions of the same plugin, in the same phase differing only by a single property, which will result in two different archives being created. Since the configuration is rather complicated, I'd rather NOT copy it just to change one value, which would create a maintenance nightmare. If it was somehow possible to define such a property in the <executions> section of the plugin config, I could avoid this headache.

问题:这可能吗?如果可以,怎么可能?

Question: Is this possible and if so how?

更新:提到了使用多个执行的两个答案,其中一个提到您可以在每个执行中使用单独的配置.但是,考虑到我的大部分配置在两次执行之间是恒定的,我可以在插件级别上拥有一个配置,并且在每次执行中也可以有针对不同部分的配置部分吗?

Update: Two answers have mentioned using multiple executions and one of them mentions that you can have separate configurations in each execution. But given that the majority of my configuration is constant between the two executions, can I have one configuration on the plugin level and also have configuration sections in each execution for the parts that are different?

推荐答案

给出简单的Maven源插件配置(例如),您在所有执行中都拥有一个共享配置(在executions元素之外),然后根据您的问题的要求,在同一阶段的每次执行中自定义配置:

Given the simple Maven Source Plugin configuration (as an example) you have a shared configuration across all of its executions (outside the executions element) and then a custom configuration per each execution, for the same phase, as requested by your question:

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-source-plugin</artifactId>
            <version>2.4</version>
            <configuration>
                <includePom>true</includePom>
            </configuration>
            <executions>
                <execution>
                    <id>test-id1</id>
                    <phase>verify</phase>
                    <goals>
                        <goal>jar</goal>
                    </goals>
                    <configuration>
                        <finalName>aaa</finalName>
                    </configuration>
                </execution>
                <execution>
                    <id>test-id2</id>
                    <phase>verify</phase>
                    <goals>
                        <goal>jar</goal>
                    </goals>
                    <configuration>
                        <finalName>bbb</finalName>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

在这种情况下,配置条目<includePom>true</includePom>将与每次执行的自定义配置合并,因此集中了通用配置(如插件通用配置).

The configuration entry <includePom>true</includePom> will in this case be merged with the custom configurations of each execution and as such centralize the common configuration as plugin generic configuration.

有关不同级别配置的更多详细信息,可以查看Maven官方文档,此处,尤其是示例配置编译以运行两次".进一步的详细信息也可以在官方POM文档的此处的插件"部分中找到.

For more details on the different level of configurations, you can check official Maven documentation, here, in particular the example "Configuring compile to run twice". Further details are also available on the official POM documentation, here, Plugins section.

这篇关于如何使用不同的属性两次执行Maven插件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆