当前位置: 首页 > news >正文

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

    <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

<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

<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

<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 文件中添加以下代码:

<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 文件中添加以下代码:

<properties><maven.compiler.target>1.8</maven.compiler.target>
</properties>

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


maven.compiler.target

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

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

<properties><maven.compiler.source>1.8</maven.compiler.source><maven.compiler.target>1.8</maven.compiler.target>
</properties>

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


maven.compiler.compilerVersion

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

在 Maven 的 pom.xml 文件中,你可以通过在 <properties> 标签中设置 maven.compiler.compilerVersion 属性来指定编译器编译源代码的版本。例如,要将编译器版本设置为 1.8,你可以在 pom.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.sourcemaven.compiler.target 属性来指定编译器编译源代码的 Java 版本和生成目标字节码的 Java 版本,那么这些属性将优先于 maven.compiler.compilerVersion 属性。这意味着如果你没有显式设置 maven.compiler.compilerVersion 属性,Maven 将使用与 maven.compiler.sourcemaven.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

maven.compiler.source
maven.compiler.target

在pom.xml中的位置

<project><properties><maven.compiler.source>21</maven.compiler.source><maven.compiler.target>21</maven.compiler.target></properties>
</project>

在settings.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版本

<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中的位置

<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中的位置 , 好像用不了

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

去掉注释

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

    <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> 激活 , 则可以不要

    <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版本
<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>

一处设置,双重激活

    <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版本

  • 用设置属性的方式
<project><properties><maven.compiler.source>21</maven.compiler.source><maven.compiler.target>21</maven.compiler.target></properties>
</project>
    <maven.compiler.source>21</maven.compiler.source><maven.compiler.target>21</maven.compiler.target>
  • 用设置插件的方式 , 设置插件的方式优先级高于设置属性
<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>
  • 用设置插件的方式 , 设置插件的方式优先级高于设置属性
    <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>

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

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

相关文章:

  • 【嵌入式开发 Linux 常用命令系列 4.2 -- .repo 各个目录介绍】
  • 使用cmake构建Qt6.6的qt quick项目,添加应用程序图标的方法
  • 软件兼容性测试:保障多样化用户体验的重要功能
  • 数据分析基础之《matplotlib(5)—直方图》
  • 分布式环境认证和授权-基于springboot+JWT+拦截器实现-实操+源码下载
  • 什么是 AWS IAM?如何使用 IAM 数据库身份验证连接到 Amazon RDS(上)
  • 【python中类的介绍】
  • jquery实现省市区三级联动
  • 线性回归与逻辑回归:深入解析机器学习的基石模型
  • 计算机网络:应用层(一)
  • web如何实现录制音频,满满干货(上篇)
  • 大文件分割,合并------C++ ------fstream
  • OpenCL学习笔记(三)手动编译开发库(win10+mingw64)
  • leetcode 101.对称二叉树
  • iphone/安卓手机如何使用burp抓包
  • php的引用
  • (三)从jvm层面了解线程的启动和停止
  • 【跃迁之路】【585天】程序员高效学习方法论探索系列(实验阶段342-2018.09.13)...
  • Android开源项目规范总结
  • Apache Pulsar 2.1 重磅发布
  • Bootstrap JS插件Alert源码分析
  • ES6--对象的扩展
  • hadoop集群管理系统搭建规划说明
  • Java超时控制的实现
  • Java多线程(4):使用线程池执行定时任务
  • JS函数式编程 数组部分风格 ES6版
  • Linux快速配置 VIM 实现语法高亮 补全 缩进等功能
  • Logstash 参考指南(目录)
  • springMvc学习笔记(2)
  • v-if和v-for连用出现的问题
  • webpack入门学习手记(二)
  • 巧用 TypeScript (一)
  • postgresql行列转换函数
  • ​卜东波研究员:高观点下的少儿计算思维
  • ​软考-高级-系统架构设计师教程(清华第2版)【第1章-绪论-思维导图】​
  • ​一些不规范的GTID使用场景
  • # centos7下FFmpeg环境部署记录
  • # 数据结构
  • #AngularJS#$sce.trustAsResourceUrl
  • #图像处理
  • #预处理和函数的对比以及条件编译
  • (AtCoder Beginner Contest 340) -- F - S = 1 -- 题解
  • (C语言)输入一个序列,判断是否为奇偶交叉数
  • (java版)排序算法----【冒泡,选择,插入,希尔,快速排序,归并排序,基数排序】超详细~~
  • (Java岗)秋招打卡!一本学历拿下美团、阿里、快手、米哈游offer
  • (vue)el-checkbox 实现展示区分 label 和 value(展示值与选中获取值需不同)
  • (附源码)ssm户外用品商城 毕业设计 112346
  • (介绍与使用)物联网NodeMCUESP8266(ESP-12F)连接新版onenet mqtt协议实现上传数据(温湿度)和下发指令(控制LED灯)
  • (实战篇)如何缓存数据
  • (转)真正的中国天气api接口xml,json(求加精) ...
  • .NET 6 在已知拓扑路径的情况下使用 Dijkstra,A*算法搜索最短路径
  • .net CHARTING图表控件下载地址
  • .NET Core中的去虚
  • .NET MVC之AOP
  • .net 简单实现MD5