如何将一个插件目标绑定到另一个插件目标

发布于 2024-08-03 17:40:38 字数 2801 浏览 3 评论 0原文

在我当前的项目中,我们使用其他插件参数所需的一些插件,例如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 命令需要执行属性插件和 buildNumber 插件,以便我们可以输入:

$> mvn schemaspy:schemaspy

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

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:

gt; mvn org.codehaus.mojo:properties-maven-plugin:read-project-properties schemaspy:schemaspy

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

gt; mvn schemaspy:schemaspy

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

南薇 2024-08-10 17:40:38

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

如果您希望 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>

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.

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>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文