2014-05-13 24 views
0

我有一個奇怪的行爲,當我的用戶tomcat插件,在我的父項目我聲明pluginmanagement插件配置。tomcat-maven-plugin和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:部署-Pdeploy-的child2或MVN tomcat7:部署-Pdeploy-child3

我的問題是行家嘗試部署的child1項目,我不想要它。我期望child1將被構建,但不會被部署,因爲它沒有聲明該插件。

+0

首先,如果你調用'MVN tomcat7:deploy'你不叫生命週期調用插件的目標,在這種情況下的maven-tomcat7-插件的部署目標。此外,如果你想激活一個配置文件,你應該通過使用'mvn -Pdeploy-child2 ...'和** not **來執行'mvn -Ddeploy-child2 ...',它無法工作。我會建議去你的項目的根級,並嘗試'mvn -Pdeploy-child2 deploy',它不會重新工作,導致tomcat7-maven-plugin在目標'deploy'中生命週期。還有一個目標是「僅限部署」,可以與生命週期綁定。 – khmarbaise

+0

確定你的權利,關於-D我寫這篇文章時我的不好。我使用-P選擇配置文件。我糾正它。 – alecas

+0

你可以試試編輯給孩子1戰爭依賴 – Poorna

回答

0

即使在pluginManagement中提到這個插件,即使未包含在子poms中,子插件也會繼承該插件。要知道它們包含的原因,請檢查link。部署目標是戰爭包的生命週期目標。

在父pom中,包含以下內容,那麼它將不會包含在未定義的子項中。

<configuration> 
      <skip>true</skip> 
    </configuration> 
+0

跳過似乎不是在這種情況下管理。我也嘗試在child1項目中將其設置爲true,但它不起作用。 – alecas