Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to rename goals in Maven?

In the Maven document Introduction to the Build Lifecycle, a goal of display:time is described that outputs the current time. The plugin is as follows:

...
<plugin>
  <groupId>com.mycompany.example</groupId>
  <artifactId>maven-touch-plugin</artifactId>
  <version>1.0</version>
  <executions>
    <execution>
      <phase>process-test-resources</phase>
      <goals>
        <goal>timestamp</goal>
      </goals>
    </execution>
  </executions>
</plugin>
...

I have several questions relating to this plugin:

  1. How can I change the name of the goal to, for example, foo:bar? (Why does neither display nor time appear anywhere in the XML fragment? How can you tell, from looking at the fragment, what goals it defines?)

  2. How can I manually run this goal? (For similar constructs, the equivalent of mvn display:time sometimes works, but this doesn't work consistently.)

  3. How can I see if this goal exists? (i.e. list available goals; this question suggests this is impossible.)

like image 748
mjs Avatar asked Apr 29 '10 10:04

mjs


People also ask

How do you rename a Maven file?

Using the Copy Rename Maven Plugin The copy-rename-maven-plugin helps copying files or renaming files/directories during the Maven build lifecycle. Upon building the project, we'll see foo. txt in the target/destination-folder.

How do I set goals in Maven?

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 are the goals of Maven?

A Maven plugin is a group of goals; however, these goals aren't necessarily all bound to the same phase. As we can see, the Failsafe plugin has two main goals configured here: integration-test: run integration tests. verify: verify all integration tests passed.


2 Answers

To your first one. The name of the goal is defined by the plugin (there is an annotation for that). If have the source code you change that. Taking a look at the XML you can't know what kind of goals a plugin defines only the ones which are given in the XML. The best location is to look at the documentation of the plugin. Second one: You have to check the docs. Usually pluginname:goal ...May be you have to specify the full path of the plugin (groupId). To the third: Usually should be able to use the help plugin take a look at the docs.

like image 87
khmarbaise Avatar answered Sep 24 '22 00:09

khmarbaise


How can I change the name of the goal to, for example, foo:bar? (Why does neither display nor time appear anywhere in the XML fragment? How can you tell, from looking at the fragment, what goals it defines?)

To change the name of the prefix to "foo" you need to configure the maven plugin "plugin".

    <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-plugin-plugin</artifactId>
    <version>2.5.1</version>
    <configuration>
        <goalPrefix>foo</goalPrefix>
    </configuration>
    </plugin>

To change the name of the goal, you need to edit the javadoc within the plugin java source

/**
 * Prints a timestamp to console
 *
 * @goal bar
 */
public class TimestampMojo extends AbstractMojo {
  // ...
}

Add the plugin prefix to your settings.xml file

<pluginGroups>
  <pluginGroup>com.mycompany.example</pluginGroup>
</pluginGroups>

How can I manually run this goal?

mvn com.mycompany.example:foo:bar

or with plugin prefix setting (above)

mvn foo:bar

How can I see if this goal exists? (i.e. list available goals)

Add the following to the maven plugin plugin element and you can use foo:help to print out the list of goals.

<plugin>
...
<executions>
<execution>
<id>generated-helpmojo</id>
<goals>
<goal>helpmojo</goal>
</goals>
</execution>
</executions>
</plugin>
like image 42
dcompiled Avatar answered Sep 23 '22 00:09

dcompiled