【发布时间】: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有依赖关系吗?