【问题标题】:maven antrun plugin in build and profile tags构建和配置文件标签中的 maven antrun 插件
【发布时间】:2013-10-16 14:09:40
【问题描述】:

我们在将 ear 部署到服务器时遇到问题。在不同的环境(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 插件。它不应该这样做,因为那是针对部署阶段的。

一些研究告诉我们,构建标签中不能有两个单独的 antrun 插件!这对于构建中的一个和配置文件标签中的一个是否相同?我知道我们可以使用 maven replacer 插件,所以在这种情况下,它们不会是配置文件标签中的 antrun 插件,但如果配置文件标签中的 ant 需要发生其他事情,这不是一个解决方案。

补充说明?也许可以在默认配置文件中定义 antrun 插件,但是有没有办法说该配置文件总是需要执行,即使有其他配置文件请求?所以就像如果你会做 -Pintg -> 那么它会做 -Pdefault, intg (因为如果你需要在任何地方输入 default 会很混乱)

备注 2:我知道您可以将配置文件的 activeByDefault 设置为 true,但我假设这仅使用默认配置文件执行,如果您没有指定 -P?

【问题讨论】:

    标签: java deployment maven-3


    【解决方案1】:

    配置在插件级别,而不是执行级别。因此,通过将配置放在执行标签中,它只会针对特定的阶段和目标执行!

    所以应该是这样的:

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

    【讨论】:

      猜你喜欢
      • 2011-04-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-12-21
      相关资源
      最近更新 更多