2016-12-13 15 views
3

Mavenプロジェクトのビルドを実行しているアクティブな現在のプロファイルを印刷しようとしています。Maven:現在のプロファイルをコンソールに印刷する方法は?

私はmaven-antrun-pluginを使用して、現在のプロファイルを参照するプロパティと組み合わせてメッセージをコンソールに出力します。

${project.activeProfiles[0].id} 

${project.profiles[0].id} 

をしかし、両方のケースでは、変数を解決せずに、それが書かれているとして「文字列」を出力します。

は、私は、次のプロパティを試してみました。

これは私のテストで:

<build> 
    <plugins> 
     <plugin> 
      <artifactId>maven-antrun-plugin</artifactId> 
      <executions> 
       <execution> 
        <phase>generate-resources</phase> 
        <goals> 
         <goal>run</goal> 
        </goals> 
        <configuration> 
         <tasks> 
          <echo>current active profile: ${project.activeProfiles[0].id}</echo> 
         </tasks> 
        </configuration> 
       </execution> 
      </executions> 
     </plugin> 
    </plugins> 
</build> 

しかし、これは私が得る結果である:任意の提案が理解されるであろう

main: 
[echo] current active profile: ${project.activeProfiles[0].id} 

ありがとうございました。

+0

のように、それを使用する理由プロファイルに依存している、あなたが特にやりたいですか? – Tunaki

答えて

2

maven-help-pluginには、必要なものがあります。それはactive-profilesという目標を持っています。

あなたのpomに追加することも、コマンドラインから呼び出すこともできます(ビルド呼び出しでそれを組み込むことができます)。 ビルド中にどのプロファイルが有効であるかをどのように知ることができますか? Maven profile introduction pageセクションにはどのように表示されますか。要するに:

mvn help:active-profiles 

これはあなたのために動作しないよう(コメントを参照)、ここで別のソリューションです:

私は、アクティブなプロファイルが(!つ以上存在することができます)は反映されませんだと思いますavailable variablesと同じですが、プロパティはです。

だから、プロファイルセクションのカスタムプロパティを設定し、

<profiles> 
    <profile> 
     <id>default</id> 
     <activation> 
      <activeByDefault>true</activeByDefault> 
     </activation> 
     <properties> 
      <myProfile>default</myProfile> 
     </properties> 
    </profile> 
    <profile> 
     <id>debug</id> 
     <activation> 
      <property> 
       <name>debug</name> 
      </property> 
     </activation> 
     <properties> 
      <myProfile>debug</myProfile> 
     </properties> 
    </profile> 
</profiles> 

<build> 
    <plugins> 
     <plugin> 
      <artifactId>maven-antrun-plugin</artifactId> 
      <executions> 
       <execution> 
        <phase>generate-resources</phase> 
        <goals> 
         <goal>run</goal> 
        </goals> 
        <configuration> 
         <tasks> 
          <echo>current active profile: ${myProfile}</echo> 
         </tasks> 
        </configuration> 
       </execution> 
      </executions> 
     </plugin> 
    </plugins> 
</build> 
+0

はい、これは私が必要なものではありません。プロファイルに基づいていくつかの操作を行いたいので、変数でアクセスしているプロファイルを印刷したいのですが。 –

+1

私の更新を見てください。 – FrVaBe

+0

正確には、これは私が必要なものです!ありがとう! –

関連する問題