2009-09-08 34 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