如何将一个插件目标绑定到另一个插件目标 [英] How to bind a plugin goal to another plugin goal

查看:118
本文介绍了如何将一个插件目标绑定到另一个插件目标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我当前的项目中,我们使用了其他插件参数所需的一些插件,例如properties-maven-plugin或buildnumber-plugin.

In my current project we use some plugins needed by other plugins parameters like properties-maven-plugin or 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>

问题在于,当您直接执行插件目标时,绑定阶段不会在初始化阶段(或验证)上执行.因此,要生成模式间谍,我们需要输入:

The problem is that when you execute directly a plugin goal, goals binded on the initialize phase (or validate) are not executed. So to generate schema spy we need to type:

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

我们想告诉我们,每个maven命令都需要执行属性插件和buildNumber插件,因此我们可以输入:

We want to tell that properties plugin and buildNumber plugin need to be executed for every maven command so we can type:

$> mvn schemaspy:schemaspy

是否有一种干净的方法(无需编写脚本)?

Is there a clean way to do that (without scripting) ?

推荐答案

最简单的方法是将schemaspy目标绑定到生命周期阶段(特别是因为您已经为其他两个插件完成了此工作),然后您只需运行 mvn软件包之类的东西,并在适当的阶段执行所有三个插件.

The simplest way would be to bind the schemaspy goal to a lifecycle phase (particularly as you have already done this ffor the other two plugins), so then you can simply run something like mvn package and have all three plugins executed in the appropriate phases.

如果您只希望在特定情况下执行schmespy插件,请将其放在配置文件中,然后运行 mvn软件包-P schemaspy 激活它.实现此目的的配置如下所示:

If you want the schmespy plugin to only be executed under certain circumstances, put it in a profile, then run mvn package -P schemaspy to activate it. The configuration to achieve this looks like this:

<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>

这篇关于如何将一个插件目标绑定到另一个插件目标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆