flatten-maven-plugin使用教程

2023-08-06 0 2,244

目录

一、简介

1.1 作用

pom工程父子pom的版本,提出作为变量定义在properties。

这样仅修改变量的值(如在运行mvn命令时指定) 即可实现版本整体切换。

1.2 goal介绍

  • flatten:clean

删除flatten插件生成的 .flattened-pom.xml

配置参数有:

flattenedPomFilename: 插件生成的pom的名字,默认为 .flattened-pom.xml

outputDirectory:插件生成pom的目录,默认为 ${project.basedir}

  • flatten:flatten

resources-process生成 .flattened-pom.xml,并在install/deploy时替换原始pom.xml

主要配置参数有:

flattenedPomFilename: 插件生成的pom的名字,默认为 .flattened-pom.xml

outputDirectory:插件生成pom的目录,默认为 ${project.basedir}

updatePomFile: packing=pom的module也进行reversion变量替换,默认为false

flattenMode:用来定义生成 .flattened-pom.xml所包含的元素,常用值有:

oss:开源软件常用,除了repositories/pluginRepositories外其他所有FlattenDescriptor定义的元素都生成

ossrh:所有FlattenDescriptor定义的元素都生成

bom:在ossrh基础上增加dependencyManagement和properties

defaults:除了repositories其他所有FlattenDescriptor定义的元素都不生成

clean:所有FlattenDescriptor定义的元素都不生成

fatjar:所有FlattenDescriptor定义的元素和dependencies都不生成

resolveCiFriendliesOnly:只替换原始pom中的revision, sha1 and changelist,其他否保持原样

常用oss/ossrh/resolveCiFriendliesOnly

  • FlattenDescriptor定义的pom.xml元素有:

modelVersion
groupId
artifactId
version
packaging
licenses
dependencies
profiles
name
description
url
inceptionYear
organization
scm
developers
contributors
mailingLists
pluginRepositories
issueManagement
ciManagement
distributionManagement
prerequisites
repositories
parent
build
dependencyManagement
properties
modules
reporting

二、使用总结

  • 不用flatten-maven-plugin

1.父pom定义版本为变量reversion并作为version,子pom复引用变量reversion作为version

2.结果能正常运行compile/test, 但install或deploy时父子pom中的version还是reversion变量未被替换

3.没有version别人无法引用你的包

父pom.xml

<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>
    <packaging>pom</packaging>
    <version>${reversion1}</version>
    <modules>
        <module>no-flatten-child</module>
    </modules>
    <groupId>com.wsl.my.maven</groupId>
    <artifactId>no-flatten-plugin</artifactId>
    <properties>
        <maven.compiler.source>8</maven.compiler.source>
        <maven.compiler.target>8</maven.compiler.target>
        <reversion1>1.1.0-SNAPSHOT</reversion1>
    </properties>
</project>

子pom.xml

<?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\">
    <parent>
        <artifactId>no-flatten-plugin</artifactId>
        <groupId>com.wsl.my.maven</groupId>
        <version>${reversion1}</version>
        <relativePath>../pom.xml</relativePath>
    </parent>
    <modelVersion>4.0.0</modelVersion>
    <artifactId>no-flatten-child</artifactId>
</project>

install/deploy后父子pom.xml中的${reversion1}没有被替换

  • 使用了flatten-maven-plugin

1.父pom定义版本为变量reversion并作为version,子pom复引用变量reversion作为version

2.使用flatten-maven-plugin并设置updatePomFile=true,并绑定goal到maven周期

3.在process-resources阶段时会在父子project目录下生成.flattened-pom.xml(version已替换为具体值)

4.运行install或deploy时会将.flattened-pom.xml替换原来的pom.xml

原始父pom

<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>
    <version>${reversion2}</version>
    <packaging>pom</packaging>
    <artifactId>use-flatten-parent</artifactId>
		<groupId>com.wsl.my.maven</groupId>
    <modules>
        <module>use-flatten-child</module>
    </modules>
    <properties>
        <maven.compiler.source>8</maven.compiler.source>
        <maven.compiler.target>8</maven.compiler.target>
        <reversion2>1.2.0-SNAPSHOT</reversion2>
    </properties>
    <build>
        <plugins>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>flatten-maven-plugin</artifactId>
                <version>1.2.7</version>
                <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>
    </build>
</project>
资源下载此资源下载价格为1小猪币,终身VIP免费,请先
由于本站资源来源于互联网,以研究交流为目的,所有仅供大家参考、学习,不存在任何商业目的与商业用途,如资源存在BUG以及其他任何问题,请自行解决,本站不提供技术服务! 由于资源为虚拟可复制性,下载后不予退积分和退款,谢谢您的支持!如遇到失效或错误的下载链接请联系客服QQ:442469558

:本文采用 知识共享署名-非商业性使用-相同方式共享 4.0 国际许可协议 进行许可, 转载请附上原文出处链接。
1、本站提供的源码不保证资源的完整性以及安全性,不附带任何技术服务!
2、本站提供的模板、软件工具等其他资源,均不包含技术服务,请大家谅解!
3、本站提供的资源仅供下载者参考学习,请勿用于任何商业用途,请24小时内删除!
4、如需商用,请购买正版,由于未及时购买正版发生的侵权行为,与本站无关。
5、本站部分资源存放于百度网盘或其他网盘中,请提前注册好百度网盘账号,下载安装百度网盘客户端或其他网盘客户端进行下载;
6、本站部分资源文件是经压缩后的,请下载后安装解压软件,推荐使用WinRAR和7-Zip解压软件。
7、如果本站提供的资源侵犯到了您的权益,请邮件联系: 442469558@qq.com 进行处理!

猪小侠源码-最新源码下载平台 Java教程 flatten-maven-plugin使用教程 http://www.20zxx.cn/806426/xuexijiaocheng/javajc.html

猪小侠源码,优质资源分享网

常见问题
  • 本站所有资源版权均属于原作者所有,均只能用于参考学习,请勿直接商用。若由于商用引起版权纠纷,一切责任均由使用者承担
查看详情
  • 最常见的情况是下载不完整: 可对比下载完压缩包的与网盘上的容量,建议提前注册好百度网盘账号,使用百度网盘客户端下载
查看详情

相关文章

官方客服团队

为您解决烦忧 - 24小时在线 专业服务