Step1:配置jdk toolchain环境

log4j需要的jdk有多个版本:

  1. 默认jdk:1.7以上
  2. jdk9
  3. jdk11

当有了这些jdk之后,修改toolchains-sample-mac.xml文件,设置这几个版本的JAVAHOME路径:

<?xml version="1.0" encoding="UTF8"?>
<!--
  ~ Licensed to the Apache Software Foundation (ASF) under one or more
  ~ contributor license agreements. See the NOTICE file distributed with
  ~ this work for additional information regarding copyright ownership.
  ~ The ASF licenses this file to You under the Apache license, Version 2.0
  ~ (the "License"); you may not use this file except in compliance with
  ~ the License. You may obtain a copy of the License at
  ~
  ~      http://www.apache.org/licenses/LICENSE-2.0
  ~
  ~ Unless required by applicable law or agreed to in writing, software
  ~ distributed under the License is distributed on an "AS IS" BASIS,
  ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  ~ See the license for the specific language governing permissions and
  ~ limitations under the license.
  -->
<toolchains>
  <!-- JDK toolchains -->
  <toolchain>
    <type>jdk</type>
    <provides>
      <version>1.7</version>
      <vendor>sun</vendor>
    </provides>
    <configuration>
      <jdkHome>/Library/Java/JavaVirtualMachines/jdk1.7.0_80.jdk/Contents/Home</jdkHome>
    </configuration>
  </toolchain>
  <toolchain>
    <type>jdk</type>
    <provides>
      <version>1.8</version>
      <vendor>sun</vendor>
    </provides>
    <configuration>
      <jdkHome>/Library/Java/JavaVirtualMachines/jdk1.8.0_281.jdk/Contents/Home</jdkHome>
    </configuration>
  </toolchain>
  <toolchain>
    <type>jdk</type>
    <provides>
      <version>9</version>
      <vendor>sun</vendor>
    </provides>
    <configuration>
      <jdkHome>/Library/Java/JavaVirtualMachines/jdk-9.0.4.jdk/Contents/Home</jdkHome>
    </configuration>
  </toolchain>
  <toolchain>
    <type>jdk</type>
    <provides>
      <version>11</version>
      <vendor>sun</vendor>
    </provides>
    <configuration>
      <jdkHome>/Library/Java/JavaVirtualMachines/jdk-11.0.12.jdk/Contents/Home</jdkHome>
    </configuration>
  </toolchain>
 
  <!-- other toolchains -->
</toolchains>

Step2:修改zip的引用

有些包是通过zip引用的,但是我们打包之后的jar,所以要把zip的引用变成jar的引用,全局搜索<type>zip</type>,如果没有version标签的话自己添加version标签为<version>2.14.0</version>
image.png
修改成如下的内容:
image.png

Step3:修改maven的默认JAVA_HOME

由于我是用homebrew安装的maven,导致maven的JAVA_HOME被设置到了系统的openjdk下,所以需要改一下,不然会报错找不到jconsole
image.png
改起来也很简单,在命令行export一个JAVA_HOME的环境变量即可:
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_281.jdk/Contents/Home

Step4:构建codeql database

codeql database create --language=java --command="mvn clean compile -Dmaven.test.skip -t toolchains-sample-mac.xml" --overwrite ../../codedb/log4j2-2.14.0