【发布时间】:2014-07-01 09:36:05
【问题描述】:
当我使用 tomcat-plugin 时,我有一个奇怪的行为,在我的父项目中,我在插件管理中声明了插件配置。
我有 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 将被构建但不会部署,因为它没有声明插件。
【问题讨论】:
-
首先,如果您调用
mvn tomcat7:deploy,您不会调用生命周期,而是调用插件的目标,在这种情况下称为 maven-tomcat7-plugin 的部署目标。此外,如果您想激活配置文件,您应该使用mvn -Pdeploy-child2 ...和 not bymvn -Ddeploy-child2 ...来执行此操作,这是行不通的。我建议转到您项目的根级别并尝试mvn -Pdeploy-child2 deploy,这将无法正常工作,因为tomcat7-maven-plugin 以deploy为目标分叉了生命周期。还有一个目标deploy-only可以绑定到生命周期。 -
好吧,在写这篇文章时,我对 -D 的看法是正确的。我使用 -P 来选择配置文件。我纠正它。
-
你可以尝试
编译 到子1战争依赖