Как указать версию Java с Bazel - PullRequest
0 голосов
/ 26 октября 2019

Я использую Bazel для создания и тестирования проекта Java. Кажется, он компилируется с JDK10, который он откуда-то скачал. Хотел бы уточнить, что он использует JDK13.

Как мне это сделать? это то, что я могу положить в файл .bazelrc или BUILD? Действительно проблемы с этим.

1 Ответ

2 голосов
/ 29 октября 2019

java_toolchain, кажется, делает трюк:

Например:

В вашем BUILD файле добавьте:

java_toolchain(
    name = "bootstrap_toolchain",
    # javac -extdirs is implemented by appending the contents to the platform
    # class path after -bootclasspath. For convenience, we currently have a
    # single jar that contains the contents of both the bootclasspath and
    # extdirs.
    bootclasspath = ["//tools/jdk:platformclasspath.jar"],
    extclasspath = [],
    genclass = ["bootstrap_genclass_deploy.jar"],
    ijar = ["//third_party/ijar"],
    javabuilder = ["bootstrap_VanillaJavaBuilder_deploy.jar"],
    javac = ["//third_party/java/jdk/langtools:javac_jar"],
    jvm_opts = [
        # Prevent "Could not reserve enough space for object heap" errors on Windows.
        "-Xmx512m",
        # Using tiered compilation improves performance of Javac when not using the worker mode.
        "-XX:+TieredCompilation",
        "-XX:TieredStopAtLevel=1",
    ],
    singlejar = ["//src/java_tools/singlejar:bootstrap_deploy.jar"],
    source_version = "8",
    tags = ["manual"],
    target_version = "8",
    visibility = ["//visibility:public"],
)

.bazelrc

build --java_toolchain=//:bootstrap_toolchain
...