如何跳过Maven插件父pom的执行?

6

我有一个包含多个模块的父级聚合POM。在父级中有一个build/pluginManagement,因为每个子模块的插件执行方式都相同。

如果我在每个子模块中执行 (mvn package),它可以正常工作。如果我在父级中执行: mvn package -Pmytest,我想跳过父级模块中的插件执行,所以我添加了:

    <plugin>
        <groupId>org.wildfly.plugins</groupId>
        <artifactId>wildfly-maven-plugin</artifactId>
        <configuration>
            <skip>true</skip>
        </configuration>
    </plugin>

然而,它没有起作用。
父 pom.xml:
<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>com.xyz.jboss.config</groupId>
    <artifactId>jboss-config</artifactId>
    <packaging>pom</packaging>
    <version>1.2-SNAPSHOT</version>
    <name>jboss-config</name>
    <url>http://maven.apache.org</url>

    <profiles>
        <profile>
            <id>mytest</id>
            <modules>
                <module>jboss-system-properties</module>
                <module>jboss-security</module>
            </modules>
        </profile>
    </profiles>
    <build>
        <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-resources-plugin</artifactId>
                    <executions>
                        <execution>
                            <id>process-package</id>
                            <phase>package</phase>
                            <goals>
                                <goal>copy-resources</goal>
                            </goals>
                            <configuration>
                                <outputDirectory>${basedir}/processed/scripts</outputDirectory>
                                <resources>
                                    <resource>
                                        <directory>${basedir}/src/main/resources/scripts</directory>
                                        <filtering>true</filtering>
                                    </resource>
                                </resources>
                            </configuration>
                        </execution>
                        <execution>
                            <id>process-clean</id>
                            <phase>clean</phase>
                            <goals>
                                <goal>copy-resources</goal>
                            </goals>
                            <configuration>
                                <outputDirectory>${basedir}/processed/scripts</outputDirectory>
                                <resources>
                                    <resource>
                                        <directory>${basedir}/src/main/resources/scripts</directory>
                                        <filtering>true</filtering>
                                    </resource>
                                </resources>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>
                <plugin>
                    <groupId>org.wildfly.plugins</groupId>
                    <artifactId>wildfly-maven-plugin</artifactId>
                    <executions>
                        <execution>
                            <id>add-${project.artifactId}</id>
                            <phase>package</phase>
                            <goals>
                                <goal>execute-commands</goal>
                            </goals>
                            <configuration>
                                <execute-commands>
                                    <scripts>
                                        <script>${basedir}/processed/scripts/add-${project.artifactId}.cli</script>
                                    </scripts>
                                </execute-commands>
                            </configuration>
                        </execution>
                        <execution>
                            <id>remove-${project.artifactId}</id>
                            <phase>clean</phase>
                            <goals>
                                <goal>execute-commands</goal>
                            </goals>
                            <configuration>
                                <execute-commands>
                                    <scripts>
                                        <script>${basedir}/processed/scripts/remove-${project.artifactId}.cli</script>
                                    </scripts>
                                </execute-commands>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </pluginManagement>

        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-resources-plugin</artifactId>
                <configuration>
                    <skip>true</skip>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.wildfly.plugins</groupId>
                <artifactId>wildfly-maven-plugin</artifactId>
                <configuration>
                    <skip>true</skip>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

子POM文件

<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>
    <parent>
        <groupId>com.xyz.jboss.config</groupId>
        <artifactId>jboss-config</artifactId>
        <version>1.2-SNAPSHOT</version>
    </parent>
    <artifactId>jboss-system-properties</artifactId>
    <packaging>ear</packaging>
    <name>jboss-system-properties</name>
    <url>http://maven.apache.org</url>
</project>

我遇到了一个文件未找到的错误。这个文件不应该存在于这里。问题在于为什么它没有跳过父模块的执行。

[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO]
[INFO] jboss-config ....................................... FAILURE [ 20.238 s]
[INFO] jboss-system-properties ............................ SKIPPED
[INFO] jboss-security ..................................... SKIPPED
[INFO] ------------------------------------------------------------------------

[ERROR] Failed to execute goal org.wildfly.plugins:wildfly-maven-plugin:1.0.2.Final:
    execute-commands (add-jboss-config) on project jboss-config: 
    Execution add-jboss-config of goal org.wildfly.plugins:wildfly-maven-plugin:1.0.2.Final:execute-commands failed: 
    Failed to process file 'H:\projects\xyz\jboss\trunk\jboss-configuration\processed\scripts\add-jboss-config.cli': 
    H:\projects\xyz\jboss\trunk\jboss-configuration\processed\scripts\add-jboss-config.cli 
    (The system cannot find the path specified) 
1个回答

4

我找到了问题所在。如果执行id是参数化的,就像我的情况:

   <plugin>
       <groupId>org.wildfly.plugins</groupId>
       <artifactId>wildfly-maven-plugin</artifactId>
       <executions>
           <execution>
               <id>add-${project.artifactId}</id>
...
...
       <executions>
           <execution>
               <id>remove-${project.artifactId}</id>
...
...

要跳过插件执行,您需要显式指定执行ID和阶段:

        <plugin>
            <groupId>org.wildfly.plugins</groupId>
            <artifactId>wildfly-maven-plugin</artifactId>
            <executions>
                <execution>
                    <id>add-jboss-config</id>
                    <phase/>
                </execution>
                <execution>
                    <id>remove-jboss-config</id>
                    <phase/>
                </execution>
          </executions>
          <configuration>
                <skip>true</skip>
            </configuration>
        </plugin>

现在它跳过父级,在所有子模块中执行,并且我只有一个插件配置的地方。
注意:我尝试使用静态执行ID,但这会导致在子模块中也跳过执行。另外,我不确定所有这些问题是否都只存在于wildfly-maven-plugin中。

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