build: 优化 Maven 配置

This commit is contained in:
2023-11-20 19:45:41 +08:00
parent 2c4fc7e314
commit 51d7c05902
3 changed files with 185 additions and 134 deletions

View File

@@ -47,7 +47,6 @@
<url>https://github.com/Bull-BCLS</url> <url>https://github.com/Bull-BCLS</url>
</developer> </developer>
</developers> </developers>
<scm> <scm>
<url>https://github.com/Charles7c/continew-starter</url> <url>https://github.com/Charles7c/continew-starter</url>
<connection>scm:git:git@github.com:Charles7c/continew-starter.git</connection> <connection>scm:git:git@github.com:Charles7c/continew-starter.git</connection>
@@ -57,10 +56,6 @@
<properties> <properties>
<revision>1.0.0-SNAPSHOT</revision> <revision>1.0.0-SNAPSHOT</revision>
<hutool.version>5.8.23</hutool.version> <hutool.version>5.8.23</hutool.version>
<!-- Maven Plugin Versions -->
<maven-gpg-plugin.version>3.1.0</maven-gpg-plugin.version>
<flatten-maven-plugin.version>1.5.0</flatten-maven-plugin.version>
</properties> </properties>
<dependencyManagement> <dependencyManagement>
@@ -81,6 +76,141 @@
</dependencies> </dependencies>
</dependencyManagement> </dependencyManagement>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>flatten-maven-plugin</artifactId>
<version>1.5.0</version>
<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>continew-starter-dependencies.xml</flattenedPomFilename>
<flattenMode>oss</flattenMode>
<pomElements>
<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>
<properties>keep</properties>
<pluginManagement>keep</pluginManagement>
<repositories>remove</repositories>
</pomElements>
</configuration>
</execution>
<execution>
<id>flatten-clean</id>
<phase>clean</phase>
<goals>
<goal>clean</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>xml-maven-plugin</artifactId>
<inherited>false</inherited>
<executions>
<execution>
<!-- Cleanup the effective POM -->
<id>post-process-effective-pom</id>
<phase>process-resources</phase>
<goals>
<goal>transform</goal>
</goals>
<configuration>
<transformationSets>
<transformationSet>
<dir>${project.build.directory}/effective-pom</dir>
<outputDir>${project.build.directory}/effective-pom</outputDir>
<stylesheet>src/main/xslt/post-process-flattened-pom.xsl</stylesheet>
<outputProperties>
<outputProperty>
<name>indent</name>
<value>yes</value>
</outputProperty>
</outputProperties>
</transformationSet>
</transformationSets>
</configuration>
</execution>
<execution>
<!-- Cleanup the flattened project POM -->
<id>post-process-flattened-pom</id>
<phase>process-resources</phase>
<goals>
<goal>transform</goal>
</goals>
<configuration>
<transformationSets>
<transformationSet>
<dir>${project.basedir}</dir>
<outputDir>${project.basedir}</outputDir>
<includes>.flattened-pom.xml</includes>
<stylesheet>src/main/xslt/post-process-flattened-pom.xsl</stylesheet>
<outputProperties>
<outputProperty>
<name>indent</name>
<value>yes</value>
</outputProperty>
</outputProperties>
</transformationSet>
</transformationSets>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<inherited>false</inherited>
<executions>
<execution>
<!-- Attach effective POM -->
<id>attach-artifacts</id>
<phase>package</phase>
<goals>
<goal>attach-artifact</goal>
</goals>
<configuration>
<artifacts>
<artifact>
<file>${project.build.directory}/effective-pom/continew-starter-dependencies.xml</file>
<type>effective-pom</type>
</artifact>
</artifacts>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<profiles> <profiles>
<profile> <profile>
<id>release</id> <id>release</id>
@@ -110,11 +240,10 @@
</execution> </execution>
</executions> </executions>
</plugin> </plugin>
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId> <artifactId>maven-gpg-plugin</artifactId>
<version>${maven-gpg-plugin.version}</version> <version>3.1.0</version>
<executions> <executions>
<execution> <execution>
<phase>verify</phase> <phase>verify</phase>
@@ -124,47 +253,19 @@
</execution> </execution>
</executions> </executions>
</plugin> </plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>flatten-maven-plugin</artifactId>
<version>${flatten-maven-plugin.version}</version>
<inherited>false</inherited>
<configuration>
<updatePomFile>true</updatePomFile>
<flattenMode>resolveCiFriendliesOnly</flattenMode>
</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>
</plugins> </plugins>
</build> </build>
<distributionManagement> <distributionManagement>
<repository>
<id>sonatype-nexus-staging</id>
<name>Nexus Release Repository</name>
<url>https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/</url>
</repository>
<snapshotRepository> <snapshotRepository>
<id>sonatype-nexus-snapshots</id> <id>sonatype-nexus-snapshots</id>
<name>Sonatype Nexus Snapshots</name> <name>Sonatype Nexus Snapshots</name>
<url>https://s01.oss.sonatype.org/content/repositories/snapshots/</url> <url>https://s01.oss.sonatype.org/content/repositories/snapshots/</url>
</snapshotRepository> </snapshotRepository>
<repository>
<id>sonatype-nexus-staging</id>
<name>Nexus Release Repository</name>
<url>https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/</url>
</repository>
</distributionManagement> </distributionManagement>
</profile> </profile>
</profiles> </profiles>

View File

@@ -0,0 +1,31 @@
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:m="http://maven.apache.org/POM/4.0.0"
exclude-result-prefixes="m">
<xsl:output method="xml" encoding="utf-8" indent="yes"
xslt:indent-amount="2" xmlns:xslt="http://xml.apache.org/xslt" />
<xsl:strip-space elements="*" />
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()" />
</xsl:copy>
</xsl:template>
<xsl:template match="/m:project/m:properties">
<xsl:copy>
<xsl:apply-templates select="node()">
<xsl:sort select="name()" />
</xsl:apply-templates>
</xsl:copy>
</xsl:template>
<xsl:template
match="/m:project/m:dependencyManagement/m:dependencies/m:dependency/m:version/text()[. = '${revision}']">
<xsl:value-of select="/m:project/m:version/text()" />
</xsl:template>
<xsl:template
match="/m:project/m:build/m:pluginManagement/m:plugins/m:plugin/m:version/text()[. = '${revision}']">
<xsl:value-of select="/m:project/m:version/text()" />
</xsl:template>
<xsl:template match="/m:project/m:properties/m:revision" />
<xsl:template match="/m:project/m:properties/m:main.basedir" />
<xsl:template match="/m:project/m:distributionManagement" />
</xsl:stylesheet>

107
pom.xml
View File

@@ -3,10 +3,14 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<parent>
<groupId>top.charles7c.continew</groupId>
<artifactId>continew-starter-dependencies</artifactId>
<version>${revision}</version>
<relativePath>./continew-starter-dependencies</relativePath>
</parent>
<groupId>top.charles7c.continew</groupId>
<artifactId>continew-starter</artifactId> <artifactId>continew-starter</artifactId>
<version>${revision}</version>
<packaging>pom</packaging> <packaging>pom</packaging>
<name>${project.artifactId}</name> <name>${project.artifactId}</name>
@@ -46,7 +50,6 @@
<url>https://github.com/Bull-BCLS</url> <url>https://github.com/Bull-BCLS</url>
</developer> </developer>
</developers> </developers>
<scm> <scm>
<url>https://github.com/Charles7c/continew-starter</url> <url>https://github.com/Charles7c/continew-starter</url>
<connection>scm:git:git@github.com:Charles7c/continew-starter.git</connection> <connection>scm:git:git@github.com:Charles7c/continew-starter.git</connection>
@@ -54,10 +57,6 @@
</scm> </scm>
<properties> <properties>
<revision>1.0.0-SNAPSHOT</revision>
<spring-boot.version>3.1.5</spring-boot.version>
<!-- Maven Environment Versions --> <!-- Maven Environment Versions -->
<java.version>17</java.version> <java.version>17</java.version>
<resource.delimiter>@</resource.delimiter> <resource.delimiter>@</resource.delimiter>
@@ -65,13 +64,6 @@
<maven.compiler.target>${java.version}</maven.compiler.target> <maven.compiler.target>${java.version}</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<!-- Maven Plugin Versions -->
<spotless.version>2.30.0</spotless.version>
<maven-source-plugin.version>3.2.1</maven-source-plugin.version>
<maven-javadoc-plugin.version>3.5.0</maven-javadoc-plugin.version>
<maven-gpg-plugin.version>3.1.0</maven-gpg-plugin.version>
<flatten-maven-plugin.version>1.5.0</flatten-maven-plugin.version>
</properties> </properties>
<modules> <modules>
@@ -79,26 +71,13 @@
<module>continew-starter-core</module> <module>continew-starter-core</module>
</modules> </modules>
<dependencyManagement>
<dependencies>
<!-- ContiNew Starter Dependencies -->
<dependency>
<groupId>top.charles7c.continew</groupId>
<artifactId>continew-starter-dependencies</artifactId>
<version>${revision}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<build> <build>
<plugins> <plugins>
<!-- 代码等格式化插件 --> <!-- 代码等格式化插件 -->
<plugin> <plugin>
<groupId>com.diffplug.spotless</groupId> <groupId>com.diffplug.spotless</groupId>
<artifactId>spotless-maven-plugin</artifactId> <artifactId>spotless-maven-plugin</artifactId>
<version>${spotless.version}</version> <version>2.40.0</version>
<executions> <executions>
<execution> <execution>
<phase>compile</phase> <phase>compile</phase>
@@ -116,14 +95,17 @@
</java> </java>
</configuration> </configuration>
</plugin> </plugin>
<plugin> <plugin>
<groupId>org.codehaus.mojo</groupId> <groupId>org.codehaus.mojo</groupId>
<artifactId>flatten-maven-plugin</artifactId> <artifactId>flatten-maven-plugin</artifactId>
<version>${flatten-maven-plugin.version}</version> <version>1.5.0</version>
<configuration> <configuration>
<updatePomFile>true</updatePomFile> <updatePomFile>true</updatePomFile>
<flattenMode>resolveCiFriendliesOnly</flattenMode> <flattenMode>oss</flattenMode>
<pomElements>
<parent>expand</parent>
<properties>keep</properties>
</pomElements>
</configuration> </configuration>
<executions> <executions>
<execution> <execution>
@@ -144,67 +126,4 @@
</plugin> </plugin>
</plugins> </plugins>
</build> </build>
<profiles>
<profile>
<id>release</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>${maven-source-plugin.version}</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>jar-no-fork</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>${maven-javadoc-plugin.version}</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<version>${maven-gpg-plugin.version}</version>
<executions>
<execution>
<phase>verify</phase>
<goals>
<goal>sign</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<distributionManagement>
<snapshotRepository>
<id>sonatype-nexus-snapshots</id>
<name>Sonatype Nexus Snapshots</name>
<url>https://s01.oss.sonatype.org/content/repositories/snapshots/</url>
</snapshotRepository>
<repository>
<id>sonatype-nexus-staging</id>
<name>Nexus Release Repository</name>
<url>https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/</url>
</repository>
</distributionManagement>
</profile>
</profiles>
</project> </project>