两个构建配置文件处于活动状态,但Maven仅在一个配置文件中执行antrun插件任务

tpu*_*nen 6 java maven-2

我们的应用程序可以为多个应用程序服务器构建,并在多个环境中使用.

应使用Maven配置文件指定应用程序服务器和目标环境的类型.编译代码时,每个配置文件类型中只应存在一个.所有配置文件都会导致执行一个或多个mavent-antrun-plugin复制任务,以便将正确的设置文件包含到生成的JAR中.

下面是pom.xml文件的一部分.包括AS简档"oracle"的一部分,以及环境概况"开发"的一部分.目的是,为了创建可以在开发环境中部署到Oracle AS的JAR,使用两个配置文件开关编译代码mvn -P oracle,development

AS配置文件还有其他任务(下面未显示),这些任务必须在环境配置文件任务发生之前执行(这就是配置文件具有不同阶段的原因).

我的问题是,Maven拒绝在两个选定的配置文件中执行任务.

mvn -Poracle就像它应该的那样工作.那样做mvn -Pdevelopment.但是,mvn -Poracle,development导致只执行oracle配置文件中的任务.如果oracle profile的antrun插件中的所有任务都被注释掉,那么开发配置文件中的任务就会被执行.

我的问题是:*为什么Maven拒绝在这两个配置文件中执行ant任务?*有没有办法来解决这个问题?

结合配置文件(oracle-development,jboss-development等)对我们来说不是一个选项,因为这个模块是一个更大项目的一部分,需要修改其他几个项目.

我们使用目前的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...
Run Code Online (Sandbox Code Playgroud)

Pas*_*ent 7

为每个添加唯一的执行ID <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>
Run Code Online (Sandbox Code Playgroud)

经过测试的工作解决方案:)没有<id>元素,我想那个<execution>会覆盖另一个.