1

The Eclipse IDE requires the snippet below in the <pluginManagement> (details don't matter).

Is there a way to import such a Maven fragment from another file? Does Maven have any macro/import/snippet/sub-pob support?

I would like to obtain this:

</pluginManagement>
    <plugins>
        ...
        <!-- import some plugin configurations from another file -->
        <import from="another/file.pom.or.xml" />
    </plugins>
</pluginManagement>

and another/file.pom.or.xml has the corresponding <plugin> definitions/configurations:

<plugin>
    ...
<plugin>

or

<plugins>
    <plugin>
        ...
    <plugin>
<plugins>

or whatever other form of file-based Maven pom import mechanism.

Details:

This is the snippet I would like to move out of the main Maven pom file:

<!--
    This is in order to please the Eclipse m2e plugin:
    https://stackoverflow.com/questions/7638562/import-maven-project-to-eclipse-and-fix-the-errors/8103824#8103824
    Eclipse m2e complains that:
    "Plugin execution not covered by lifecycle configuration: org.apache.maven.plugins:maven-antrun-plugin:1.8:run (execution: default, phase: process-resources)"
    Adapter the SO answer with the correct artifactId, versionRange and goals reported by the error.
-->
<plugin>
    <groupId>org.eclipse.m2e</groupId>
    <artifactId>lifecycle-mapping</artifactId>
    <version>1.0.0</version>
    <configuration>
        <lifecycleMappingMetadata>
            <pluginExecutions>
                <pluginExecution>
                    <pluginExecutionFilter>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-antrun-plugin</artifactId>
                        <versionRange>[1.8,)</versionRange>
                        <goals>
                            <goal>run</goal>
                        </goals>
                    </pluginExecutionFilter>
                    <action>
                        <ignore />
                    </action>
                </pluginExecution>
            </pluginExecutions>
        </lifecycleMappingMetadata>
    </configuration>
</plugin>

The reason is a religious one: InteliJ IDEA developers are fighting with the Eclipse IDE developers and don't accept an Eclipse-specific configuration to land in the code. Without that configuration, the Eclipse m2e would complain (and this is the single solution I found to fix that m2e error)

Gabriel Petrovay
  • 20,476
  • 22
  • 97
  • 168

1 Answers1

2

No, this is not possible. There were discussions about "mixins", but this not a feature at present or the foreseeable future.

We moved all plugin configuration to the company parent POM, so it remains more or less invisible to the mortal developer.

Furthermore, notice that modern m2e versions support tags like <?m2e ignore?> in the POM that allow for smoother configuration.

J Fabian Meier
  • 33,516
  • 10
  • 64
  • 142