对于java_library,我可以在构建规则上设置javacopts属性。对于java_proto_libraryjava_lite_proto_library,似乎没有任何相似之处。
我可以通过bazel的-source标志将-target-javacopt选项设置为javac来解决这个问题,但我宁愿将其编码到构建文件中。

最佳答案

您可以添加一个jdk7工具链,然后用它构建所有东西。例如,将this添加到生成文件:

java_toolchain(
    name = "jdk7",
    bootclasspath = ["@bazel_tools//tools/jdk:bootclasspath"],
    encoding = "UTF-8",
    extclasspath = ["@bazel_tools//tools/jdk:extdir"],
    genclass = ["@bazel_tools//tools/jdk:GenClass_deploy.jar"],
    header_compiler = ["@bazel_tools//tools/jdk:turbine_deploy.jar"],
    ijar = ["@bazel_tools//tools/jdk:ijar"],
    javabuilder = ["@bazel_tools//tools/jdk:JavaBuilder_deploy.jar"],
    javac = ["@bazel_tools//third_party/java/jdk/langtools:javac_jar"],
    javac_supports_workers = 1,
    jvm_opts = [
        "-XX:+TieredCompilation",
        "-XX:TieredStopAtLevel=1",
    ],
    singlejar = ["@bazel_tools//tools/jdk:SingleJar_deploy.jar"],
    source_version = "7",
    target_version = "7",
    visibility = ["//visibility:public"],
)

然后使用:
bazel build --java_toolchain=//whatever:jdk7 //your:target

关于java - 如何获得java_proto_library的1.7兼容输出?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/43354237/

10-10 09:10