9

maven-antrun-pluginを使用して、ファイルが存在するかどうかを最初の実行でチェックインし、それに応じてプロパティを設定しようとしました。antrun-pluginの別の実行(別のフェーズ)で、プロパティを利用したいと思います。ただし、ある実行で設定されたプロパティは、Mavenプロパティではなくantであり、伝播されないため、別の実行で使用することはできません。

antプロパティをmavenに伝播すること、つまり、antからmavenプロパティを設定することは可能ですか?

この質問のように別のMavenビルドを使用することはオプションではありません。

どういうわけか機能する可能性のある別の方法は、外部のbuild.xmlですが、これもオプションではありません。1つのpomに物事を保持する必要があるためです。

GMavenを使用してMavenプロパティを設定する方法について読みましたが、antを使用したいと思います。

4

3 に答える 3

9

maven-antrun-pluginのバージョン1.7以降、プラグインのドキュメントに従って可能です(exportAntPropertiesを参照)。したがって、以前のバージョンでは、そうではないと思います;-)。

于 2011-12-21T11:24:20.860 に答える
1

antrun-pluginの代わりに、ファイルの存在に応じて、戦略をさまざまなプロファイルのアクティブ化にリダイレクトできます。

<profiles>
    <profile>
        <id>notExist</id>
        <activation>
          <file>
            <missing>target/maven-archiver/notExist.properties</missing>
          </file>
        </activation>

    <build>
        <plugins>
            <plugin>
                <artifactId>maven-antrun-plugin</artifactId>
                <version>1.3</version>
                <executions>
                  <execution>
                    <phase>package</phase>
                    <goals>
                      <goal>run</goal>
                    </goals>
                    <configuration>
                        <tasks>
                            <echo>not exist</echo>
                        </tasks>
                    </configuration>
                  </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</profile>

<profile>
    <id>exist</id>
    <activation>
      <file>
        <exists>target/maven-archiver/pom.properties</exists>
      </file>
    </activation>
    <build>
        <plugins>
            <plugin>
                <artifactId>maven-antrun-plugin</artifactId>
                <version>1.3</version>
                <executions>
                  <execution>
                    <phase>package</phase>
                    <goals>
                      <goal>run</goal>
                    </goals>
                    <configuration>
                        <tasks>
                            <echo>not exist</echo>
                        </tasks>
                    </configuration>
                  </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</profile>

アクティベーションプロファイルのMaven機能を使用して、アクティベーション基準に従って1つの構成と別の構成を区別できます。

例では、エコーを実行するためにのみantrun-pluginを使用します

于 2011-08-05T20:56:54.160 に答える
1

はい、デフォルト値でも可能です。install.pathエコーを使用した設定例:

<plugin>
    <!-- Workaround maven not being able to set a property conditionally based on environment variable -->
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-antrun-plugin</artifactId>
    <version>1.8</version>
    <executions>
        <execution>
            <phase>validate</phase>
            <goals>
                <goal>run</goal>
            </goals>
            <configuration>
                <exportAntProperties>true</exportAntProperties>
                <target>
                    <property environment="env"/>
                    <condition property="install.path" value="${env.INSTALL_HOME}" else="C:\default-install-home">
                        <isset property="env.INSTALL_HOME" />
                    </condition>
                    <echo message="${install.path}"/>
                </target>
            </configuration>
        </execution>
    </executions>
</plugin>
于 2016-04-21T12:50:43.740 に答える