【问题标题】:How to skip Maven plugin parent pom execution?如何跳过 Maven 插件父 pom 执行?
【发布时间】:2017-01-02 09:18:31
【问题描述】:

我有一个包含多个模块的父聚合器 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.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>
    <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) 

【问题讨论】:

    标签: maven maven-3 wildfly maven-plugin wildfly-8


    【解决方案1】:

    我发现了问题。如果执行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 中。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-10-31
      • 1970-01-01
      • 1970-01-01
      • 2018-07-18
      • 1970-01-01
      相关资源
      最近更新 更多