java - 如何使用maven-flatten解决pom.xml父项目修订中的fecth问题?

标签 java spring maven spring-boot revision

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

我使用 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

当我尝试为子项目运行 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 }。 但是当我尝试父项目时它有效。但我必须运行子项目,因为我在其中使用了 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 是这样的

<?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>

关于java - 如何使用maven-flatten解决pom.xml父项目修订中的fecth问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57468201/

相关文章:

java - 将maven项目转为eclipse项目的问题

java - 为什么 JLabel 实例只显示 8 行?

java - 使用 transferHandler 将文本从 JLabel 拖放到 JTable

Spring REST - 如何检索返回资源的 ID?

Spring 3 构造函数 Autowiring - 为什么这段代码有效?

java - 在多模块 Maven 项目中创建程序集存档时出错

java - SVM预测读取数据测试

java - 序列化后在 ArrayList 上调用 equals

java - 替换 spring/hibernate 项目中的 import.sql 文件

java - GWT 2.6.1 编译时出现数字转换错误