How to run the plugin only for the type of "war" in Maven?

Two Maven projects are provided: J (jar), W (war); both depend on one parent P (pom). The parent has a plugin that should only run for the "W" project.

How to do it:

  • without creating separate parent projects
  • without using a profile (so assembly should be done with mvn clean package)

J (jar)

<project>
  <parent>
    <artifactId>P</artifactId>
  </parent>
  <artifactId>J</artifactId>
  <packaging>jar</packaging>
</project>

W (war)

<project>
  <parent>
    <artifactId>P</artifactId>
  </parent>
  <artifactId>W</artifactId>
  <packaging>war</packaging>
</project>

P (pom)

<project>
  <artifactId>P</artifactId>
  <packaging>pom</packaging>

  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-jar-plugin</artifactId>
        <executions>
          <execution>
            <phase>package</phase>
            <goals>
              <goal>jar</goal>
            </goals>
            <configuration>
              <classifier>classes</classifier>
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
</project>
+5
source share
3 answers

One way to do this is to place the plugin in the parent pom in the section <pluginManagement>. After that, specify the plugin in the project (s) that you want to run.

J, W.

  <build>
    ...
    <pluginManagement>
      <plugins>
        <plugin>
          <groupId>...</groupId>
          <artifactId>...</artifactId>
          ...  other plugin details ...
        </plugin>
      </plugins>
    </pluginManagement>
    ...
   </build>

J

  <build>
    ...
      <plugins>
        <plugin>
          <groupId>...</groupId>
          <artifactId>...</artifactId>
        <plugin>
      </plugins>
    ...
   </build>
0

: Maven , . , .

: (, pom , ) plugin config . , .

- maven-assembly-plugin jar . jar war, <pluginManagement>, , Raghuram. , , , .

0

, , . - " - ", , -, Maven. , , , : " src/main/webapp".

Here's what yours looks like pom.xml:

<profiles>
    <profile>
        <activation>
            <file>
                <exists>src/main/webapp</exists>
            </file>
        </activation>
        <build>
            [plugin configuration]
        </build>
    </profile>
</profiles>
0
source

All Articles