[英]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.