【问题标题】:Two build profiles are active, but Maven executes antrun plugin tasks in one profile only两个构建配置文件处于活动状态,但 Maven 仅在一个配置文件中执行 antrun 插件任务
【发布时间】:2010-02-02 22:15:27
【问题描述】:

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

应使用 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 插件中的所有任务都被注释掉了,那么 development profile 中的任务就会被执行。

我的问题是: * 为什么 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...

【问题讨论】:

  • 你的antruns有依赖关系吗?

标签: java maven-2


【解决方案1】:

为每个&lt;execution&gt;添加一个唯一的执行ID:

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

经过测试的工作解决方案 :) 如果没有 &lt;id&gt; 元素,我猜&lt;execution&gt; 会覆盖另一个。

【讨论】:

    猜你喜欢
    • 2012-09-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-26
    • 2011-07-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多