maven toolchains 简单说明

很多时候我们项目可以会包含需要不同jdk 构建,比如有些只能使用jdk8,有些需要使用jdk11,toolchains 可以帮助我们解决此问题

一般玩法

创建一个toolchains.xml 目录,放到home 目录下,里边配置实际需要的jdk 版本(我们的环境可以安装多jdk)
项目构建的时候(使用的插件)使用配置的工具

  • 参考配置
 
<?xml version="1.0" encoding="UTF-8"?>
<toolchains>
  <toolchain>
    <type>jdk</type>
    <provides>
      <version>1.8</version>
      <vendor>zulu</vendor>
    </provides>
    <configuration>
      <jdkHome>...../8.0.382-zulu</jdkHome>
    </configuration>
  </toolchain>
  <toolchain>
    <type>jdk</type>
    <provides>
      <version>11</version>
      <vendor>zulu</vendor>
    </provides>
    <configuration>
      <jdkHome>...../11.0.20-zulu</jdkHome>
    </configuration>
  </toolchain>
</toolchains>
  • 项目使用
<plugin>
  <artifactId>maven-surefire-plugin</artifactId>
  <configuration>
    <!-- Need to run with Java 8, because `GuavaPatcher` runs too late, and
     `com.google.common.base.Stopwatch` has already been loaded. GuavaPatcher
      tries to re-define the Stopwatch class in the same classloader, but Java
      Java 11 no longer allows this. The existing workaround with that
      `GuavaPatcherRunner` runs into the same issue. A proper solution would be
      to implement a Java agent, which _is_ allowed to re-define classes.
      -->
    <jdkToolchain>
      <version>1.8</version>
    </jdkToolchain>
  </configuration>
</plugin>

说明

比如dremio 目前构建就需要配置toolchains,依赖的一些包构建只能使用jdk8

参考资料

https://maven.apache.org/guides/mini/guide-using-toolchains.html

posted on   荣锋亮  阅读(397)  评论(0编辑  收藏  举报

相关博文:
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· .NET10 - 预览版1新功能体验(一)
历史上的今天:
2019-12-21 使用threaddump-analyzer 快速查看jvm thread 状态信息
2018-12-21 nginx http2 push 试用
2018-12-21 几个方便进行micro frontend 开发的工具&&类库
2018-12-21 Compoxure example 应用说明
2018-12-21 Compoxure 微服务组合proxy 中间件
2018-12-21 SCS Characteristics
2017-12-21 sqlopsstudio 微软开源跨平台sql server 连接工具

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
点击右上角即可分享
微信分享提示