11

Web アプリケーションをデプロイするとき、UI リソースのいくつかの変数を更新し、いくつかのアセットを解凍し、いくつかのファイルを連結する必要があります。現在、これは ant タスクによって実現されています。このようなものを使用して、mavenビルドプロセスでこのタスクを実行しようとしています...

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-antrun-plugin</artifactId>
    <version>1.6</version>
    <executions>
        <execution>
            <id>deploy-ui</id>
            <phase>prepare-package</phase>
            <inherited>false</inherited>
            <configuration>
                <target>
                    <property name="buildDir" value="${project.build.directory}/${project.build.finalName}" />
                    <ant antfile="build.xml" target="static-assets" />
                </target>
            </configuration>
            <goals>
                <goal>run</goal>
            </goals>
        </execution>
    </executions>
</plugin>

ファイルがまだターゲットディレクトリにコピーされていないため、上記は失敗します。フェーズを「パッケージ」に設定すると、ant タスクは正常に実行され、すべてのファイルが作成/修正されますが、ant ターゲットが実行される前に .war が既にビルドされているため、役に立ちません。

基本的に、準備パッケージ フェーズの終わり近くで ant ターゲットを実行する必要があります。

ライフサイクル リファレンスを調べたところ、より詳細な目標を antrun プラグインに公開する方法がわかりません。

何か案は?

4

2 に答える 2

18

私のコメントに対して何の回答も得られなかったので、あなたは を使い続けたいと思いますmaven-antrun-plugin

私が学んだことと経験したことから、2 つのプラグインが同じフェーズで実行される場合、それらは で宣言されている順序で実行されpom.xmlます。

maven-war-pluginこれを機能させるには、<plugins/>リストの の後にを追加する必要がありますmaven-antrun-plugin

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-antrun-plugin</artifactId>
    <version>1.6</version>
    <executions>
        <execution>
            <id>deploy-ui</id>
            <phase>package</phase>
            <inherited>false</inherited>
            <configuration>
                <target>
                    <property name="buildDir" value="${project.build.directory}/${project.build.finalName}" />
                    <ant antfile="build.xml" target="static-assets" />
                </target>
            </configuration>
            <goals>
                <goal>run</goal>
            </goals>
        </execution>
    </executions>
</plugin>
<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-war-plugin</artifactId>
    <version>2.3</version>
    <executions>
        <execution>
            <!-- First step is to disable the default-war build step. -->
            <id>default-war</id>
            <phase>none</phase>
        </execution>
        <execution>
            <!-- Second step is to create an exploded war. Done in prepare-package -->
            <id>war-exploded</id>
            <phase>prepare-package</phase>
            <goals>
                <goal>exploded</goal>
            </goals>
        </execution>
        <execution>
            <!-- Last step is to make sure that the war is built in the package phase -->
            <id>custom-war</id>
            <phase>package</phase>
            <goals>
                <goal>war</goal>
            </goals>
        </execution>
    </executions>
</plugin>

default-warが最初に無効になり、次に戦争が爆発し、最後に戦争がパッケージ化されるように、いくつかの実行を追加しました。

于 2012-10-01T11:24:35.443 に答える
1

ご覧のとおり、これはライフサイクルが必要な粒度を提供しない場所です。私は以前に誰かのために同様の質問に答えました。それはあなたの質問に対する正確な答えではありませんが、テクニックが適用されるかもしれません。

于 2012-10-02T13:51:32.087 に答える