/ / mavenプラグイン構成の継承(ネストされた要素のマージ戦略)-java、maven、maven-plugin

mavenプラグインの設定継承(ネストした要素のマージ戦略) - java、maven、maven-plugin

もう読んだ この そして それ。言葉遣いの違いを除いて、基本的に同じ内容です。後者には、指摘したい重要な言葉があります。

構成要素は 再帰的に 要素名に基づいてマージ...

前者では、次のように書かれています。

デフォルトの動作では、のコンテンツをマージします要素名に応じた構成要素。子POMに特定の要素がある場合、その値が有効な値になります。子POMに要素がなく、親にある場合、親の値が有効な値になります。

私の質問は、構成要素がネストされた要素である場合です。私の親pom.xmlに次のものがあるとしましょう。

<build>
<plugins>
<plugin>
<executions>
<execution>
<id>enforce-maven</id>
<goals>
<goal>enforce</goal>
</goals>
<configuration>
<rules>
<bannedDependencies>
<excludes>
<exclude>com.my.group:my.id</exclude>
</excludes>
</bannedDependencies>
</rules>
</configuration>
...

それから私の子供のポンポンで、私は持っています:

<build>
<plugins>
<plugin>
<executions>
<execution>
<id>enforce-maven</id>
<goals>
<goal>enforce</goal>
</goals>
<configuration>
<rules>
<bannedDependencies>
<includes>
<include>com.my.group:my.id</include>
</includes>
</bannedDependencies>
</rules>
</configuration>
...

あなたが見ることができるように、私はしようとしている include 親が持つ依存関係 exclude編ここで要素をマージしようとしているので(<excludes> そして <includes>)中 </rules>/</bannedDependencies>、私が得るかどうかわからない:

<build>
<plugins>
<plugin>
<executions>
<execution>
<id>enforce-maven</id>
<goals>
<goal>enforce</goal>
</goals>
<configuration>
<rules>
<bannedDependencies>
<excludes>
<exclude>com.my.group:my.id</exclude>
</excludes>
<includes>
<include>com.my.group:my.id</include>
</includes>
</bannedDependencies>
</rules>
</configuration>
...

または、子pomが指定するもの(つまり、親pomのネストされた要素は、子pomの要素に置き換えられます)。

回答:

回答№1は1

あなたは両方を取得します includes そして excludes。これを確認するには、次のコマンドを実行します。 mvn help:effective-pom。エンフォーサプラグインは、除外の例外としてインクルードを処理するため、同じアーティファクトを除外してからインクルードすると、禁止されないという効果があります(これはテストしていませんが)。

構成の継承に疑問がある場合、Mavenが構成要素を再帰的にマージする 最も内側の 要素と外向きなので、この場合、 bannedDependencies 要素は両方を取得します includes 子からの要素と excludes 親からの要素。子が何かを継承したくない場合 bannedDependencies 要素の場合、子pomで以下を実行できます。

<bannedDependencies combine.self="override">
...
</bannedDependencies>