Search code examples
javamavenmaven-3maven-pluginmaven-assembly-plugin

Create a jar artifact with minimal pom / parent pom.xml / flattened / regenerated pom [maven]


I have a multimodule maven project and distribute the resulting jar file to different parties. Part of the jar file is the pom.xml file (in META-INF/maven/.../pom.xml).

The problem with that is, that the parent pom.xml is missing which contains a complete list of the dependencies and the necessary dependency-versions etc. So I tried several things:

Solution 1 I added the effective pom to the jar file
Problem the pom file is way too big, with too much information (partly internal, local etc)
Solution 2 I combined two plugins and managed to additionally add the parent pom.xml file to the jar.
Problem This is way better than S1 however the parent pom again contains a (grand)parent and also tags like <scm> which are internal and could & should not be handed to the outside world

Now I wanted to start to manipulate the parent pom and remove some parts etc. However there must be a better solution and others who have the same problem?

What I need is (e.g) a plugin which creates a clean "releasable" pom.xml file with only the dependencies (and of course artifact, groupid, version) and can then be imported by external parties into their repo without any conflicts. Is that possible?

The only thing remotely related is the eclipse tycho pom generator plugin. It is however eclipse specific...


Solution

  • The flatten-maven-plugin is exactly what I needed! Thanks to khmarbaise I use the following configuration and the pom is looking beautiful :-)

              <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>flatten-maven-plugin</artifactId>
                <version>1.2.2</version>
                <configuration>
                    <pomElements>
                        <repositories>flatten</repositories>
                    </pomElements>
                </configuration>
                <executions>
                    <execution>
                        <id>flatten</id>
                        <phase>process-resources</phase>
                        <goals>
                            <goal>flatten</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>flatten.clean</id>
                        <phase>clean</phase>
                        <goals>
                            <goal>clean</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>