build-helper-maven-plugin
親ファイルで を使用して、pom.xml
に基づいて新しいプロパティを作成できますpackaging
(実行時にpom
、親jar
からwar
モジュールに変更されます)。maven-install-plugin
この新しいプロパティは、動的にスキップするために使用できます。
簡単な例:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.10</version>
<executions>
<execution>
<id>build-helper-regex-is-packaging-war</id>
<phase>validate</phase>
<goals>
<goal>regex-property</goal>
</goals>
<configuration>
<name>only.when.war.is.used</name>
<value>${project.packaging}</value>
<regex>war</regex>
<replacement>true</replacement>
<failIfNoMatch>false</failIfNoMatch>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-install-plugin</artifactId>
<version>2.5.2</version>
<configuration>
<skip>${only.when.war.is.used}</skip>
</configuration>
</plugin>
そうすることで、動的${only.when.war.is.used}
プロパティは値を持つ場合にtrue
のみに設定され、オプションを介して実行を効果的にスキップします。project.packaging
war
maven-install-plugin
skip
次に、この動作をプロファイルに移動して、 と の異なる設定をjar
行い、動的な動作のおかげでwar
root という共通の場所に保持できます。pom.xml
アーティファクトが既にインストールされているかどうかを検出する機能に関しては、プラグインの公式ドキュメントにはそのようなオプションはなく、単にプラグインを使用するだけでそのような動作を行うことはできないと思います.
ただし、ファイル (インストールされたファイル) が見つからない場合は、 maven プロファイルのアクティブ化メカニズムを使用して、それに応じてプロファイルをアクティブ化できます。
動的な方法で (標準プロパティのみに基づいて) 次のアプローチを使用できます。
<profiles>
<profile>
<activation>
<file>
<missing>${settings.localRepository}/${project.groupId}/${project.artifactId}/${project.build.fileName}.${project.packaging}</missing>
</file>
</activation>
...
</profile>
</profiles>