Maven的settings.xml笔记231208

https://maven.apache.org/ref/

官方文档的模板
官方文档模板3.9.6版

https://maven.apache.org/ref/3.9.6/maven-settings/settings.html

The default location for the settings file is ~/.m2/settings.xml

xml 复制代码
    <settings xmlns="http://maven.apache.org/SETTINGS/1.2.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.2.0 http://maven.apache.org/xsd/settings-1.2.0.xsd">
      <localRepository/>
      <interactiveMode/>
      <usePluginRegistry/>
      <offline/>
     
      <proxies>
        <proxy>
          <active/>
          <protocol/>
          <username/>
          <password/>
          <port/>
          <host/>
          <nonProxyHosts/>
          <id/>
        </proxy>
      </proxies>
     
      <servers>
        <server>
          <username/>
          <password/>
          <privateKey/>
          <passphrase/>
          <filePermissions/>
          <directoryPermissions/>
          <configuration/>
          <id/>
        </server>
      </servers>
     
      <mirrors>
        <mirror>
          <mirrorOf/>
          <name/>
          <url/>
          <layout/>
          <mirrorOfLayouts/>
          <blocked/>
          <id/>
        </mirror>
      </mirrors>
     
      <profiles>
        <profile>
          <activation>
            <activeByDefault/>
            <jdk/>
            <os>
              <name/>
              <family/>
              <arch/>
              <version/>
            </os>
            <property>
              <name/>
              <value/>
            </property>
            <file>
              <missing/>
              <exists/>
            </file>
          </activation>
          <properties>
            <key>value</key>
          </properties>
     
          <repositories>
            <repository>
              <releases>
                <enabled/>
                <updatePolicy/>
                <checksumPolicy/>
              </releases>
              <snapshots>
                <enabled/>
                <updatePolicy/>
                <checksumPolicy/>
              </snapshots>
              <id/>
              <name/>
              <url/>
              <layout/>
            </repository>
          </repositories>
          <pluginRepositories>
            <pluginRepository>
              <releases>
                <enabled/>
                <updatePolicy/>
                <checksumPolicy/>
              </releases>
              <snapshots>
                <enabled/>
                <updatePolicy/>
                <checksumPolicy/>
              </snapshots>
              <id/>
              <name/>
              <url/>
              <layout/>
            </pluginRepository>
          </pluginRepositories>
          <id/>
        </profile>
      </profiles>
     
      <activeProfiles/>
      <pluginGroups/>
    </settings>
官方文档模板 3.6.0 版

https://maven.apache.org/ref/3.6.0/maven-settings/settings.html

xml 复制代码
<settings xmlns="http://maven.apache.org/SETTINGS/1.1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.1.0 http://maven.apache.org/xsd/settings-1.1.0.xsd">
  <localRepository/>
  <interactiveMode/>
  <usePluginRegistry/>
  <offline/>
 
  <proxies>
    <proxy>
      <active/>
      <protocol/>
      <username/>
      <password/>
      <port/>
      <host/>
      <nonProxyHosts/>
      <id/>
    </proxy>
  </proxies>
 
  <servers>
    <server>
      <username/>
      <password/>
      <privateKey/>
      <passphrase/>
      <filePermissions/>
      <directoryPermissions/>
      <configuration/>
      <id/>
    </server>
  </servers>
 
  <mirrors>
    <mirror>
      <mirrorOf/>
      <name/>
      <url/>
      <layout/>
      <mirrorOfLayouts/>
      <id/>
    </mirror>
  </mirrors>
 
  <profiles>
    <profile>
      <activation>
        <activeByDefault/>
        <jdk/>
        <os>
          <name/>
          <family/>
          <arch/>
          <version/>
        </os>
        <property>
          <name/>
          <value/>
        </property>
        <file>
          <missing/>
          <exists/>
        </file>
      </activation>
      <properties>
        <key>value</key>
      </properties>
 
      <repositories>
        <repository>
          <releases>
            <enabled/>
            <updatePolicy/>
            <checksumPolicy/>
          </releases>
          <snapshots>
            <enabled/>
            <updatePolicy/>
            <checksumPolicy/>
          </snapshots>
          <id/>
          <name/>
          <url/>
          <layout/>
        </repository>
      </repositories>
      <pluginRepositories>
        <pluginRepository>
          <releases>
            <enabled/>
            <updatePolicy/>
            <checksumPolicy/>
          </releases>
          <snapshots>
            <enabled/>
            <updatePolicy/>
            <checksumPolicy/>
          </snapshots>
          <id/>
          <name/>
          <url/>
          <layout/>
        </pluginRepository>
      </pluginRepositories>
      <id/>
    </profile>
  </profiles>
 
  <activeProfiles/>
  <pluginGroups/>
</settings>
官方文档模板 3.1.0 版

https://maven.apache.org/ref/3.1.0/maven-settings/settings.html

xml 复制代码
<settings xmlns="http://maven.apache.org/SETTINGS/1.1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.1.0 http://maven.apache.org/xsd/settings-1.1.0.xsd">
  <localRepository/>
  <interactiveMode/>
  <usePluginRegistry/>
  <offline/>

  <proxies>
    <proxy>
      <active/>
      <protocol/>
      <username/>
      <password/>
      <port/>
      <host/>
      <nonProxyHosts/>
      <id/>
    </proxy>
  </proxies>

  <servers>
    <server>
      <username/>
      <password/>
      <privateKey/>
      <passphrase/>
      <filePermissions/>
      <directoryPermissions/>
      <configuration/>
      <id/>
    </server>
  </servers>

  <mirrors>
    <mirror>
      <mirrorOf/>
      <name/>
      <url/>
      <layout/>
      <mirrorOfLayouts/>
      <id/>
    </mirror>
  </mirrors>

  <profiles>
    <profile>
      <activation>
        <activeByDefault/>
        <jdk/>
        <os>
          <name/>
          <family/>
          <arch/>
          <version/>
        </os>
        <property>
          <name/>
          <value/>
        </property>
        <file>
          <missing/>
          <exists/>
        </file>
      </activation>
      <properties>
        <key>value</key>
      </properties>

      <repositories>
        <repository>
          <releases>
            <enabled/>
            <updatePolicy/>
            <checksumPolicy/>
          </releases>
          <snapshots>
            <enabled/>
            <updatePolicy/>
            <checksumPolicy/>
          </snapshots>
          <id/>
          <name/>
          <url/>
          <layout/>
        </repository>
      </repositories>
      <pluginRepositories>
        <pluginRepository>
          <releases>
            <enabled/>
            <updatePolicy/>
            <checksumPolicy/>
          </releases>
          <snapshots>
            <enabled/>
            <updatePolicy/>
            <checksumPolicy/>
          </snapshots>
          <id/>
          <name/>
          <url/>
          <layout/>
        </pluginRepository>
      </pluginRepositories>
      <id/>
    </profile>
  </profiles>

  <activeProfiles/>
  <pluginGroups/>
</settings>
官方文档模板 3.0 版 , 2010年

https://maven.apache.org/ref/3.0/maven-settings/settings.html

xml 复制代码
<settings xmlns="http://maven.apache.org/SETTINGS/1.1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.1.0 http://maven.apache.org/xsd/settings-1.1.0.xsd">
  <localRepository/>
  <interactiveMode/>
  <usePluginRegistry/>
  <offline/>
  <proxies>
    <proxy>
      <active/>
      <protocol/>
      <username/>
      <password/>
      <port/>
      <host/>
      <nonProxyHosts/>
      <id/>
    </proxy>
  </proxies>
  <servers>
    <server>
      <username/>
      <password/>
      <privateKey/>
      <passphrase/>
      <filePermissions/>
      <directoryPermissions/>
      <configuration/>
      <id/>
    </server>
  </servers>
  <mirrors>
    <mirror>
      <mirrorOf/>
      <name/>
      <url/>
      <layout/>
      <mirrorOfLayouts/>
      <id/>
    </mirror>
  </mirrors>
  <profiles>
    <profile>
      <activation>
        <activeByDefault/>
        <jdk/>
        <os>
          <name/>
          <family/>
          <arch/>
          <version/>
        </os>
        <property>
          <name/>
          <value/>
        </property>
        <file>
          <missing/>
          <exists/>
        </file>
      </activation>
      <properties>
        <key>value</key>
      <properties/>
      <repositories>
        <repository>
          <releases>
            <enabled/>
            <updatePolicy/>
            <checksumPolicy/>
          </releases>
          <snapshots>
            <enabled/>
            <updatePolicy/>
            <checksumPolicy/>
          </snapshots>
          <id/>
          <name/>
          <url/>
          <layout/>
        </repository>
      </repositories>
      <pluginRepositories>
        <pluginRepository>
          <releases>
            <enabled/>
            <updatePolicy/>
            <checksumPolicy/>
          </releases>
          <snapshots>
            <enabled/>
            <updatePolicy/>
            <checksumPolicy/>
          </snapshots>
          <id/>
          <name/>
          <url/>
          <layout/>
        </pluginRepository>
      </pluginRepositories>
      <id/>
    </profile>
  </profiles>
  <activeProfiles/>
  <pluginGroups/>
</settings>

true是Maven profile中的一个元素,它表示如果没有任何其他的profile被显式激活,那么这个profile将会被默认激活。

在Maven中,你可以定义多个profile,每个profile可以包含一些特定的设置,例如仓库的位置、插件的版本、依赖的版本等等。这些设置可以在不同的环境中使用,例如在开发环境、测试环境和生产环境中使用不同的设置。当你运行Maven命令时,你可以通过一些方式来显式地激活一个或多个profile,例如通过命令行参数或者通过设置环境变量。

但是,如果没有任何profile被显式激活,Maven将会使用哪个profile呢?这时,元素就起作用了。如果你在profile中将设置为true,那么这个profile将会在没有任何其他profile被显式激活的情况下被默认激活。

需要注意的是,如果有多个profile都将设置为true,那么Maven将会使用第一个在settings.xml文件中定义的profile。因此,你需要确保你的settings.xml文件中定义的profile的顺序是有意义的。

总的来说,true的作用是在没有其他profile被显式激活的情况下,默认激活这个profile。这可以帮助你确保在没有指定任何特定设置的情况下,Maven仍然可以使用一些合理的默认设置来构建你的项目。

设置 Java Jdk 版本

maven.compiler.source

maven.compiler.source 是 Maven 中的一个属性,它用于指定编译器编译源代码的 Java 版本。

在 Maven 的 pom.xml 文件中,你可以通过在 <properties> 标签中设置 maven.compiler.source 属性来指定编译器编译源代码的 Java 版本。例如,要将编译器源代码版本设置为 1.8,你可以在 pom.xml 文件中添加以下代码:

xml 复制代码
<properties>
  <maven.compiler.source>1.8</maven.compiler.source>
</properties>

这将告诉 Maven 使用 Java 1.8 版本的编译器来编译源代码。你可以根据需要将 maven.compiler.source 属性设置为其他 Java 版本。

请注意,maven.compiler.source 属性仅指定编译器编译源代码的 Java 版本。如果你还需要指定编译器生成目标字节码的 Java 版本,你应该使用 maven.compiler.target 属性。例如,要将编译器目标字节码版本设置为 1.8,你可以在 pom.xml 文件中添加以下代码:

xml 复制代码
<properties>
  <maven.compiler.target>1.8</maven.compiler.target>
</properties>

通过设置 maven.compiler.source 和 maven.compiler.target 属性,你可以确保 Maven 使用正确的 Java 版本进行编译,并生成符合目标环境的字节码。

maven.compiler.target

maven.compiler.target 是 Maven 中的一个属性,它用于指定编译器生成目标字节码的 Java 版本。

在 Maven 的 pom.xml 文件中,你可以通过在 <properties> 标签中设置 maven.compiler.target 属性来指定编译器生成目标字节码的 Java 版本。例如,要将编译器目标字节码版本设置为 1.8,你可以在 pom.xml 文件中添加以下代码:

xml 复制代码
<properties>
  <maven.compiler.target>1.8</maven.compiler.target>
</properties>

这将告诉 Maven 使用 Java 1.8 版本的编译器生成目标字节码。你可以根据需要将 maven.compiler.target 属性设置为其他 Java 版本。

请注意,maven.compiler.target 属性仅指定编译器生成目标字节码的 Java 版本。如果你还需要指定编译器编译源代码的 Java 版本,你应该使用 maven.compiler.source 属性。例如,要将编译器源代码版本设置为 1.8,你可以在 pom.xml 文件中添加以下代码:

xml 复制代码
<properties>
  <maven.compiler.source>1.8</maven.compiler.source>
  <maven.compiler.target>1.8</maven.compiler.target>
</properties>

通过设置 maven.compiler.source 和 maven.compiler.target 属性,你可以确保 Maven 使用正确的 Java 版本进行编译,并生成符合目标环境的字节码。

maven.compiler.compilerVersion

maven.compiler.compilerVersion 是 Maven 中的一个属性,它用于指定编译器编译源代码的版本。

在 Maven 的 pom.xml 文件中,你可以通过在 <properties> 标签中设置 maven.compiler.compilerVersion 属性来指定编译器编译源代码的版本。例如,要将编译器版本设置为 1.8,你可以在 pom.xml 文件中添加以下代码:

xml 复制代码
<properties>
  <maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion>
</properties>

这将告诉 Maven 使用 Java 1.8 版本的编译器来编译源代码。你可以根据需要将 maven.compiler.compilerVersion 属性设置为其他编译器版本。

请注意,maven.compiler.compilerVersion 属性并不是必需的。如果你没有设置该属性,Maven 将使用默认的编译器版本,这通常是系统上安装的默认 Java 版本。

另外,如果你已经设置了 maven.compiler.source 和 maven.compiler.target 属性来指定编译器编译源代码的 Java 版本和生成目标字节码的 Java 版本,那么这些属性将优先于 maven.compiler.compilerVersion 属性。这意味着如果你没有显式设置 maven.compiler.compilerVersion 属性,Maven 将使用与 maven.compiler.source 和 maven.compiler.target 属性指定的 Java 版本相对应的编译器版本。

maven在settings.xm和pom.xml中指定jdk版本编译

maven的settings.xm和pom.xml都可以通过 maven.compiler.source , maven.compiler.target 这两个属性值来指定jdk版本

  • maven.compiler.source

  • maven.compiler.target

xml 复制代码
maven.compiler.source
xml 复制代码
maven.compiler.target

在pom.xml中的位置

xml 复制代码
<project>
  <properties>
    <maven.compiler.source>21</maven.compiler.source>
    <maven.compiler.target>21</maven.compiler.target>
  </properties>
</project>

在settings.xml中的位置

xml 复制代码
<settings>
    <profiles>
        <profile>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
            <properties>
                <maven.compiler.source>21</maven.compiler.source>
                <maven.compiler.target>21</maven.compiler.target>  <!-- JRE System Liblary 的版本和这句相同  -->
            </properties>
        </profile>
    </profiles>
</settings>

在spring项目中, 用java.version来统一设置

maven的settings.xm和pom.xml也可以通过设定 maven-compiler-plugin 这个插件来指定jdk版本

xml 复制代码
<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>3.9.6</version>
    <configuration>
        <source>21</source>
        <target>21</target>
    </configuration>
</plugin>

在pom.xml中的位置

xml 复制代码
<project>
  ...
  <build>
    ...
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.9.6</version>
        <configuration>
          <source>21</source>
          <target>21</target>
        </configuration>
      </plugin>
    </plugins>
    ...
  </build>
  ...
</project>

在settings.xml中的位置 , 好像用不了

xml 复制代码
<settings>
  ...
  <profiles>
    <profile>
      <id>profile-maven-compiler-plugin</id>
      <activation>
        <activeByDefault>true</activeByDefault>
      </activation>
      <build>
        <plugins>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.9.6</version>
            <configuration>
              <source>17</source>
              <target>17</target>
            </configuration>
          </plugin>
        </plugins>
      </build>
    </profile>
  </profiles>
  ...
</settings>

Maven 在 settings.xml 中指定jdk版本

settings.xml 中的属性写在 setting👉profiles👉profile👉properties中,位于第5层

方法一, 直接写死, 例如指定jdk21
xml 复制代码
<settings>
    <profiles>
        <profile>
            <id>jdk-version-21</id>
            <!-- id和activation都可以用于激活该profile, 定义id可以在activeProfiles的activeProfile里设置该id从而激活该id代表的profile, id和activation可以只保留一个,也可两个都使用.  -->
            <activation>
                <activeByDefault>true</activeByDefault> <!-- 该profile是否默认激活, 不激活的话, 下面的properties是否默认生效, 这里设为true就能激活该profile从而使属性生效. 下方又用<activeProfile>jdk-version-21</activeProfile>再次确保该profile激活 -->
            </activation>
            <!--要使properties起作用, properties所属的profile必须在激活状态  -->
            <properties>
                <maven.compiler.source>21</maven.compiler.source>
                <maven.compiler.target>21</maven.compiler.target>  <!-- JRE System Liblary 的版本和这句相同  -->
            </properties>
        </profile>
    </profiles>
    <!--  activeProfiles里的activeProfile对应profiles里的profile的id; 是激活profile的方式之一; 在activeProfiles中激活的profile可以不要activation标签了-->
    <!--  activeProfiles与profiles同级是第二级, profile是第三级, settings → activeProfiles → activeProfile  ,  activeProfile可以有多个-->
    <activeProfiles>
        <!-- 要激活的profile的id , 在这里激活了的profile里的activation就无效了,可以去掉,当然也可以保留-->
        <activeProfile>jdk-version-21</activeProfile>  <!-- 要激活的profile的id . 这里和上面该id的profile中的 <activeByDefault>true</activeByDefault> 任一个都能激活该id代表的profile, 两处设置确保启用该profile-->
    </activeProfiles>
</settings>

去掉注释

xml 复制代码
    <profiles>
        <profile>
            <id>jdk-version-21</id>
            <activation>
                <activeByDefault>true</activeByDefault> <!-- 该profile是否默认激活, 不激活的话, 下面的properties是否默认生效, 这里设为true就能激活该profile从而使属性生效. 下方又用<activeProfile>jdk-version-21</activeProfile>再次确保该profile激活 -->
            </activation>
            <properties>
                <maven.compiler.source>21</maven.compiler.source>
                <maven.compiler.target>21</maven.compiler.target>  <!-- JRE System Liblary 的版本和这句相同  -->
            </properties>
        </profile>
    </profiles>
    <activeProfiles>
        <activeProfile>jdk-version-21</activeProfile>  <!-- 要激活的profile的id . 这里和上面该id的profile中的 <activeByDefault>true</activeByDefault> 任一个都能激活该id代表的profile, 两处设置确保启用该profile-->
    </activeProfiles>

只用 <activeByDefault>true</activeByDefault> 激活, 可以不要 <id>jdk-version-21</id>和 <activeProfile>jdk-version-21</activeProfile>

xml 复制代码
    <profiles>
        <profile>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
            <properties>
                <maven.compiler.source>21</maven.compiler.source>
                <maven.compiler.target>21</maven.compiler.target>  <!-- JRE System Liblary 的版本和这句相同  -->
            </properties>
        </profile>
    </profiles>

只用 <activeProfile>jdk-version-21</activeProfile> 激活 , 则可以不要

xml 复制代码
    <profiles>
        <profile>
            <id>jdk-version-21</id>
            <properties>
                <maven.compiler.source>21</maven.compiler.source>
                <maven.compiler.target>21</maven.compiler.target>  <!-- JRE System Liblary 的版本和这句相同  -->
            </properties>
        </profile>
    </profiles>
    <activeProfiles>
        <activeProfile>jdk-version-21</activeProfile>
    </activeProfiles>
引用属性变量,只在一个地方修设值jdk版本
xml 复制代码
<settings>
    <profiles>
        <profile>
            <id>set-jdk-version</id>
            <!-- id和activation都可以用于激活该profile, 定义id可以在activeProfiles的activeProfile里设置该id从而激活该id代表的profile, id和activation可以只保留一个,也可两个都使用.  -->
            <activation>
                <activeByDefault>true</activeByDefault> <!-- 该profile是否默认激活, 不激活的话, 下面的properties是否默认生效, 这里设为true就能激活该profile从而使属性生效. 下方又用<activeProfile>jdk-version-21</activeProfile>再次确保该profile激活 -->
            </activation>
            <!--要使properties起作用, properties所属的profile必须在激活状态  -->
            <properties>
                <jdk-version>21</jdk-version> <!--自定义一个属性用来设置版本,之后可以用${该属性名引用},就不用多处修改了-->
                <maven.compiler.source>${jdk-version}</maven.compiler.source>
                <maven.compiler.target>${jdk-version}</maven.compiler.target>  <!-- JRE System Library 的版本和这句相同  -->
            </properties>
        </profile>
    </profiles>
    <!--  activeProfiles里的activeProfile对应profiles里的profile的id; 是激活profile的方式之一; 在activeProfiles中激活的profile可以不要activation标签了-->
    <!--  activeProfiles与profiles同级是第二级, profile是第三级, settings → activeProfiles → activeProfile  ,  activeProfile可以有多个-->
    <activeProfiles>
        <!-- 要激活的profile的id , 在这里激活了的profile里的activation就无效了,可以去掉,当然也可以保留-->
        <activeProfile>set-jdk-version</activeProfile>  <!-- 要激活的profile的id . 这里和上面该id的profile中的 <activeByDefault>true</activeByDefault> 任一个都能激活该id代表的profile, 两处设置确保启用该profile-->
    </activeProfiles>
</settings>

一处设置,双重激活

xml 复制代码
    <profiles>
        <profile>
            <id>set-JdkVersion</id>
            <activation>
                <activeByDefault>true</activeByDefault> <!-- 该profile是否默认激活, 不激活的话, 下面的properties是否默认生效, 这里设为true就能激活该profile从而使属性生效. 下方又用<activeProfile>JdkVersion-21</activeProfile>再次确保该profile激活 -->
            </activation>
            <properties>
                <JdkVersion>21</JdkVersion> <!--自定义一个属性用来设置版本,之后可以用${该属性名引用},就不用多处修改了-->
                <maven.compiler.source>${JdkVersion}</maven.compiler.source>
                <maven.compiler.target>${JdkVersion}</maven.compiler.target>  <!-- JRE System Library 的版本和这句相同  -->
            </properties>
        </profile>
    </profiles>
    <activeProfiles>
        <activeProfile>set-JdkVersion</activeProfile>  <!-- 要激活的profile的id . 这里和上面该id的profile中的 <activeByDefault>true</activeByDefault> 任一个都能激活该id代表的profile, 两处设置确保启用该profile-->
    </activeProfiles>

Maven 在 pom.xml 中指定jdk版本

在pom.xml中可以用设置属性或者设置插件两种方法来设置jdk版本

  • 用设置属性的方式
xml 复制代码
<project>
  <properties>
    <maven.compiler.source>21</maven.compiler.source>
    <maven.compiler.target>21</maven.compiler.target>
  </properties>
</project>
xml 复制代码
    <maven.compiler.source>21</maven.compiler.source>
    <maven.compiler.target>21</maven.compiler.target>
  • 用设置插件的方式 , 设置插件的方式优先级高于设置属性
xml 复制代码
<project>
  ...
  <build>
    ...
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <!-- <version>3.9.6</version> --> <!-- 可以不要version -->
        <configuration>
          <source>21</source>
          <target>21</target>
        </configuration>
      </plugin>
    </plugins>
    ...
  </build>
  ...
</project>
  • 用设置插件的方式 , 设置插件的方式优先级高于设置属性
xml 复制代码
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <!-- <version>3.9.6</version> --> <!-- 可以不要version -->
        <configuration>
          <source>21</source>
          <target>21</target>
        </configuration>
      </plugin>
    </plugins>

两种方法都用上, , 插件的优先级高于属性

xml 复制代码
  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <JdkVersionOfThisPom>17</JdkVersionOfThisPom>
    <java.version>${JdkVersionOfThisPom}</java.version>
    <maven.compiler.source>${JdkVersionOfThisPom}</maven.compiler.source>
    <maven.compiler.target>${JdkVersionOfThisPom}</maven.compiler.target>
    <maven.compiler.compilerVersion>${JdkVersionOfThisPom}</maven.compiler.compilerVersion>
  </properties>
  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
<!--        <version>3.9.6</version>-->
        <configuration>
          <source>${JdkVersionOfThisPom}</source>
          <target>${JdkVersionOfThisPom}</target>
          <compilerVersion>${JdkVersionOfThisPom}</compilerVersion>
        </configuration>
      </plugin>
    </plugins>
  </build>
相关推荐
一隅论数智3 天前
给AI一张“业务概念地图“:本体如何从哲学走向企业智能
大数据·人工智能·经验分享·笔记·学习·学习方法·政务
深圳老胡3 天前
STM32F407 控制 L6470 步进电机驱动 —— 控制过程简介
笔记·stm32·单片机·嵌入式硬件·代码规范
Because_of_Her13 天前
并查集-听课笔记
笔记·算法·并查集
彧azz3 天前
Linux 环境下 Redis 学习总结:数据类型、持久化、锁、事务、主从与缓存问题
linux·redis·笔记·学习·面试
陈卫军老师3 天前
陈卫军:把口味写在一张纸上,店才稳得住
经验分享·笔记·流量运营
`流年づ3 天前
人工智能学习笔记 - 补充
人工智能·笔记·深度学习·学习
qeen873 天前
【Linux】操作系统之进程介绍(二)
linux·笔记·学习·进程
从零开始的嵌入式之旅3 天前
day47
arm开发·经验分享·笔记·嵌入式硬件
陈年老古董3 天前
MediaPipe 姿态检测与脸部关键点检测
笔记·python·opencv·学习·dlib
彧azz3 天前
操作系统时间管理与系统核心板块学习总结
c语言·笔记·学习·系统架构