2

maven フィルター タグと、それがプラグインの properties-maven-plugin の files タグにどのように対応するかについて説明したいと思います。

問題のプロファイル:

<profile>
    <id>local-spm-caefeeder-preview</id>
    <build>
        <plugins>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>properties-maven-plugin</artifactId>
                <version>1.0-alpha-1</version>
                <executions>
                    <execution>
                        <phase>initialize</phase>
                        <goals>
                            <goal>read-project-properties</goal>
                        </goals>
                        <configuration>
                        <quiet>true</quiet>
                        <files>
                            <file>${main.basedir}/src/config/global.properties</file>
                            <file>${main.basedir}/src/config/caefeeder/caefeeder_global.properties</file>
                            <file>${main.basedir}/src/config/caefeeder/caefeeder_preview.properties</file>
                            <file>${main.basedir}/src/config/local.properties</file>
                            <file>${main.basedir}/src/config/${user.name}.properties</file>
                        </files>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
        <filters>
            <filter>${main.basedir}/src/config/caefeeder/caefeeder_global.properties</filter>
            <filter>${main.basedir}/src/config/caefeeder/caefeeder_preview.properties</filter>
            <filter>${main.basedir}/src/config/local.properties</filter>
            <filter>${main.basedir}/src/config/${user.name}.properties</filter>
        </filters>
    </build>
</profile>

私の調査によると、フィルターは、置換が必要な変数を含むファイルを定義します。「properties-maven-plugin」は、ファイルタグで定義されたファイルからこれらの変数を提供しますか?

4

1 に答える 1

6

まず、Maven フィルタを実際に機能させるには、特定のディレクトリに対してリソース フィルタリングを有効にする必要があります。

  <resource>
    <directory>src/main/resources</directory>
    <filtering>true</filtering>
  </resource>

これらの読み取り値はどこにも使用されていないため、いくつかのフィルターファイルをリストするだけでは何も起こりません。

さて、ここで違いの説明。プロパティ ファイルからいくつかの値read-project-propertiesを読み取り、それらを Maven 変数として保存するという目標。properties-maven-pluginMaven ライフサイクル ( <phase>initialize</phase>) のかなり早い段階で実行されるため、ほぼ最初から利用できます。<properties>したがって、これは、Maven のプロパティを、おそらく巨大なブロックの代わりに、いくつかの通常のプロパティ ファイルに入れることによって外部化する方法であると言えますpom.xml。ここで重要なのは、Maven 変数がリソース フィルタリングで使用されていることです。

さて、<filters>タグ。これらのファイルは Maven プロジェクト変数を提供しません。これらは、リソースのフィルタリングにのみ使用される変数を提供します。

したがって、リソース フィルタリングのコンテキストでは、実際の動作はほとんど同じです。によって読み取られたプロパティはproperties-maven-plugin、リソース フィルタリングに使用されるだけでなく、フィルター ファイルから読み取られたプロパティにも使用されます。ただし、読み込まれたものproperties-maven-pluginはMavenプロジェクトのプロパティとしても利用できるため、プラグインの構成やその他のPOM関連のものなどで使用できます。

于 2012-07-03T08:49:22.673 に答える