当我使用tomcat-plugin时,我有一个奇怪的行为,在我的父项目中,我在pluginmanagement中声明了插件配置。
我有3个子战争项目,其中两个声明了插件,一个没有声明插件。
由于未知原因,插件在第一个项目中执行,但我不明白为什么。
以下是我父项目的示例。
<?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>
以下是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>
这是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>
以下是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>
当我运行此命令时:
mvn tomcat7:deploy -Pdeploy-child2或mvn tomcat7:deploy -Pdeploy-child3
我的问题是maven尝试部署child1项目而我不想要它。我希望child1将被构建但不会部署,因为它没有声明插件。
答案 0 :(得分:0)
这个插件即使在pluginManagement中提到过,也会被子模块继承,即使它不包含在子poms中。要了解其中包含的原因,请查看link。部署目标是战争包的生命周期目标。
在父pom中,包含以下内容,然后它不会包含在未定义它的子项中。
<configuration>
<skip>true</skip>
</configuration>