Skip to content

Commit

Permalink
Add load() statements for the builtin Bazel java rules
Browse files Browse the repository at this point in the history
Loads are being added in preparation for moving the rules out of Bazel and into `rules_java`.

PiperOrigin-RevId: 622922174
  • Loading branch information
java-team-github-bot authored and Dagger Team committed Apr 8, 2024
1 parent 6722bb3 commit 18ce1b5
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 9 deletions.
10 changes: 10 additions & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,16 @@ load("@bazel_skylib//:workspace.bzl", "bazel_skylib_workspace")

bazel_skylib_workspace()

#############################
# Load rules_java repository
#############################

http_archive(
name = "rules_java",
sha256 = "c73336802d0b4882e40770666ad055212df4ea62cfa6edf9cb0f9d29828a0934",
url = "https://github.com/bazelbuild/rules_java/releases/download/5.3.5/rules_java-5.3.5.tar.gz",
)

####################################################
# Load Protobuf repository (needed by bazel-common)
####################################################
Expand Down
7 changes: 3 additions & 4 deletions java/dagger/testing/compile/macros.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
# 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.

"""Macros for building compiler tests."""

load("@rules_java//java:defs.bzl", "java_binary", "java_test")
load("@io_bazel_rules_kotlin//kotlin:kotlin.bzl", "kt_jvm_library")

def compiler_test(name, size = "large", compiler_deps = None, **kwargs):
Expand All @@ -35,7 +35,7 @@ def compiler_test(name, size = "large", compiler_deps = None, **kwargs):

# This JAR is loaded at runtime and contains the dependencies used by the compiler during tests.
# We separate these dependencies from the java_test dependencies to avoid 1 version violations.
native.java_binary(
java_binary(
name = name + "_compiler_deps",
testonly = 1,
tags = ["notap"],
Expand All @@ -54,8 +54,7 @@ def compiler_test(name, size = "large", compiler_deps = None, **kwargs):
if kwargs.get("srcs", None):
# Add a dep to allow usage of CompilerTests.
kwargs["deps"] = kwargs.get("deps", []) + ["//java/dagger/testing/compile"]

native.java_test(name = name, size = size, **kwargs)
java_test(name = name, size = size, **kwargs)

def kt_compiler_test(name, srcs = [], deps = [], **kwargs):
"""Generates a java_test that tests java compilation with the given compiler deps.
Expand Down
10 changes: 8 additions & 2 deletions tools/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,19 @@ exports_files([
bzl_library(
name = "maven_bzl",
srcs = ["maven.bzl"],
deps = [":maven_info_bzl"],
deps = [
":maven_info_bzl",
"@rules_java//java:rules",
],
)

bzl_library(
name = "maven_info_bzl",
srcs = ["maven_info.bzl"],
deps = ["@bazel_skylib//lib:unittest"],
deps = [
"@bazel_skylib//lib:unittest",
"@rules_java//java:rules",
],
)

bzl_library(
Expand Down
4 changes: 2 additions & 2 deletions tools/maven.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@
# 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.

"""Macros to simplify generating maven files.
"""

load("@google_bazel_common//tools/jarjar:jarjar.bzl", "jarjar_library")
load("@google_bazel_common//tools/javadoc:javadoc.bzl", "javadoc_library")
load("@google_bazel_common//tools/maven:pom_file.bzl", default_pom_file = "pom_file")
load("@rules_java//java:defs.bzl", "java_binary")
load(":maven_info.bzl", "MavenInfo", "collect_maven_info")

SHADED_MAVEN_DEPS = [
Expand Down Expand Up @@ -290,7 +290,7 @@ def _gen_maven_artifact(
# Build an empty javadoc because Sonatype requires javadocs
# even if the jar is empty.
# https://central.sonatype.org/pages/requirements.html#supply-javadoc-and-sources
native.java_binary(
java_binary(
name = name + "-javadoc",
)

Expand Down
3 changes: 2 additions & 1 deletion tools/maven_info.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"""Skylark rules to collect Maven artifacts information.
"""

load("@rules_java//java:defs.bzl", "java_library")
load("@bazel_skylib//lib:unittest.bzl", "asserts", "unittest")

# TODO(b/142057516): Unfork this file once we've settled on a more general API.
Expand Down Expand Up @@ -105,7 +106,7 @@ def _fake_java_library(name, deps = None, exports = None, is_artifact = True):
outs = src_file,
cmd = "echo 'package pkg; class %s {}' > $@" % name,
)
native.java_library(
java_library(
name = name,
srcs = src_file,
tags = ["maven_coordinates=%s:_:_" % name] if is_artifact else [],
Expand Down

0 comments on commit 18ce1b5

Please sign in to comment.