Skip to content

Commit

Permalink
Load JavaInfo and java_common from rules_java (#1027)
Browse files Browse the repository at this point in the history
This prepares rules_jvm_external for bazelbuild/bazel#19455

Closes #967 which has been left in limbo.
  • Loading branch information
shs96c authored Jan 15, 2024
1 parent d2d1888 commit b0c1d02
Show file tree
Hide file tree
Showing 12 changed files with 57 additions and 0 deletions.
3 changes: 3 additions & 0 deletions BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ bzl_library(
# stardoc.
"//visibility:public",
],
deps = [
"@rules_java//java:rules",
],
)

alias(
Expand Down
4 changes: 4 additions & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ bazel_dep(
name = "platforms",
version = "0.0.8",
)
bazel_dep(
name = "rules_java",
version = "7.3.2",
)
bazel_dep(
name = "rules_kotlin",
version = "1.9.0",
Expand Down
2 changes: 2 additions & 0 deletions private/rules/has_maven_deps.bzl
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
load("@rules_java//java:defs.bzl", "JavaInfo")

MavenInfo = provider(
fields = {
# Fields to do with maven coordinates
Expand Down
1 change: 1 addition & 0 deletions private/rules/javadoc.bzl
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
load("@rules_java//java:defs.bzl", "JavaInfo")
load(":maven_project_jar.bzl", "DEFAULT_EXCLUDED_WORKSPACES")

_JavadocInfo = provider(
Expand Down
1 change: 1 addition & 0 deletions private/rules/jvm_import.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
# [0]: https://github.com/square/bazel_maven_repository/pull/48
# [1]: https://github.com/bazelbuild/bazel/issues/4549

load("@rules_java//java:defs.bzl", "JavaInfo")
load("//settings:stamp_manifest.bzl", "StampManifestProvider")

def _jvm_import_impl(ctx):
Expand Down
1 change: 1 addition & 0 deletions private/rules/maven_bom_fragment.bzl
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
load("@rules_java//java:defs.bzl", "JavaInfo")
load(":has_maven_deps.bzl", "MavenInfo", "has_maven_deps")

MavenBomFragmentInfo = provider(
Expand Down
1 change: 1 addition & 0 deletions private/rules/maven_project_jar.bzl
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
load("@rules_java//java:defs.bzl", "JavaInfo", "java_common")
load(":has_maven_deps.bzl", "MavenInfo", "calculate_artifact_jars", "calculate_artifact_source_jars", "has_maven_deps")
load(":maven_utils.bzl", "determine_additional_dependencies")

Expand Down
1 change: 1 addition & 0 deletions private/rules/pom_file.bzl
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
load("@rules_java//java:defs.bzl", "JavaInfo")
load(":has_maven_deps.bzl", "MavenInfo", "calculate_artifact_jars", "has_maven_deps")
load(":maven_utils.bzl", "determine_additional_dependencies", "generate_pom")

Expand Down
33 changes: 33 additions & 0 deletions repositories.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,39 @@ def rules_jvm_external_deps(repositories = _DEFAULT_REPOSITORIES):
],
)

# The `rules_java` major version is tied to the major version of Bazel that it supports,
# so this is different from the version in the MODULE file.
major_version = native.bazel_version.partition(".")[0]
if major_version == "5":
maybe(
http_archive,
name = "rules_java",
urls = [
"https://github.com/bazelbuild/rules_java/releases/download/5.5.1/rules_java-5.5.1.tar.gz",
],
sha256 = "73b88f34dc251bce7bc6c472eb386a6c2b312ed5b473c81fe46855c248f792e0",
)

elif major_version == "6":
maybe(
http_archive,
name = "rules_java",
urls = [
"https://github.com/bazelbuild/rules_java/releases/download/6.5.2/rules_java-6.5.2.tar.gz",
],
sha256 = "16bc94b1a3c64f2c36ceecddc9e09a643e80937076b97e934b96a8f715ed1eaa",
)

else:
maybe(
http_archive,
name = "rules_java",
urls = [
"https://github.com/bazelbuild/rules_java/releases/download/7.3.2/rules_java-7.3.2.tar.gz",
],
sha256 = "3121a00588b1581bd7c1f9b550599629e5adcc11ba9c65f482bbd5cfe47fdf30",
)

maven_install(
name = "rules_jvm_external_deps",
artifacts = [
Expand Down
8 changes: 8 additions & 0 deletions setup.bzl
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
load("@bazel_skylib//:workspace.bzl", "bazel_skylib_workspace")
load("@rules_java//java:repositories.bzl", "rules_java_dependencies", "rules_java_toolchains")
load("@rules_jvm_external_deps//:defs.bzl", "pinned_maven_install")

def rules_jvm_external_setup():
bazel_skylib_workspace()

# When using bazel 5, we have undefined toolchains from rules_js. This should be fine to skip, since we only need
# it for the `JavaInfo` definition.
major_version = native.bazel_version.partition(".")[0]
if major_version != "5":
rules_java_dependencies()
rules_java_toolchains()
pinned_maven_install()
1 change: 1 addition & 0 deletions tests/unit/aar_import/aar_import_test.bzl
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
load("@bazel_skylib//lib:unittest.bzl", "analysistest", "asserts")
load("@rules_java//java:defs.bzl", "JavaInfo")

def _does_aar_import_have_srcjar_impl(ctx):
env = analysistest.begin(ctx)
Expand Down
1 change: 1 addition & 0 deletions tests/unit/exports/exports_test.bzl
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Unit tests for exports."""

load("@bazel_skylib//lib:unittest.bzl", "analysistest", "asserts")
load("@rules_java//java:defs.bzl", "JavaInfo")
load("//private/rules:has_maven_deps.bzl", "MavenInfo", "has_maven_deps")
load("//private/rules:maven_project_jar.bzl", "maven_project_jar")

Expand Down

0 comments on commit b0c1d02

Please sign in to comment.