flatten-maven-plugin 插件使用效果
2021/5/21 18:55:32
本文主要是介绍flatten-maven-plugin 插件使用效果,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
从 Maven 3.5.0-beta-1 版本开始,Maven 就支持使用类似于 ${xxx.version} 这样的工件版本占位符来替代硬编码的版本号了,赶紧来试试。
<?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>com.jjk</groupId> <artifactId>flatten-maven-plugin-demo</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>jar</packaging> <properties> <commons-lang3.version>3.11</commons-lang3.version> <junit.version>4.12</junit.version> </properties> <dependencies> <dependency> <groupId>org.apache.commons</groupId> <artifactId>commons-lang3</artifactId> <version>${commons-lang3.version}</version> </dependency> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>${junit.version}</version> <scope>test</scope> </dependency> </dependencies> <build> <plugins> <!-- <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>flatten-maven-plugin</artifactId> <version>1.2.5</version> <configuration> </configuration> <executions> <execution> <id>flatten</id> <phase>process-resources</phase> <goals> <goal>flatten</goal> </goals> </execution> </executions> </plugin>--> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.1</version> <configuration> <source>1.8</source> <target>1.8</target> <encoding>utf-8</encoding> </configuration> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-source-plugin</artifactId> <executions> <execution> <id>attach-sources</id> <goals> <goal>jar</goal> </goals> </execution> </executions> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-javadoc-plugin</artifactId> <version>2.9</version> <executions> <execution> <id>attach-javadocs</id> <goals> <goal>jar</goal> </goals> </execution> </executions> </plugin> </plugins> </build> <distributionManagement> <snapshotRepository> <id>snapshots</id> <name>maven2 repository-snapshots</name> <url>http://YOUR-URL</url> </snapshotRepository> </distributionManagement> </project>
先注释掉“flatten-maven-plugin”,deploy成功后,到我公司的私服上去查看该工件的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>com.jjk</groupId> <artifactId>flatten-maven-plugin-demo</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>jar</packaging> <properties> <commons-lang3.version>3.11</commons-lang3.version> <junit.version>4.12</junit.version> </properties> <dependencies> <dependency> <groupId>org.apache.commons</groupId> <artifactId>commons-lang3</artifactId> <version>${commons-lang3.version}</version> </dependency> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>${junit.version}</version> <scope>test</scope> </dependency> </dependencies> <build> <plugins> <!-- <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>flatten-maven-plugin</artifactId> <version>1.2.5</version> <configuration> </configuration> <executions> <execution> <id>flatten</id> <phase>process-resources</phase> <goals> <goal>flatten</goal> </goals> </execution> </executions> </plugin>--> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.1</version> <configuration> <source>1.8</source> <target>1.8</target> <encoding>utf-8</encoding> </configuration> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-source-plugin</artifactId> <executions> <execution> <id>attach-sources</id> <goals> <goal>jar</goal> </goals> </execution> </executions> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-javadoc-plugin</artifactId> <version>2.9</version> <executions> <execution> <id>attach-javadocs</id> <goals> <goal>jar</goal> </goals> </execution> </executions> </plugin> </plugins> </build> <distributionManagement> <snapshotRepository> <id>snapshots</id> <name>maven2 repository-snapshots</name> <url>http://YOUR-URL</url> </snapshotRepository> </distributionManagement> </project>
你会发现:
- commons-lang3的版本仍然是占位符,对于低版本Maven来说,无法识别;
- junit、maven-compiler-plugin、maven-source-plugin、maven-javadoc-plugin、distributionManagement,对于工件使用者来说,不用关心;
去掉注释后,再次deploy,可以看到一切都安静、整洁了:
<?xml version="1.0" encoding="UTF-8"?> <project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <modelVersion>4.0.0</modelVersion> <groupId>com.jdd</groupId> <artifactId>flatten-maven-plugin-demo</artifactId> <version>0.0.2-SNAPSHOT</version> <dependencies> <dependency> <groupId>org.apache.commons</groupId> <artifactId>commons-lang3</artifactId> <version>3.11</version> <scope>compile</scope> </dependency> </dependencies> </project>
资料
- https://blog.csdn.net/sayyy/article/details/103994302
- https://segmentfault.com/a/1190000019280804?utm_source=tag-newest
- https://blog.csdn.net/weixin_35377249/article/details/112207499 非常详细
- https://www.cnblogs.com/jonath/p/7729903.html
- https://www.coder.work/article/6246918
- https://my.oschina.net/liyuj/blog/874929
- https://zhuanlan.zhihu.com/p/270574226
- https://www.mojohaus.org/flatten-maven-plugin/examples/example-simple-project.html
这篇关于flatten-maven-plugin 插件使用效果的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-11-23Springboot应用的多环境打包入门
- 2024-11-23Springboot应用的生产发布入门教程
- 2024-11-23Python编程入门指南
- 2024-11-23Java创业入门:从零开始的编程之旅
- 2024-11-23Java创业入门:新手必读的Java编程与创业指南
- 2024-11-23Java对接阿里云智能语音服务入门详解
- 2024-11-23Java对接阿里云智能语音服务入门教程
- 2024-11-23JAVA对接阿里云智能语音服务入门教程
- 2024-11-23Java副业入门:初学者的简单教程
- 2024-11-23JAVA副业入门:初学者的实战指南