0

I have a strange behavior when I user tomcat-plugin, in my parent project I declare the plugin configuration in the pluginmanagement.

I have 3 child war project, two of them declare the plugin and one did not declare the plugin.

For an unknown reason the plugin is execute in the first project but I don't understand why.

Here is a sample of my parent project.

<?xml version="1.0"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  <groupId>my.groupID</groupId>
  <artifactId>parent</artifactId>
  <packaging>pom</packaging>
  <version>1.0.0</version>
  <name>parent</name>

  <build>
    ...
    <pluginManagement>
      <plugins>
        <plugin>
          <groupId>org.apache.tomcat.maven</groupId>
          <artifactId>tomcat7-maven-plugin</artifactId>
          <version>2.2</version>
          <configuration>
            <server>local</server>
            <update>true</update>
            <charset>UTF-8</charset>                
          </configuration>
        </plugin>
      </plugins>
    </pluginManagement>
  </build>
</project>

Here is the sample of the child1 (the plugin isn't declare):

<?xml version="1.0"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <parent>
    <artifactId>parentProject</artifactId>
    <groupId>my.groupID</groupId>
    <version>1.0.0</version>
  </parent>

  <groupId>my.groupID</groupId>
  <artifactId>child1</artifactId>
  <packaging>war</packaging>

  <build>
    ...
  </build>
</project>

Here is the sample of the child2 (the plugin is declare)

<?xml version="1.0"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <parent>
    <artifactId>parentProject</artifactId>
    <groupId>my.groupID</groupId>
    <version>1.0.0</version>
  </parent>

  <groupId>my.groupID</groupId>
  <artifactId>child2</artifactId>
  <packaging>war</packaging>

  <properties>
    <urlTomcat>http://localhost:8080/</urlTomcat>
    <pathApp>child2</pathApp>
  </properties>

  <profiles>
    <profile>
      <id>deploy-child2</id>
      <activation>
        <activeByDefault>false</activeByDefault>
      </activation>
      <build>
        <plugins>
          <plugin>
            <groupId>org.apache.tomcat.maven</groupId>
            <artifactId>tomcat7-maven-plugin</artifactId>
            <configuration>
              <url>${urlTomcat}manager/text</url>
              <path>/${pathApp}</path>
            </configuration>
          </plugin>
        </plugins>
      </build>
    </profile>
  </profiles>

  <dependencies>
    <dependency>
      <groupId>my.groupID</groupId>
      <artifactId>child1</artifactId>
      <type>war</type>
    </dependency>
  </dependencies>

  <build>
    ...
  </build>
</project>

Here is the sample of the child3 (the plugin is declare)

    <?xml version="1.0"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <parent>
    <artifactId>parentProject</artifactId>
    <groupId>my.groupID</groupId>
    <version>1.0.0</version>
  </parent>

  <groupId>my.groupID</groupId>
  <artifactId>child3</artifactId>
  <packaging>war</packaging>

  <properties>
    <urlTomcat>http://localhost:8080/</urlTomcat>
    <pathApp>child3</pathApp>
  </properties>

  <profiles>
    <profile>
      <id>deploy-child3</id>
      <activation>
        <activeByDefault>false</activeByDefault>
      </activation>
      <build>
        <plugins>
          <plugin>
            <groupId>org.apache.tomcat.maven</groupId>
            <artifactId>tomcat7-maven-plugin</artifactId>
            <configuration>
              <url>${urlTomcat}manager/text</url>
              <path>/${pathApp}</path>
            </configuration>
          </plugin>
        </plugins>
      </build>
    </profile>
  </profiles>

  <dependencies>
    <dependency>
      <groupId>my.groupID</groupId>
      <artifactId>child1</artifactId>
      <type>war</type>
    </dependency>
  </dependencies>

  <build>
    ...
  </build>
</project>

When I ran this command :

mvn tomcat7:deploy -Pdeploy-child2 or mvn tomcat7:deploy -Pdeploy-child3

My problem is that maven try to deploy the child1 project and I don't want it. I expect that the child1 will be build but not deploy because it doesn't declare the plugin.

alecas
  • 1
  • 1
  • First if you call `mvn tomcat7:deploy` you don't call a life-cycle you call a goal of a plugin in this case the deploy goal of maven-tomcat7-plugin. Furthermore if you like to activate a profile you should do that by using `mvn -Pdeploy-child2 ...` and **not** by `mvn -Ddeploy-child2 ...` which can't work. I would suggest to go to the root level of your project and try `mvn -Pdeploy-child2 deploy` which will not realls work, cause tomcat7-maven-plugin forks the life-cycle with the goal `deploy`. There is an other goal `deploy-only` which can be bound to the life-cycle. – khmarbaise May 13 '14 at 17:22
  • ok your right about the -D its my bad when writing the post. I use the -P for selecting the profile. I correct it. – alecas May 13 '14 at 18:30
  • Can you try compile to the child 1 war dependency – Poorna Subhash May 14 '14 at 00:50

1 Answers1

0

This plugin even though mentioned in pluginManagement, will be inherited by child modules even if it is not included in child poms. To know why they are included, please check this link. The deploy goal is a lifecycle goal for war packages.

In parent pom, include following, then it'll not be included in the childs in which it is not defined.

    <configuration>
          <skip>true</skip>
   </configuration>
Community
  • 1
  • 1
Poorna Subhash
  • 2,078
  • 2
  • 21
  • 28
  • the skip don't seem to be manage in that case. I also try to put it to true in the child1 project but it didn't work. – alecas May 13 '14 at 18:30