Skip to content

[question] why are some plugins bound to the package phase executed by eclipse lifecycle mapping by default and others not? #1792

Closed

Description

@reto-hoehener

In Eclipse 2024-06, new workspace, when I create a simple maven project with 2 plugins bound to the package phase, one is ignored and one is executed.

I thought Eclipse only considers phases up to and including compile as 'interesting', but I couldn't find any documentation about this, only hints here: https://eclipse.dev/m2e/documentation/m2e-execution-not-covered.html

I had a look inside the maven-dependency-plugin jar but did not observe any META-INF/m2e lifecycle mapping that could explain the execution. I clearly observe the junit dependency being copied to target/dependency by the Eclipse workspace build (no manual maven execution).

Is the maven-dependency-plugin treated special by m2e?

<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>test</groupId>
  <artifactId>test</artifactId>
  <version>1.0.0</version>
  <packaging>jar</packaging>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>

  <build>
    <plugins>
      <plugin>

        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-antrun-plugin</artifactId>
        <version>3.1.0</version>
        <executions>
          <execution>
            <id>id</id>
            <phase>package</phase>
            <goals>
              <goal>run</goal>
            </goals>
            <configuration>
              <target>
                <echo>Hello world!</echo>
              </target>
            </configuration>
          </execution>
        </executions>
      </plugin>

      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-dependency-plugin</artifactId>
        <version>3.7.1</version>
        <executions>
          <execution>
            <id>id</id>
            <phase>package</phase>
            <goals>
              <goal>copy</goal>
            </goals>
          </execution>
        </executions>
        <configuration>
          <artifactItems>
            <artifact>
              <groupId>junit</groupId>
              <artifactId>junit</artifactId>
              <version>4.11</version>
            </artifact>
          </artifactItems>
        </configuration>
      </plugin>

    </plugins>
  </build>
</project>

image

Activity

  1. changed the title [-][question] why are some plugins in the package phase executed by eclipse lifecycle mapping by default and others not?[/-] [+][question] why are some plugins bound to the package phase executed by eclipse lifecycle mapping by default and others not?[/+] on Jul 30, 2024
  2. laeubi commented on Jul 30, 2024

    @laeubi
    Member

    In your screenshot you can see that the antrun plugin is ignored (I assume it has a mapping for that), the dependency plugin is executed because mojos are executed by default if not otherwise specified.

  3. reto-hoehener commented on Jul 30, 2024

    @reto-hoehener
    Author

    @laeubi are you sure? that is the core of my question: I thought only plugins bound to "interesting phases" (i.e. up to compile) are executed by eclipse? at least that's what is written in the linked page.

  4. reto-hoehener commented on Jul 30, 2024

    @reto-hoehener
    Author

    Thanks for that pointer, that's good to know. So the package phase is an "interesting" phase for m2e? I mean, plugins bound to test/install/deploy are surely never executed by m2e, right?

    I will check the maven-antrun-plugin...

  5. reto-hoehener commented on Jul 30, 2024

    @reto-hoehener
    Author

    In your screenshot you can see that the antrun plugin is ignored (I assume it has a mapping for that), the dependency plugin is executed because mojos are executed by default if not otherwise specified.

    I checked the plugin jar and don't see a META-INF/m2e folder. Are there other ways to specify m2e mappings that I can check?

  6. laeubi commented on Jul 30, 2024

    @laeubi
    Member

    m2e ship with some default mappings ifecycle-mapping-metadata.xml and as far as I know every phase can be interesting. The question is more do you want the antrun to execute (than you can enable it e.g with processing instructions (I can't find the n&n at the moment maybe @HannesWell knows them?) or if you like to disable the maven-dependency-plugin?

  7. reto-hoehener commented on Jul 30, 2024

    @reto-hoehener
    Author

    I am mainly trying to update my mental model of how m2e is supposed to work with relation to the package phase: I was surprised by the maven-dependency-plugin being executed, because I thought m2e would never automatically execute plugins bound to the package phase. Now you pointed me to the release notes that say that m2e executes all plugins by default, which I think is not the case at least for the test/install/deploy-phases. I believe my custom plugins bound to the package phase are also not executed by default but I have to recheck those.

    I tried to click on "Open workspace lifecycle mappings metadata" but got an error message and an empty editor. Edit: Now it works (but this mapping is empty).

    image

  8. laeubi commented on Jul 30, 2024

    @laeubi
    Member

    Yes it is not always easy when it comes to mappings, but you can open the LifeCycle Mappings as a view to at least get the info what is executed.

    In this particular case I think the reason is that m2e has a default mapping for maven-dependency-plugin here that is used when nothing else is configured.

    So even if the package-phase is "uninteresting" by default, if there is a mapping (either implicit or explicit) m2e can execute mojos in such a phase.

    So here we have:

    1. maven-antrun-plugin:run has no explicit or implicit binding and package phase is uninteresting -> ignored
    2. maven-dependency-plugin:copy-dependency has implicit default binding -> execute regardless of phase.
  9. locked and limited conversation to collaborators on Jul 30, 2024
  10. converted this issue into a discussion #1794 on Jul 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions