如何解决 pom.xml parent 项目修订 maven-flatten 中的问题?

How to solve fecth problem in pom.xml parent project revision with maven-flatten?

我尝试制作集中项目来管理修订。我有多模块项目。

我用apache-maven-flatten 我的参考链接:

https://blog.soebes.de/blog/2017/04/02/maven-pom-files-without-a-version-in-it/ https://dev.to/khmarbaise/continuous-delivery-with-apache-maven--4i03 https://maven.apache.org/maven-ci-friendly.html

当我尝试 运行 child 项目的 Maven 目标时

-Drevision=3.0.0 clean install

我得到这个异常

Downloading from archiva.internal: http://localhost:8080/repository/internal/io/geniusbrain/great/$%7Brevision%7D/great-$%7Brevision%7D.pom

无法解决 ${revision }。 但是当我尝试 parent 项目时它起作用了。但是我必须 运行 用于 child 项目,因为我在其中使用 spring-boot。所以我使用 spring-boot:repackage 为它

我尝试将 maven 版本从 3.5.4 更改为 3.6.0 我也试过这个

https://github.com/wilkinsona/flatten-maven-plugin-problem

我的 parent pom 是这样的

<?xml version="1.0" encoding="UTF-8"?>
<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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>


    <groupId>io.geniusbrain</groupId>
    <artifactId>great</artifactId>
    <version>${revision}</version>
    <packaging>pom</packaging>
    <name>great</name>



        <module>firstmodule</module>
        <module>x1</module>
        <module>x2</module>
        <module>x3</module>
        <!--- etc -->


    </modules>


    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
        <pg-commons-util.version>1.0</pg-commons-util.version>
        <pg-commons-rabbit.version>1.3.4</pg-commons-rabbit.version>
        <ignite.version>2.7.5</ignite.version>
        <spring.boot.version>2.1.2.RELEASE</spring.boot.version>
        <spring.cloud.config.version>2.1.2.RELEASE</spring.cloud.config.version>
    </properties>


    <build>
        <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>org.codehaus.mojo</groupId>
                    <artifactId>flatten-maven-plugin</artifactId>
                    <configuration>
                        <updatePomFile>true</updatePomFile>
                    </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>
        </pluginManagement>
    </build>

    <distributionManagement>
        <repository>
            <id>archiva.internal</id>
            <name>Internal Release Repository</name>
            <url>http://127.0.0.1:8080/repository/internal/</url>
        </repository>
        <snapshotRepository>
            <id>archiva.snapshots</id>
            <name>Internal Snapshot Repository</name>
            <url>http://127.0.0.1:8080/repository/snapshots/</url>
        </snapshotRepository>
    </distributionManagement>


    <repositories>
        <repository>
            <id>archiva.internal</id>
            <url>http://127.0.0.1:8080/repository/internal/</url>
            <releases>
                <enabled>true</enabled>
            </releases>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </repository>
        <repository>
            <id>archiva.snapshots</id>
            <url>http://127.0.0.1:8080/repository/snapshots/</url>
            <releases>
                <enabled>false</enabled>
            </releases>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
        </repository>

        <!--- etc -->


    </repositories>


    <dependencyManagement>
        <dependencies>

            <dependency>
                <groupId>${project.groupId}</groupId>
                <artifactId>lib-cluster-core</artifactId>
                <version>${project.version}</version>
            </dependency>

            <dependency>
                <groupId>org.projectlombok</groupId>
                <artifactId>lombok</artifactId>
                <version>${lombok.version}</version>
            </dependency>

            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-dependencies</artifactId>
                <version>${spring.boot.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-config-dependencies</artifactId>
                <version>${spring.cloud.config.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>

            <!--- etc -->

        </dependencies>
    </dependencyManagement>

    <dependencies>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
        </dependency>
    </dependencies>


</project>

我的 child pom 是这样的

<?xml version="1.0" encoding="UTF-8"?>
<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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <parent>
        <groupId>io.geniusbrain</groupId>
        <artifactId>great</artifactId>
        <version>${revision}</version>
    </parent>

    <name>firstmodule</name>
    <artifactId>firstmodule</artifactId>
    <packaging>jar</packaging>


    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <version>${spring.boot.version}</version>
            </plugin>
        </plugins>
    </build>

    <dependencies>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
            <exclusions>
                <exclusion>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-tomcat</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-config</artifactId>
        </dependency>

        <!--- etc -->

    </dependencies>
</project>

这是我找到的解决方案

我为每个子项目添加了这个配置

    <build>
    <plugins>
            <!--My others plugins  for ex : spring-boot  -->
    </plugins>
    <pluginManagement>
        <plugins>
            <!--This plugin's configuration is used to store Eclipse m2e settings only. It has no influence on the Maven build itself.-->
            <plugin>
                <groupId>org.eclipse.m2e</groupId>
                <artifactId>lifecycle-mapping</artifactId>
                <version>1.0.0</version>
                <configuration>
                    <lifecycleMappingMetadata>
                        <pluginExecutions>
                            <pluginExecution>
                                <pluginExecutionFilter>
                                    <groupId>
                                        org.codehaus.mojo
                                    </groupId>
                                    <artifactId>
                                        flatten-maven-plugin
                                    </artifactId>
                                    <versionRange>
                                        [1.1.0,)
                                    </versionRange>
                                    <goals>
                                        <goal>flatten</goal>
                                    </goals>
                                </pluginExecutionFilter>
                                <action>
                                    <ignore></ignore>
                                </action>
                            </pluginExecution>
                        </pluginExecutions>
                    </lifecycleMappingMetadata>
                </configuration>
            </plugin>
        </plugins>
    </pluginManagement>
</build>