flatten-maven-plugin 插件使用效果

从 Maven 3.5.0-beta-1 版本开始,Maven 就支持使用类似于 ${xxx.version} 这样的工件版本占位符来替代硬编码的版本号了,赶紧来试试。


<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.0modelVersion>

    <groupId>com.jjkgroupId>
    <artifactId>flatten-maven-plugin-demoartifactId>
    <version>0.0.1-SNAPSHOTversion>
    <packaging>jarpackaging>

    <properties>
        <commons-lang3.version>3.11commons-lang3.version>
        <junit.version>4.12junit.version>
    properties>

    <dependencies>
        <dependency>
            <groupId>org.apache.commonsgroupId>
            <artifactId>commons-lang3artifactId>
            <version>${commons-lang3.version}version>
        dependency>
        <dependency>
            <groupId>junitgroupId>
            <artifactId>junitartifactId>
            <version>${junit.version}version>
            <scope>testscope>
        dependency>
    dependencies>

    <build>
        <plugins>

            <plugin>
                <groupId>org.apache.maven.pluginsgroupId>
                <artifactId>maven-compiler-pluginartifactId>
                <version>3.1version>
                <configuration>
                    <source>1.8source>
                    <target>1.8target>
                    <encoding>utf-8encoding>
                configuration>
            plugin>
            <plugin>
                <groupId>org.apache.maven.pluginsgroupId>
                <artifactId>maven-source-pluginartifactId>
                <executions>
                    <execution>
                        <id>attach-sourcesid>
                        <goals>
                            <goal>jargoal>
                        goals>
                    execution>
                executions>
            plugin>
            <plugin>
                <groupId>org.apache.maven.pluginsgroupId>
                <artifactId>maven-javadoc-pluginartifactId>
                <version>2.9version>
                <executions>
                    <execution>
                        <id>attach-javadocsid>
                        <goals>
                            <goal>jargoal>
                        goals>
                    execution>
                executions>
            plugin>
        plugins>
    build>

    <distributionManagement>
        <snapshotRepository>
            <id>snapshotsid>
            <name>maven2 repository-snapshotsname>
            <url>http://YOUR-URLurl>
        snapshotRepository>
    distributionManagement>
project>

先注释掉“flatten-maven-plugin”,deploy成功后,到我公司的私服上去查看该工件的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.0modelVersion>

    <groupId>com.jjkgroupId>
    <artifactId>flatten-maven-plugin-demoartifactId>
    <version>0.0.1-SNAPSHOTversion>
    <packaging>jarpackaging>

    <properties>
        <commons-lang3.version>3.11commons-lang3.version>
        <junit.version>4.12junit.version>
    properties>

    <dependencies>
        <dependency>
            <groupId>org.apache.commonsgroupId>
            <artifactId>commons-lang3artifactId>
            <version>${commons-lang3.version}version>
        dependency>
        <dependency>
            <groupId>junitgroupId>
            <artifactId>junitartifactId>
            <version>${junit.version}version>
            <scope>testscope>
        dependency>
    dependencies>

    <build>
        <plugins>


            <plugin>
                <groupId>org.apache.maven.pluginsgroupId>
                <artifactId>maven-compiler-pluginartifactId>
                <version>3.1version>
                <configuration>
                    <source>1.8source>
                    <target>1.8target>
                    <encoding>utf-8encoding>
                configuration>
            plugin>
            <plugin>
                <groupId>org.apache.maven.pluginsgroupId>
                <artifactId>maven-source-pluginartifactId>
                <executions>
                    <execution>
                        <id>attach-sourcesid>
                        <goals>
                            <goal>jargoal>
                        goals>
                    execution>
                executions>
            plugin>
            <plugin>
                <groupId>org.apache.maven.pluginsgroupId>
                <artifactId>maven-javadoc-pluginartifactId>
                <version>2.9version>
                <executions>
                    <execution>
                        <id>attach-javadocsid>
                        <goals>
                            <goal>jargoal>
                        goals>
                    execution>
                executions>
            plugin>
        plugins>
    build>

    <distributionManagement>
        <snapshotRepository>
            <id>snapshotsid>
            <name>maven2 repository-snapshotsname>
            <url>http://YOUR-URLurl>
        snapshotRepository>
    distributionManagement>

project>

你会发现:

  • commons-lang3的版本仍然是占位符,对于低版本Maven来说,无法识别;
  • junit、maven-compiler-plugin、maven-source-plugin、maven-javadoc-plugin、distributionManagement,对于工件使用者来说,不用关心;

去掉注释后,再次deploy,可以看到一切都安静、整洁了:


<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.0modelVersion>
  <groupId>com.jddgroupId>
  <artifactId>flatten-maven-plugin-demoartifactId>
  <version>0.0.2-SNAPSHOTversion>
  <dependencies>
    <dependency>
      <groupId>org.apache.commonsgroupId>
      <artifactId>commons-lang3artifactId>
      <version>3.11version>
      <scope>compilescope>
    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

你可能感兴趣的:(Java基础)