【问题标题】:Maven changes the order of plugins of different profilesMaven改变不同profile的插件顺序
【发布时间】:2014-04-04 16:54:34
【问题描述】:

我有一个pom.xml,我在两个不同的profiles 中定义了相同的plugin(相同的groupIdartifactId,不同的execution :-))。 executions定义在同一个phase中,所以顺序是从xml中按顺序计算出来的:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>echo</groupId>
    <artifactId>test</artifactId>
    <name>echo-test</name>
    <version>1.0.0</version>
    <packaging>pom</packaging>
    <profiles>
        <profile>
            <id>1st-profile</id>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
            <build>
                <plugins>
                    <plugin>
                        <artifactId>maven-antrun-plugin</artifactId>
                        <executions>
                            <execution>
                                <id>1st-antrun-echo</id>
                                <phase>test</phase>
                                <goals>
                                    <goal>run</goal>
                                </goals>
                                <configuration>
                                    <tasks>
                                        <echo>1st antrun plugin</echo>
                                    </tasks>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
        <profile>
            <id>2nd-profile</id>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
            <build>
                <plugins>
                    <plugin>
                        <groupId>com.soebes.maven.plugins</groupId>
                        <artifactId>maven-echo-plugin</artifactId>
                        <version>0.1</version>
                        <executions>
                            <execution>
                                <id>1st-soebes-echo</id>
                                <phase>test</phase>
                                <goals>
                                    <goal>echo</goal>
                                </goals>
                                <configuration>
                                    <echos>
                                        <echo>1st echo-plugin</echo>
                                    </echos>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                    <plugin>
                        <artifactId>maven-antrun-plugin</artifactId>
                        <executions>
                            <execution>
                                <id>2nd-antrun-echo</id>
                                <phase>test</phase>
                                <goals>
                                    <goal>run</goal>
                                </goals>
                                <configuration>
                                    <tasks>
                                        <echo>2nd antrun plugin</echo>
                                    </tasks>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>
</project>

所有插件的执行都在test 阶段定义,因此我希望以下顺序:

1st antrun plugin
1st echo-plugin
2nd antrun plugin

但是,由于 antrun-plugins 已合并,我得到以下输出:

1st echo-plugin    
1st antrun plugin    
2nd antrun plugin

此命令解释了为什么会发生这种情况:mvn help:effective-pom

除了引入新阶段之外,还有其他解决方案来保持顺序吗?我们的项目真的很大,这是一个非常简单的例子。

为什么 maven 会限制将插件合并为一个并执行多个操作?

【问题讨论】:

  • 你真的需要这些资料吗?
  • 是的,在我的项目中,我确实需要这些配置文件。该示例是我正在处理的项目的一个非常简化的投影。
  • 您可以提交您的 pom 作为以下 MNG-2258 错误的示例。

标签: java maven maven-3 maven-plugin


【解决方案1】:

根据我的经验,这是 Maven 中最大的错误之一。如果您在不同的配置文件中为同一个插件有多个配置,则顺序根本无法预测。我什至观察到,在给定阶段,我在项目 B 中有一些插件订单,并且一旦一些相同的插件在父项目中获得配置(甚至不在同一阶段),订单就被破坏了。

https://issues.apache.org/jira/browse/MNG-2258 有一个明显错误地关闭的错误。

可能的解决方法

  • 如果可能,尝试将一些插件转移到上一阶段 (准备测试用于一些插件并测试其余的)
  • 试试 用一个替换多个插件的功能 groovy-maven-plugin 脚本(与 ant 集成非常方便,并且 您到达脚本中的活动配置文件列表)
  • 写下你的 拥有 mojo 并以正确的顺序调用插件(参见 https://github.com/TimMoore/mojo-executor)
  • 尝试 gradle。也许它符合你的需求,它附带了很多来自 Maven 的好东西

我不认为你现在可以做更多的事情。

【讨论】:

    猜你喜欢
    • 2012-01-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-04-03
    相关资源
    最近更新 更多