Using the maven flatten plugin for published POMs

To avoid propagating build setup that is required to build a Spring Cloud project, the maven flatten plugin can be used. It has the advantage of letting you use whatever features you need while publishing "clean" pom to the repository.

fixes gh-89
This commit is contained in:
Marcin Grzejszczak
2019-11-07 14:12:44 +01:00
parent 8a3f69227e
commit 9d88a2c0de
5 changed files with 118 additions and 68 deletions

View File

@@ -226,6 +226,24 @@ Go to `File` -> `Settings` -> `Other settings` -> `Checkstyle`. There click on t
IMPORTANT: Remember to set the `Scan Scope` to `All sources` since we apply checkstyle rules for production and test sources.
== Flattening the POMs
To avoid propagating build setup that is required to build a Spring Cloud project, we're using the maven flatten plugin. It has the advantage of letting you use whatever features you need while publishing "clean" pom to the repository.
In order to add it, add the `org.codehaus.mojo:flatten-maven-plugin` to your `pom.xml`.
[source,xml]
----
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>flatten-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
----
== Reusing the documentation
Spring Cloud Build publishes its `spring-cloud-build-docs` module that contains

View File

@@ -42,6 +42,24 @@ $ mvn deploy -P central -DaltReleaseDeploymentRepository=sonatype-nexus-staging:
include::https://raw.githubusercontent.com/spring-cloud/spring-cloud-build/master/docs/src/main/asciidoc/contributing.adoc[]
== Flattening the POMs
To avoid propagating build setup that is required to build a Spring Cloud project, we're using the maven flatten plugin. It has the advantage of letting you use whatever features you need while publishing "clean" pom to the repository.
In order to add it, add the `org.codehaus.mojo:flatten-maven-plugin` to your `pom.xml`.
[source,xml]
----
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>flatten-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
----
== Reusing the documentation
Spring Cloud Build publishes its `spring-cloud-build-docs` module that contains

57
pom.xml
View File

@@ -253,42 +253,33 @@
</execution>
</executions>
</plugin>
<!--<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>flatten-maven-plugin</artifactId>
<version>1.0.0</version>
<inherited>true</inherited>
<configuration>
<updatePomFile>true</updatePomFile>
<flattenMode>oss</flattenMode>
<pomElements>
<parent>expand</parent>
<distributionManagement>remove</distributionManagement>
<repositories>remove</repositories>
</pomElements>
</configuration>
<executions>
&lt;!&ndash; enable flattening &ndash;&gt;
<execution>
<id>flatten</id>
<phase>process-resources</phase>
<goals>
<goal>flatten</goal>
</goals>
</execution>
&lt;!&ndash; ensure proper cleanup &ndash;&gt;
<execution>
<id>flatten.clean</id>
<phase>clean</phase>
<goals>
<goal>clean</goal>
</goals>
</execution>
</executions>
</plugin>-->
</plugins>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>flatten-maven-plugin</artifactId>
<inherited>true</inherited>
<executions>
<execution>
<!-- Tidy up all POMs before they are published -->
<id>flatten</id>
<phase>process-resources</phase>
<goals>
<goal>flatten</goal>
</goals>
<configuration>
<updatePomFile>true</updatePomFile>
<flattenMode>oss</flattenMode>
<pomElements>
<parent>expand</parent>
<distributionManagement>remove</distributionManagement>
<repositories>remove</repositories>
</pomElements>
</configuration>
</execution>
</executions>
</plugin>
<!-- Apply more sensible defaults for user projects -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>

View File

@@ -21,6 +21,64 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<spring-boot.version>2.2.0.RELEASE</spring-boot.version>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>flatten-maven-plugin</artifactId>
<inherited>false</inherited>
<executions>
<execution>
<!-- Create an effective POM (with versions expanded) for the CLI and
documentation -->
<id>flatten-effective-pom</id>
<phase>process-resources</phase>
<goals>
<goal>flatten</goal>
</goals>
<configuration>
<updatePomFile>false</updatePomFile>
<outputDirectory>${project.build.directory}/effective-pom</outputDirectory>
<flattenedPomFilename>spring-cloud-build-dependencies.xml</flattenedPomFilename>
<flattenMode>oss</flattenMode>
<pomElements>
<parent>expand</parent>
<dependencyManagement>expand</dependencyManagement>
<pluginManagement>expand</pluginManagement>
<properties>remove</properties>
<repositories>remove</repositories>
</pomElements>
</configuration>
</execution>
<execution>
<!-- Flatten and simplify our own POM for install/deploy -->
<id>flatten</id>
<phase>process-resources</phase>
<goals>
<goal>flatten</goal>
</goals>
<configuration>
<updatePomFile>true</updatePomFile>
<flattenMode>bom</flattenMode>
<pomElements>
<parent>expand</parent>
<pluginManagement>keep</pluginManagement>
<properties>keep</properties>
<repositories>remove</repositories>
</pomElements>
</configuration>
</execution>
<execution>
<id>flatten-clean</id>
<phase>clean</phase>
<goals>
<goal>clean</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<distributionManagement>
<downloadUrl>https://github.com/spring-cloud</downloadUrl>
<site>

View File

@@ -195,41 +195,6 @@
</profile>
</profiles>
<build>
<plugins>
<!--<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>flatten-maven-plugin</artifactId>
<version>1.0.0</version>
<inherited>true</inherited>
<configuration>
<updatePomFile>true</updatePomFile>
<flattenMode>oss</flattenMode>
<pomElements>
<parent>expand</parent>
<distributionManagement>remove</distributionManagement>
<repositories>remove</repositories>
</pomElements>
</configuration>
<executions>
&lt;!&ndash; enable flattening &ndash;&gt;
<execution>
<id>flatten</id>
<phase>process-resources</phase>
<goals>
<goal>flatten</goal>
</goals>
</execution>
&lt;!&ndash; ensure proper cleanup &ndash;&gt;
<execution>
<id>flatten.clean</id>
<phase>clean</phase>
<goals>
<goal>clean</goal>
</goals>
</execution>
</executions>
</plugin>-->
</plugins>
<pluginManagement>
<plugins>
<plugin>