当我使用 tomcat-plugin 时,我有一个奇怪的行为,在我的父项目中,我在插件管理中声明了插件配置。
我有 3 个子 war 项目,其中两个声明了插件,一个没有声明插件。
由于未知原因,插件在第一个项目中执行,但我不明白为什么。
这是我的父项目的示例。
<?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 or mvn tomcat7:deploy -Pdeploy-child3
我的问题是 maven 尝试部署 child1 项目,但我不想要它。我希望 child1 将被构建但不会部署,因为它没有声明插件。
最佳答案
这个插件即使在 pluginManagement 中提到,也会被子模块继承,即使它没有包含在子 pom 中。要了解为什么包含它们,请查看此 link . deploy 目标是 war 包的生命周期目标。
在父pom中,包含following,那么它不会包含在没有定义它的childs中。
<configuration>
<skip>true</skip>
</configuration>
关于java - 具有多个模块的 tomcat-maven-plugin 和 pluginManagement,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23635874/