What is the syntax to run a maven plugin from the command line.

6.8k views Asked by At

I see that this has already been asked over here: How to execute maven plugin from command line? but I don't really understand the answer. It looks like the syntax is of the form:

mvn foo:bar

But I'm not really sure what foo and bar are supposed to be.

Specifically I have configured the maven-resource-plugin like this:

<plugin>
    <artifactId>maven-resources-plugin</artifactId>
    <version>2.5</version>
    <executions>
        <execution>
            <id>copy-resources</id>
            <phase>prepare-package</phase>
            <goals>
                <goal>copy-resources</goal>
            </goals>
            <configuration>
                <!--configuration here-->
            </configuration>
        </execution>
    </executions>
</plugin>

I've tried several permutations of mvn artifactId|id|phase|goal:artifactidId|id|phase|goal but none of them are working. I figured i'd stop trying to brute-force it and just ask the internet. Also, is this documented anywhere?

2

There are 2 answers

0
Robert Scholte On BEST ANSWER

There are 3 patterns:

groupId:artifactId:version:goal
groupId:artifactId:goal
prefix:goal

If you run this from a location with a pom.xml and you haven't specified the version, Maven will search for a matching plugin in the build-section. The prefix can often (not always) be recognized as part of the artifactId, e.g. maven-help-plugin has the prefix help. The plugin documentation should give you the exact prefix.

0
M A On

You would call this plugin goal as follows:

mvn resources:copy-resources

where copy-resources is the plugin goal that you configured in the POM, and resources is prefix of the maven-resources-plugin (see this link for plugin prefix resolution).