2016-08-25 74 views
0

我有一個父聚合POM與多個模塊。我有一個父親build/pluginManagement,因爲每個子模塊的插件執行是相同的。如何跳過Maven插件父pom執行?

如果我在每個子模塊中執行(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) 

回答

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中。