Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run a plugin only for "war" package type in Maven?

Provided two Maven projects: J (jar), W (war); both depend on one parent P (pom). The parent has a plugin, which must only run for the project "W".

How does one go about doing this:

  • without creating separate parent projects
  • without using a profile (so build must still be executed 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>
like image 898
Yuriy Nemtsov Avatar asked Oct 28 '11 20:10

Yuriy Nemtsov


1 Answers

I think you can achieve this using Profile Activation. Ideally, the activation condition would be something like "packaging type is war", but apparently, this condition cannot be implemented in Maven. However, in your case, there is a condition that can be implemented and that is probably equivalent in practice: "there is a src/main/webapp directory".

This is how your pom.xml might look like:

<profiles>
    <profile>
        <activation>
            <file>
                <exists>src/main/webapp</exists>
            </file>
        </activation>
        <build>
            [plugin configuration]
        </build>
    </profile>
</profiles>
like image 157
rolve Avatar answered Oct 01 '22 13:10

rolve