program story

상위 POM의 프로필에 대해 이미 정의 된 플러그인의 구성을 재정의 할 수 있습니까?

inputbox 2020. 8. 22. 08:48
반응형

상위 POM의 프로필에 대해 이미 정의 된 플러그인의 구성을 재정의 할 수 있습니까?


내 프로젝트의 POM 상위 파일에는이 프로젝트에 유용한 몇 가지 구성을 정의하는 프로필이 있습니다 (이 상위 POM을 제거 할 수 없음).

<profile>
<id>wls7</id>
...
<build>
  <plugins>
    <!-- use java 1.4 -->
    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-compiler-plugin</artifactId>
      <configuration>
        <fork>true</fork>
        <source>1.4</source>
        <target>1.4</target>
        <meminitial>128m</meminitial>
        <maxmem>1024m</maxmem>
        <executable>%${jdk14.executable}</executable>
      </configuration>
    </plugin>
  </plugins>
</build>

...
</profile>

그러나 내 프로젝트에서는 테스트 클래스를 컴파일하는 데 jdk4 대신 jdk5를 사용하기 위해 maven-compiler-plugin의 구성을 재정의하고 싶습니다.

이것이 내 프로젝트의 POM에서이 섹션을 수행 한 이유입니다.

<profiles>
  <profile>
    <id>wls7</id>
        <activation>
            <property>
                <name>jdk</name>
                <value>4</value>
            </property>
        </activation>
    <build>
      <directory>target-1.4</directory>
      <plugins>
        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-compiler-plugin</artifactId>
          <executions>
            <execution>
              <id>my-testCompile</id>
              <phase>test-compile</phase>
              <goals>
                <goal>testCompile</goal>
              </goals>
              <configuration>
                <fork>true</fork>
                <executable>${jdk15.executable}</executable>
                <compilerVersion>1.5</compilerVersion>
                <source>1.5</source>
                <target>1.5</target>
                <verbose>true</verbose>
              </configuration>
            </execution>
          </executions>
        </plugin>
      </plugins>
    </build>
  </profile>
              ...
</profiles>

작동하지 않습니다 ...

내 POM의 일반 플러그인 섹션에서 구성을 재정의하려고 시도했습니다 (특정 프로필이 아니라 전체 POM에 대한 것입니다).

무엇이 문제일까요?

내 요구 사항 중 일부를 명확히하려면 다음을 수행하십시오.

  • I don't want to get rid of the parent POM and the profile (wls7) defined inside it (since I need many and many properties, configurations, ...) and that is not the process in my company.
  • A solution based on duplicating the parent POM and/or the profile defined inside it is not a good one. Since if the responsible of
    the parent POM change something, I
    would have to report it in mine.

It's just an inheritance matter (extend or override a profile, a configuration from an upper-level POM) so I think it should be possible with Maven 2.


Overriding configurations from a parent pom can be done by adding the combine.self="override" attribute to the element in your pom.

Try changing your plugin configuration to:

    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-compiler-plugin</artifactId>
      <executions>
        <execution>
          <id>my-testCompile</id>
          <phase>test-compile</phase>
          <goals>
            <goal>testCompile</goal>
          </goals>
          <configuration combine.self="override">
            <fork>true</fork>
            <executable>${jdk15.executable}</executable>
            <compilerVersion>1.5</compilerVersion>
            <source>1.5</source>
            <target>1.5</target>
            <verbose>true</verbose>
          </configuration>
        </execution>
      </executions>
    </plugin>

For more information on overriding plugins, see: http://maven.apache.org/pom.html


i had the same issue. By default my maven war plugin excluded a html file. But in my acceptance-tests profile i wanted this file included. So when i added in the maven war plugin again it did not override the default.

To resolve this issue i passed in the combine.self attribute and worked fine.

Default build:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-war-plugin</artifactId>
    <version>2.4</version>
    <configuration>
        <packagingExcludes>swagger-ui/client.html</packagingExcludes>
    </configuration>
</plugin>

Acceptance test profile:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-war-plugin</artifactId>
    <version>2.4</version>
    <configuration combine.self="override"/>
</plugin>

Did you try to deactivate the wls7 profile (since maven 2.0.10):

Starting with Maven 2.0.10, one or more profiles can be deactivated using the command line by prefixing their identifier with either the character '!' or '-' as shown below:

mvn groupId:artifactId:goal -P !profile-1,!profile-2

This can be used to deactivate profiles marked as activeByDefault or profiles that would otherwise be activated through their activation config.

And then add your configuration in a profile with a different name or directly in your pom.xml.

참고URL : https://stackoverflow.com/questions/1771561/is-it-possible-to-override-the-configuration-of-a-plugin-already-defined-for-a-p

반응형