2016-06-17 6 views
1

Я использую плагин maven enforcer. Учитывая, что у меня есть родительский и дочерний pom.xml, я бы хотел, чтобы элементы в тегахи inclusions добавлены, а не переопределены. Я пробовал использовать combine.children="append" для этого, и он работает, но я получаю дополнительный тег configuration. Я использую combine.children неправильно и/или как я могу избежать лишнего тега configuration? Смотрите пример ниже:Maven enscer append in children

В родителю pom.xml:

<project> 
    [...] 
    <build> 
    <plugins> 
     <plugin> 
     <groupId>org.apache.maven.plugins</groupId> 
     <artifactId>maven-enforcer-plugin</artifactId> 
     <version>1.4.1</version> 
     <executions> 
      <execution> 
      <id>enforce-banned-dependencies</id> 
      <goals> 
       <goal>enforce</goal> 
      </goals> 
      <configuration> 
       <rules> 
       <bannedDependencies> 
        <excludes> 
        <exclude>org.apache.maven</exclude> 
        <exclude>org.apache.maven:badArtifact</exclude> 
        <exclude>*:badArtifact</exclude> 
        </excludes> 
        <includes> 
        <!--only 1.0 of badArtifact is allowed--> 
        <include>org.apache.maven:badArtifact:1.0</include> 
        </includes> 
       </bannedDependencies> 
       </rules> 
       <fail>true</fail> 
      </configuration> 
      </execution> 
     </executions> 
     </plugin> 
    </plugins> 
    </build> 
    [...] 
</project> 

В детстве pom.xml:

<project> 
    [...] 
    <build> 
    <plugins> 
     <plugin> 
     <groupId>org.apache.maven.plugins</groupId> 
     <artifactId>maven-enforcer-plugin</artifactId> 
     <configuration> 
      <rules> 
      <bannedDependencies> 
       <includes combine.children="append"> 
       <include>org.apache.maven:otherArtifact:2.0</include> 
       </includes> 
      </bannedDependencies> 
      </rules> 
     </configuration> 
     </plugin> 
    </plugins> 
    </build> 
    [...] 
</project> 

Ожидаемая эффективная POM:

<project> 
    [...] 
    <build> 
    <plugins> 
     <plugin> 
     <groupId>org.apache.maven.plugins</groupId> 
     <artifactId>maven-enforcer-plugin</artifactId> 
     <version>1.4.1</version> 
     <executions> 
      <execution> 
      <id>enforce-banned-dependencies</id> 
      <goals> 
       <goal>enforce</goal> 
      </goals> 
      <configuration> 
       <rules> 
       <bannedDependencies> 
        <excludes> 
        <exclude>org.apache.maven</exclude> 
        <exclude>org.apache.maven:badArtifact</exclude> 
        <exclude>*:badArtifact</exclude> 
        </excludes> 
        <includes> 
        <!--only 1.0 of badArtifact is allowed--> 
        <include>org.apache.maven:badArtifact:1.0</include> 
        <include>org.apache.maven:otherArtifact:2.0</include> 
        </includes> 
       </bannedDependencies> 
       </rules> 
       <fail>true</fail> 
      </configuration> 
      </execution> 
     </executions> 
     </plugin> 
    </plugins> 
    </build> 
    [...] 
</project> 

Фактическое эффективное POM:

<project> 
    [...] 
    <build> 
    <plugins> 
     <plugin> 
     <groupId>org.apache.maven.plugins</groupId> 
     <artifactId>maven-enforcer-plugin</artifactId> 
     <version>1.4.1</version> 
     <executions> 
      <execution> 
      <id>enforce-banned-dependencies</id> 
      <goals> 
       <goal>enforce</goal> 
      </goals> 
      <configuration> 
       <rules> 
       <bannedDependencies> 
        <excludes> 
        <exclude>org.apache.maven</exclude> 
        <exclude>org.apache.maven:badArtifact</exclude> 
        <exclude>*:badArtifact</exclude> 
        </excludes> 
        <includes combine.children="append> 
        <!--only 1.0 of badArtifact is allowed--> 
        <include>org.apache.maven:badArtifact:1.0</include> 
        <include>org.apache.maven:otherArtifact:2.0</include> 
        </includes> 
       </bannedDependencies> 
       </rules> 
       <fail>true</fail> 
      </configuration> 
      </execution> 
     </executions> 
     <configuration> 
      <rules> 
      <bannedDependencies> 
       <includes combine.children="append"> 
       <include>org.apache.maven:otherArtifact:2.0</include> 
       </includes> 
      </bannedDependencies> 
      </rules> 
     </configuration> 
     </plugin> 
    </plugins> 
    </build> 
    [...] 
</project> 
+1

Хорошо, что ожидается. Родительский POM использует элемент '' выполнения, в то время как дочерняя POM использует глобальную конфигурацию (не под любым исполнением). На самом деле, я думаю, что ваш 'comb.children =" append "' не имеет никакого эффекта здесь. Вы не переопределяете один и тот же элемент конфигурации. – Tunaki

+0

Если я не использую приложение, эффективный pom будет содержать только ' org.apache.maven: otherArtifact: 2.0'. Поэтому он имеет эффект. – ET13

ответ

2

Если вы действительно хотите, чтобы получить ожидаемые слиты конфигурации, то вы должны иметь в своем ребенке модуля следующего:

<plugin> 
    <groupId>org.apache.maven.plugins</groupId> 
    <artifactId>maven-enforcer-plugin</artifactId> 
    <executions> 
     <execution> 
      <id>enforce-banned-dependencies</id> 
      <configuration> 
       <rules> 
        <bannedDependencies> 
         <includes> 
          <include>org.apache.maven:badArtifact:2.0</include> 
         </includes> 
        </bannedDependencies> 
       </rules> 
       <fail>true</fail> 
      </configuration> 
     </execution> 
    </executions> 
</plugin> 

То есть, повторное использование такого же значения, выполнение id для того, чтобы указать (переопределение/слияние) такое же исполнение с дополнительной конфигурацией.

Затем объединенный эффективный П будет следующим:

<plugin> 
    <artifactId>maven-enforcer-plugin</artifactId> 
    <version>1.4.1</version> 
    <executions> 
     <execution> 
      <id>enforce-banned-dependencies</id> 
      <goals> 
       <goal>enforce</goal> 
      </goals> 
      <configuration> 
       <rules> 
        <bannedDependencies> 
         <includes combine.children="append"> 
          <include>org.apache.maven:badArtifact:1.0</include> 
          <include>org.apache.maven:badArtifact:2.0</include> 
         </includes> 
         <excludes> 
          <exclude>org.apache.maven</exclude> 
          <exclude>org.apache.maven:badArtifact</exclude> 
          <exclude>*:badArtifact</exclude> 
         </excludes> 
        </bannedDependencies> 
       </rules> 
       <fail>true</fail> 
      </configuration> 
     </execution> 
    </executions> 
</plugin> 

Следовательно, нет необходимости использовать его: слияние по умолчанию будет отвечать вашим потребностям.


Одно важное замечание об использовании combine.* атрибутов, из official documentation

Обратите внимание, что эти атрибуты применяются только к элементу конфигурации они объявлены на, и не распространяются на вложенные элементы. То есть, если содержимое элемента элемента из дочернего POM было сложной структурой вместо текста, его подэлементы все равно будут подчиняться стратегии слияния по умолчанию, если сами они не были отмечены атрибутами.

 Смежные вопросы

  • Нет связанных вопросов^_^