bazel: incompatible_load_java_rules_from_bzl: load the Java rules from @rules_java

Flag: --incompatible_load_java_rules_from_bzl Available since: 0.28 Will be flipped in: 1.0 Tracking issue: #8741

java_library, java_binary, java_test, java_import, java_lite_proto_library, java_proto_library, java_package_configuration, java_plugin, java_runtime, java_toolchain have to be loaded from @rules_java.

For example if you are using java_library, add the following load statement to your BUILD/bzl file. load(“@rules_java//java:defs.bzl”, “java_library”)

Migration

Add rules_java repositories to your WORKSPACE file and load its dependecies:

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
http_archive(
    name = "rules_java",
    url = "https://github.com/bazelbuild/rules_java/releases/download/0.1.1/rules_java-0.1.1.tar.gz",
    sha256 = "220b87d8cfabd22d1c6d8e3cdb4249abd4c93dcc152e0667db061fb1b957ee68",
)
load("@rules_java//java:repositories.bzl", "rules_java_dependencies", "rules_java_toolchains")
rules_java_dependencies()
rules_java_toolchains()

Fix all your BUILD files that use Java rules to include the load statement. Use buildifier to automatically update all your BUILD files:

buildifier --lint=fix -warnings=native-java -r path/to/your/workspace/root/dir

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 20 (16 by maintainers)

Commits related to this issue

Most upvoted comments

@iirina Can we update the description to include the load statement so users will know to include them?

load("@rules_java//java:repositories.bzl", "rules_java_dependencies", "rules_java_toolchains")
rules_java_dependencies()
rules_java_toolchains()