将耳朵部署到服务器时遇到问题。在不同环境(dev,int,acc等)中的部署之间存在差异。对于每种环境,我们都部署到1台weblogic服务器。在某些情况下,还需要在第二台服务器上进行部署。
因此,由于这个原因,我们试图在这样的构建标记中使用antrun插件(因为它需要在每种环境的部署中运行:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<configuration>
<tasks>
... Here is our deployment task ...
</tasks>
</configuration>
<executions>
<execution><id>deploy_default</id>
<phase>deploy</phase>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
然后针对特定于环境的事情,我们使用配置文件(更改文件中的值,部署到第二台服务器等)。所以在这里我们再次做一些像这样的蚂蚁:
<profile>
<id>intg</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<configuration>
<tasks>
... Change value in files ...
</tasks>
</configuration>
<executions>
<execution>
<id>0_resource</id>
<phase>process-resources</phase>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
我们看到的问题是,例如,如果您执行mvn clean install -Pintg,它还将在构建中执行antrun插件。它不应该这样做,因为该对象是针对部署阶段的。
一些研究告诉我们,build标签中不能有两个单独的antrun插件!这对于构建中的一个和概要文件标记中的一个是一样的吗?我知道我们可以使用Maven替换插件,这样在那种情况下它们就不会是profile标签中的antrun插件,但是如果在profile标签中需要使用ant进行其他操作,那不是解决方案。
额外备注?也许可以在默认配置文件中定义antrun插件,但是是否有某种方式可以说该配置文件始终需要执行,即使在请求其他配置文件时也是如此?因此,就像您执行-Pintg->然后执行-Pdefault,intg一样(因为如果您需要在所有位置键入default,那将是一团糟)
备注2:我知道您可以将配置文件的activeByDefault设置为true,但是如果您未指定-P,我认为这仅在默认配置文件下执行。
最佳答案
配置位于插件级别,而不是执行级别。因此,通过将配置放入执行标签中,它将仅针对特定阶段和目标执行!
所以应该是这样的:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<configuration>
<tasks>
... Here is our deployment task ...
</tasks>
</configuration>
<id>deploy_default</id>
<phase>deploy</phase>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
关于java - Maven antrun插件在构建和配置文件标签中,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/19405713/