2017-04-13 10 views
0

(巨大な)プロジェクトをビルドするためにantを使用しました。(従来の理由から)プロパティファイル内のプロパティをかなり深くネストしました。プロパティ(プロパティ内)のプロパティのネスト

(例えば、内部のbuild.xml)

<ant dir="${object.build.dir}" target="deploy" /> 

())(時には同じいくつかの他のプロパティファイル内のいくつかのプロパティファイル:)

object.build.dir=${base.dir} 

(内側:

base.dir=${env}/some/dir 

それでは、アリはそれほど最近のものではないので、私たちは今すぐmavenに移動しています。これはかなり悪夢になるでしょう...

質問は:どのように...(テストなど)

フィルタ/ top_levelを深く、時には限り5としてのレベルのプロパティ内の営巣特性の結果である特性を読んでください。プロパティ:

env=test 

フィルター/テスト/ mid_level.properties:

specific=spec 

フィルタ/ top_level.propertiesも(別の環境のために)読むことができる:

env=prod 

ので、フィルタ/ PROD/mid_level.propertiesを:

specific=spock 

質問はこれに沸く:

どのようにして、パスが別のプロパティファイルで定義されているプロパティファイル内で定義された '特定の'プロパティを読み書きするのですか?) (この種類の入れ子はどこですか?)

また、これは 'リソース'に関係しません(これらも含まれていますが、主な問題ではなく、リソースはアプリケーションによって使用されるプロパティです、私が話すプロパティはビルド時にのみ使用されるプロパティですあなたがproperties:read-project-propertiesプラグインを持っているのmavenで

S.

+0

あなたのプロパティは、異なる環境用の設定のように見え、AntでもMavenでもプロパティを使用することは決して良いことではない。 ..ここで見ることができるかもしれません:https://github.com/khmarbaise/multienv-maven-plugin...さらに、私はあなたがdev、prodなどを意味する各プロパティのたびにビルドすることを前提としています。 Mavenでは動作しません...一度構築して一回ですべての必要な出力を生成してください... – khmarbaise

+0

ねえ、ありがとう、確かにそれを見てみましょう。 – Bamboomy

答えて

0

...ビルドが)

をたまたま私は答えを見つけましたが、1つのよりよいがある場合、私は最良の答えとしてことを選択して喜んでいると思います。

このように使用すると、ネストされたプロパティは下位のプロパティに挿入されません: (mavenはそれでも "filters/$ {env}/mid_level"プロパティ」プロパティファイル

<build> 
    <plugins> 
     <plugin> 
      <groupId>org.codehaus.mojo</groupId> 
      <artifactId>properties-maven-plugin</artifactId> 
      <version>1.0.0</version> 
      <executions> 
       <execution> 
        <id>execution1</id> 
        <phase>initialize</phase> 
        <goals> 
         <goal>read-project-properties</goal> 
        </goals> 
        <configuration> 
         <files> 
          <file>filters/top_level.properties</file> 
          <file>filters/${env}/mid_level.properties</file> 
         </files> 
        </configuration> 
       </execution> 
      </plugin> 
    </plugins> 
</build> 

しかし、あなたは '具体的な' の値をエコー+このような処刑(:) ENV = PRODと

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 
    <modelVersion>4.0.0</modelVersion> 
    <groupId>test</groupId> 
    <artifactId>test</artifactId> 
    <version>0.0.1-SNAPSHOT</version> 
    <name>test</name> 
    <description>test</description> 

    <build> 
     <plugins> 
      <plugin> 
       <groupId>org.codehaus.mojo</groupId> 
       <artifactId>properties-maven-plugin</artifactId> 
       <version>1.0.0</version> 
       <executions> 
        <execution> 
         <id>execution1</id> 
         <phase>initialize</phase> 
         <goals> 
          <goal>read-project-properties</goal> 
         </goals> 
         <configuration> 
          <files> 
           <file>filters/top_level.properties</file> 
          </files> 
         </configuration> 
        </execution> 
        <execution> 
         <id>execution2</id> 
         <phase>initialize</phase> 
         <goals> 
          <goal>read-project-properties</goal> 
         </goals> 
         <configuration> 
          <files> 
           <file>filters/${env}/mid_level.properties</file> 
          </files> 
         </configuration> 
        </execution> 
       </executions> 
      </plugin> 

      <plugin> 
       <groupId>com.soebes.maven.plugins</groupId> 
       <artifactId>maven-echo-plugin</artifactId> 
       <version>0.1</version> 
       <executions> 
        <execution> 
         <phase>install</phase> 
         <goals> 
          <goal>echo</goal> 
         </goals> 
        </execution> 
       </executions> 
       <configuration> 
        <echos> 
         <echo>Animal: ${specific}</echo> 
        </echos> 
       </configuration> 
      </plugin> 
     </plugins> 
    </build> 
</project> 

出力区切る場合:

[INFO] --- maven-echo-plugin:0.1:echo (default) @ test --- 
[INFO] Animal: spock 
[INFO] ------------------------------------------------------------------------ 
[INFO] BUILD SUCCESS 
[INFO] ------------------------------------------------------------------------ 
[INFO] Total time: 2.663 s 
[INFO] Finished at: 2017-04-13T21:32:30+02:00 
[INFO] Final Memory: 11M/164M 
[INFO] ------------------------------------------------------------------------ 

問題解決済み:

ネスティング+リファクタリングの深さだけ多くのプロパティを実行する必要がありますプロパティはそれらを層で持っているが、この問題が容易に解決されていることからappartする。

関連する問題