0

I am working on integrating a plugin into a multi-module project.

I am using a 3rd party plugin that essentially needs to only by run from the parent project (based on my understanding and usage of it). I tried to accomplish this by using a profile, like so:

<profiles>
    <profile>
        <id>run-my-guy</id>
        <build>
            <plugins>
                <plugin>
                    <groupId>com.myproject</groupId>
                    <artifactId>myproject-maven-plugin</artifactId>
                    <executions>
                        <execution>
                            <phase>package</phase>
                            <goals>
                                <goal>runThing</goal>
                            </goals>
                            <inherited>false</inherited>
                        </execution>
                    </executions>
                    <inherited>false</inherited>
                </plugin>
            </plugins>
        </build>
    </profile>
</profiles>

I have several <inherited>false</inherited>, but if I run mvn help:all-profiles I can still see this profile in every single module. If I run my mvn package -P run-my-guy I see this get executed in every single subproject. I want the ability to activate this and I do not want it to be on by default.

If I try to add it the <build> section, like this:

<build>
  <plugins>
    <plugin>
      <groupId>com.myproject</groupId>
      <artifactId>myproject-maven-plugin</artifactId>
      <inherited>false</inherited>
      <executions>
        <execution>
          <phase>package</phase>
          <goals>
            <goal>runThing</goal>
          </goals>
        </execution>
      </executions>
    </plugin>
  </plugins>
</build>

Here, I also have a few <inherited>false</inherited>, just to try and enforce that the plugin and the execution are not inherited. However, whenI run the package phase, or anything that includes that phase, the runThing goal is included.

How do I run a goal only by activation (like profile or some other feature, or just by explicitly running the goal) and only in the parent?

mkobit
  • 43,979
  • 12
  • 156
  • 150

1 Answers1

1

As shown in an answer for "Run a single Maven plugin execution?", it is now possible (since Maven 3.3.1) to specify an execution Id for a direct goal invocation.

pom.xml

<build>
  <plugins>
    <plugin>
      <groupId>com.myproject</groupId>
      <artifactId>myproject-maven-plugin</artifactId>
      <inherited>false</inherited>
      <executions>
        <id>myproject-exec-id</id>    <!-- note the execution Id -->
        <execution>
          <phase>none</phase>
          <goals>
            <goal>runThing</goal>
          </goals>
        </execution>
      </executions>
    </plugin>
  </plugins>
</build>

And then invoking the goal from the command line uses the optional @executionId parameter:

mvn myproject:runThing@myproject-exec-id
Community
  • 1
  • 1
mkobit
  • 43,979
  • 12
  • 156
  • 150