2009-09-08 35 views
8

在我當前的項目中,我們使用了其他插件參數(如properties-maven-plugin或buildnumber-plugin)所需的一些插件。如何將插件目標綁定到其他插件目標

<?xml version="1.0"?> 
<project> 
    <modelVersion>4.0.0</modelVersion> 
    <groupId>mygroup</groupId> 
    <artifactId>myartifact</artifactId> 
    <packaging>pom</packaging> 
    <version>v0</version> 
    <name>myProject</name> 

    <properties> 
      <env>dev</env> 
    </properties> 

    <build> 
     <plugins> 
     <plugin> 
      <groupId>org.codehaus.mojo</groupId> 
      <artifactId>properties-maven-plugin</artifactId> 
      <version>1.0-alpha-2</version> 
      <configuration> 
      <files> 
       <file>${basedir}/configurations/${env}.properties</file> 
      </files> 
      </configuration> 
      <executions> 
       <execution> 
        <phase>initialize</phase> 
        <goals> 
         <goal>read-project-properties</goal> 
        </goals> 
       </execution> 
      </executions> 
     </plugin> 

     <plugin> 
      <groupId>org.codehaus.mojo</groupId> 
      <artifactId>buildnumber-maven-plugin</artifactId> 
      <version>1.0-beta-3</version> 
      <executions> 
       <execution> 
        <phase>initialize</phase> 
        <goals> 
         <goal>create</goal> 
        </goals> 
       </execution> 
      </executions> 
     </plugin> 

     <plugin> 
      <groupId>com.wakaleo.schemaspy</groupId> 
      <artifactId>maven-schemaspy-plugin</artifactId> 
      <version>1.0</version> 
      <configuration> 
       <databaseType>mysql</databaseType> 
       <database>${database.schema}</database> 
       <host>${database.host}</host> 
       <user>${database.user}</user> 
       <password>${database.pwd}</password> 
       </configuration> 
     </plugin> 
    </plugins> 
    </build> 
</project> 

問題是,當您直接執行插件目標時,綁定在初始化階段(或驗證)的目標不會執行。所以產生模式間諜,我們需要輸入:

$> mvn org.codehaus.mojo:properties-maven-plugin:read-project-properties schemaspy:schemaspy 

我們想告訴大家,性能插件和buildNumber插件需要爲每個行家要執行的命令,所以我們可以輸入:

$> mvn schemaspy:schemaspy 

是否有乾淨的方式來做到這一點(無腳本)?

回答

6

最簡單的方法是將綁定schemaspy目標的生命週期階段(尤其當你已經做到了這一點ffor其他兩個插件),這樣的話,你可以簡單地運行像MVN包,並擁有所有三個插件在適當的階段執行。

如果您希望schmespy插件僅在特定情況下執行,請將其放入配置文件中,然後運行mvn軟件包-P模式以激活它。實現此目的的配置如下所示:

<profiles> 
    <profile> 
    <id>schemaspy</id> 
    <plugin> 
     <groupId>com.wakaleo.schemaspy</groupId> 
     <artifactId>maven-schemaspy-plugin</artifactId> 
     <version>1.0</version> 
     <executions> 
     <execution> 
      <phase>package</phase> 
      <goals> 
      <goal>schemaspy</goal> 
      </goals> 
     </execution> 
     </executions> 
     <configuration> 
     <databaseType>mysql</databaseType> 
     <database>${database.schema}</database> 
     <host>${database.host}</host> 
     <user>${database.user}</user> 
     <password>${database.pwd}</password> 
     </configuration> 
    </plugin> 
    </profile> 
</profile> 
+0

從未考慮過它。我喜歡。 謝謝。 – noirbizarre 2009-09-08 14:19:47

+3

對不起,但這不幫助我。我們可以將目標綁定到另一個目標嗎?我需要在分支發佈的上下文中使用插件來計算分支名稱。要開發人員啓用一個配置文件並運行一個生命週期階段來創建一個分支,當他們通常簡單地運行'release:branch'時,會很奇怪...... – 2013-04-28 14:39:24