-
Notifications
You must be signed in to change notification settings - Fork 94
Description
Currently, the plugin operates on the pom file of the current project. This is mostly useful but there are use cases where a build wants to modify/flatten a pom file from another project. In this case, it would be great to specify the pom file e.g. with
<configuration>
<pomFile>../../../some-other-project/pom.xml</pomFile>
...
</configuration>and now the flattened pom file etc. is generated from that pom file. Currently, the plugin relies on the ${project} model that is passed in by maven and even though it reads the file directly, it mixes information from the maven project into the output.
If a pom file is specified, the plugin should build a new project and use this (instead of the main pom file).
(what is my use case):
I have a project with a large number of maven modules that I want to integration test using JPMS. The easiest way to do this is:
- in an integration test setup job:
- find the pom file for this maven module (it is at
../../../pom.xml:-) ) - replace the artifactId
foowithfoo-it-parent, replace the packaging withpom. - strip the build section from the pom.
- write the pom to a new file
- install this file in the integration test repo as
groupId:foo-it-parent:pom
use an integration test pom like this:
<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>
<parent>
<groupId>groupId</groupId>
<artifactId>foo-it-parent</artifactId>
<version>@project.version@</version>
</parent>
<groupId>org.jdbi.it</groupId>
<artifactId>test-module</artifactId>
<dependencies>
<dependency>
<groupId>groupId</groupId>
<artifactId>foo</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>groupId</groupId>
<artifactId>foo</artifactId>
<classifier>tests</classifier>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<dependenciesToScan>
<dependency>groupId:foo:*:*:tests</dependency>
</dependenciesToScan>
</configuration>
</plugin>
</plugins>
</build>
</project>This works surprisingly well and the flatten plugin is 90% of the way there (with the patches that I just sent), except that I can not load another pom file but the project file itself:
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>flatten-maven-plugin</artifactId>
<version>1.5.1-SNAPSHOT</version>
<configuration>
<pomFile>../../../pom.xml</pomFile>
<flattenedPomFilename>${project.build.directory}/it-parent-pom.xml</flattenedPomFilename>
<updatePomFile>false</updatePomFile>
<defaultOperation>keep</defaultOperation>
<pomElements combine.self="override">
<packaging>replace</packaging>
<artifactId>replace</artifactId>
<build>remove</build>
</pomElements>
<replacementValues>
<packaging>pom</packaging>
<artifactId>@project.artifactId@-it-parent</artifactId>
</replacementValues>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-install-plugin</artifactId>
<configuration>
<file>${project.build.directory}/it-parent-pom.xml</file>
<pomFile>${project.build.directory}/it-parent-pom.xml</pomFile>
</configuration>
</plugin>
</plugins>
</build>