Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
rhoehener opened this issue Jul 30, 2024 · 8 comments

Comments

@rhoehener
Copy link

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

@rhoehener rhoehener 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? Jul 30, 2024
@laeubi
Copy link
Member

laeubi commented Jul 30, 2024

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.

@rhoehener
Copy link
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.

@rhoehener
Copy link
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...

@rhoehener
Copy link
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?

@laeubi
Copy link
Member

laeubi commented Jul 30, 2024

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?

@rhoehener
Copy link
Author

rhoehener commented Jul 30, 2024

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

@laeubi
Copy link
Member

laeubi commented Jul 30, 2024

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.

@eclipse-m2e eclipse-m2e locked and limited conversation to collaborators Jul 30, 2024
@laeubi laeubi converted this issue into discussion #1794 Jul 30, 2024

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants