简体   繁体   中英

Two build profiles are active, but Maven executes antrun plugin tasks in one profile only

Our application can be built for several application servers, and used in several environments.

Type of application server and target environment should be specified using Maven profiles. One and only one of each profile type should be present when compiling the code. All profiles cause execution of one or several mavent-antrun-plugin copy tasks in order to include correct setting files to the generated JAR.

Below is part of the pom.xml file. Part of AS profile "oracle" is included, as well as part of environment profile "development". The purpose is, that in order to create JAR which can be deployed to Oracle AS in development environment, the code is compiled using two profile switches mvn -P oracle,development

AS profiles have also other tasks (not shown below) which have to be executed before the environment profile tasks take place (that's the reason profiles have different phases).

My issue is, that Maven refuses to execute tasks in both of the selected profiles.

mvn -Poracle works just as it's supposed. So does mvn -Pdevelopment . However, mvn -Poracle,development results in execution of only the tasks in oracle profile. If all the tasks in oracle profile's antrun plugin are commented out, then the tasks in development profile do get executed.

My questions are: * Why does Maven refuse to execute ant tasks in both of these profiles? * Is there a way to fix this?

Combining the profiles (oracle-development, jboss-development etc.) is not an option for us, because this module is part of a bigger project and would require modifications to several other projects.

We use currently Maven 2.2.0.

<profile>
  <id>oracle</id>       
  <build>
    <plugins>       
      <plugin>
        <artifactId>maven-antrun-plugin</artifactId>
        <executions>
          <execution>
            <phase>validate</phase>
            <goals>
              <goal>run</goal>
            </goals>
            <configuration>
              <tasks>
                 <copy .../>
              </tasks>
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>      
  </build>
</profile>    

...jboss, glassfish profiles... 

<profile>
  <id>development</id>
  <build>
    <plugins>
      <plugin>
        <artifactId>maven-antrun-plugin</artifactId>
        <executions>
          <execution>
            <phase>compile</phase>
            <goals>
              <goal>run</goal>
            </goals>
            <configuration>
              <tasks>
                <copy .../>
              </tasks>
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
</profile>

...production, test profiles...

Add a unique execution id to each <execution> :

<profile>
  <id>oracle</id>       
  <build>
    <plugins>       
      <plugin>
        <artifactId>maven-antrun-plugin</artifactId>
        <executions>
          <execution>
            <id>execution1</id>
            <phase>validate</phase>
            <goals>
              <goal>run</goal>
            </goals>
            <configuration>
              <tasks>
                 <echo>ORACLE</echo>
              </tasks>
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>      
  </build>
</profile>    
<profile>
  <id>development</id>
  <build>
    <plugins>
      <plugin>
        <artifactId>maven-antrun-plugin</artifactId>
        <executions>
          <execution>
            <id>execution2</id>
            <phase>compile</phase>
            <goals>
              <goal>run</goal>
            </goals>
            <configuration>
              <tasks>
                 <echo>DEV</echo>
              </tasks>
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
</profile>

Tested working solution :) Without the <id> element, I guess that one <execution> overrides the other.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM