3

I have implemented a Maven 2 plugin.

I have that definiton for my Mojo:

/**
 * Goal which combines files.
 *
 * @goal combine
 * @phase compile
 */
public class CombineMojo extends AbstractMojo {

I have to add this into my project (which uses plugin) pom:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>base-project</groupId>
    <artifactId>base-project</artifactId>
    <version>1.0-SNAPSHOT</version>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>combine-maven-plugin</artifactId>
                <version>1.0-SNAPSHOT</version>
                <configuration>
                    <input>src/input.html</input>
                    <output>html/output.html</output>
                </configuration>
                <executions>
                    <execution>
                        <id>combine-maven-plugin</id>
                        <goals>
                            <goal>combine</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

However what should I do automatically execute it instead of defining at pom.xml. I tries adding

@execute ...

into my Mojo definition however it didn't work. By the way should I define an id, what is need for it?

kamaci
  • 72,915
  • 69
  • 228
  • 366
  • 1
    Can you show the complete pom file of your test project? Furthermore a plugin can not be executed automatically it must be bound to a life-cycle-phase. – khmarbaise Dec 31 '12 at 11:50
  • Do you get any error/message during the execution of your test project ? – khmarbaise Dec 31 '12 at 12:01
  • @khmarbaise A plugin **can** be executed automatically, but only specific ones defined for specific packaging types: https://stackoverflow.com/a/57061848/1548776 – ᴠɪɴᴄᴇɴᴛ Jul 16 '19 at 16:48

1 Answers1

0

A maven plugin can only be executed if it's bound a life-cycle phase in Maven.

khmarbaise
  • 92,914
  • 28
  • 189
  • 235
  • 1
    A plugin **can** be executed automatically, but only specific ones defined for specific packaging types: https://stackoverflow.com/a/57061848/1548776 (so not possible for custom plugins [except for custom packaging types]). – ᴠɪɴᴄᴇɴᴛ Jul 16 '19 at 16:50