Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to bind a plugin goal to another plugin goal

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

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

like image 724
noirbizarre Avatar asked Sep 08 '09 12:09

noirbizarre


People also ask

What is pluginManagement in Maven?

From Maven documentation: pluginManagement: is an element that is seen along side plugins. Plugin Management contains plugin elements in much the same way, except that rather than configuring plugin information for this particular project build, it is intended to configure project builds that inherit from this one.

How do I run a Maven plugin goal?

From the main menu, select Run | Edit Configurations to open the run/debug configuration for your project. In the list that opens, select Run Maven Goal. In the Select Maven Goal dialog, specify a project and a goal that you want to execute before launching the project. Click OK.

What is the use of build tag in POM xml?

Plugins defined in your buildsection plugins tag will be executed during the build of your project. There are many plugins that do something with your build. For example the maven-compiler-plugin which allows you to set the Java version for your project.


1 Answers

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>
like image 171
Rich Seller Avatar answered Sep 21 '22 13:09

Rich Seller