简体   繁体   English

带有多个模块的tomcat-maven-plugin和pluginManagement

[英]tomcat-maven-plugin and pluginManagement with multiple module

I have a strange behavior when I user tomcat-plugin, in my parent project I declare the plugin configuration in the pluginmanagement. 当我使用tomcat-plugin时,我有一个奇怪的行为,在我的父项目中,我在pluginmanagement中声明了插件配置。

I have 3 child war project, two of them declare the plugin and one did not declare the plugin. 我有3个子战项目,其中两个声明了插件,一个没有声明插件。

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): 这是child1的示例(未声明插件):

<?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) 这是child2的示例(插件已声明)

<?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) 这是child3的示例(插件已声明)

    <?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 mvn tomcat7:deploy -Pdeploy-child2或mvn tomcat7:deploy -Pdeploy-child3

My problem is that maven try to deploy the child1 project and I don't want it. 我的问题是,maven尝试部署child1项目,但我不想要它。 I expect that the child1 will be build but not deploy because it doesn't declare the plugin. 我希望child1将被构建但不会部署,因为它未声明插件。

This plugin even though mentioned in pluginManagement, will be inherited by child modules even if it is not included in child poms. 即使在pluginManagement中提到了此插件,即使子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. 在父pom中,包括以下内容,那么它将不会包含在未定义它的子项中。

    <configuration>
          <skip>true</skip>
   </configuration>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 带有多个模块的tomcat-maven-plugin,仅可构建一次战争 - tomcat-maven-plugin with multiple modules building one war only 将我的javaagent传递给tomcat-maven-plugin而不是Tomcat服务器 - pass my javaagent to tomcat-maven-plugin NOT Tomcat Server Maven:在哪里为tomcat-maven-plugin添加生成的资源? - Maven: Where to put generated resources for tomcat-maven-plugin? Maven无法下载tomcat-maven-plugin快照 - Maven is failing to download the tomcat-maven-plugin snapshot tomcat-maven-plugin 401。 显示不同的端口号时出错 - tomcat-maven-plugin 401 . Error showing different port number 为什么tomcat-maven-plugin尝试部署到错误的URL? - Why is tomcat-maven-plugin trying to deploy to the wrong URL? tomcat-maven-plugin 抛出 java.lang.ClassNotFoundException: - tomcat-maven-plugin throws java.lang.ClassNotFoundException: 尝试使用 tomcat-maven-plugin 部署 maven 项目时出现错误 403 - Error 403 when try to deploy a maven project with tomcat-maven-plugin Maven:org.codehaus.mojo:tomcat-maven-plugin:jar:2.2的POM在哪里? - Maven: where is the POM for org.codehaus.mojo:tomcat-maven-plugin:jar:2.2? GWT 项目中的 tomcat-maven-plugin。 org.codehaus.mojo 和 org.apache.tomcat.maven 插件有什么区别 - tomcat-maven-plugin in GWT project. What is the difference between: org.codehaus.mojo and org.apache.tomcat.maven plugin
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM