【问题标题】:How to bind a plugin goal to another plugin goal如何将插件目标绑定到另一个插件目标
【发布时间】:2010-11-26 11:50:32
【问题描述】:

在我当前的项目中,我们使用了一些其他插件参数所需的插件,例如 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

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

$> mvn schemaspy:schemaspy

有没有一种干净的方法可以做到这一点(无需编写脚本)?

【问题讨论】:

    标签: maven-2 maven-plugin


    【解决方案1】:

    最简单的方法是将 schemaspy 目标绑定到生命周期阶段(特别是因为您已经为其他两个插件完成了此操作),因此您可以简单地运行类似 mvn package 并在适当的阶段执行所有三个插件。

    如果您希望 schmespy 插件仅在某些情况下执行,请将其放在配置文件中,然后运行 ​​mvn package -P schemaspy 以激活它。实现这一点的配置如下所示:

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

    【讨论】:

    • 从来没想过。我喜欢。谢谢。
    • 对不起,但这对我没有帮助。我们可以将一个目标绑定到另一个目标吗?我需要在发布分支的上下文中使用插件计算分支名称。要求开发人员启用配置文件并运行生命周期阶段以创建分支会很奇怪,而他们通常会简单地运行'release:branch'......
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-08-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-01-17
    • 1970-01-01
    相关资源
    最近更新 更多