Mixed Scala/Java, fixed scala_rules for latest JDK

Using latest JDK (after proper GraalVM integration) broke compilation of
Scala projects due to a problem with SecurityManager in `scala_rules`.
Workaround it by having custom toolchain.

Added example BUILD for mixed Scala/Java project with a small number of
dependencies.
This commit is contained in:
Hubert Plociniczak 2024-04-25 15:25:04 +02:00
parent cd8f504b17
commit fede7efca4
9 changed files with 174 additions and 30 deletions

View File

@ -1,19 +1,2 @@
load("@npm//:defs.bzl", "npm_link_all_packages")
npm_link_all_packages(name = "node_modules")
## Discover dependencies via
## > bazel build <target> --extra_toolchains=//:plus_one_strict_deps_filter
load("@io_bazel_rules_scala//scala:scala_toolchain.bzl", "scala_toolchain")
toolchain(
name = "plus_one_strict_deps_filter",
toolchain = ":plus_one_strict_deps_filter_a_impl",
toolchain_type = "@io_bazel_rules_scala//scala:toolchain_type",
visibility = ["//visibility:public"],
)
scala_toolchain(
name = "plus_one_strict_deps_filter_a_impl",
dependency_mode = "plus-one",
dependency_tracking_method = "ast",
strict_deps_mode = "error",
visibility = ["//visibility:public"],
)

View File

@ -42,7 +42,7 @@ gvm.graalvm(
)
use_repo(gvm, "graalvm")
register_toolchains("@graalvm//:jvm")
register_toolchains("@graalvm//:sdk")
register_toolchains("@graalvm//:sdk") ## Native-image
register_toolchains("@graalvm//:toolchain")
bazel_dep(name = "rules_jvm_external", version = "6.0")
@ -56,6 +56,8 @@ circe = ["io.circe:%s_2.13:%s" % (x, circe_version) for x in circe_libs]
commons_text_version = "1.10.0"
http_components_version = "4.4.1"
jackson_version = "2.15.2"
commons_io_version = "2.12.0"
commons_compress_version = "1.23.0"
maven = use_extension("@rules_jvm_external//:extensions.bzl", "maven")
## After updating a list of artifacts run
@ -67,7 +69,9 @@ maven.install(
"org.typelevel:cats-core_2.13:%s" % cats_version,
"org.apache.commons:commons-text:%s" % commons_text_version,
"org.apache.httpcomponents:httpclient:%s" % http_components_version,
"com.fasterxml.jackson.core:jackson-databind:%s" % jackson_version
"com.fasterxml.jackson.core:jackson-databind:%s" % jackson_version,
"commons-io:commons-io:%s" % commons_io_version,
"org.apache.commons:commons-compress:%s" % commons_compress_version,
] + circe,
fail_if_repin_required = True,
lock_file = "//:maven_install.json",

View File

@ -1,6 +1,6 @@
{
"lockFileVersion": 6,
"moduleFileHash": "6a3c0e8ec645ca9137de65f11f4ddebff3a6e1a8b5f915800f791471a0996859",
"moduleFileHash": "d584f112e6db5ad4995cfcb1bb9fc95f685e79af114072e6eb1f5b3d6541bfde",
"flags": {
"cmdRegistries": [
"https://bcr.bazel.build/"
@ -159,7 +159,7 @@
"usingModule": "<root>",
"location": {
"file": "@@//:MODULE.bazel",
"line": 60,
"line": 62,
"column": 22
},
"imports": {
@ -178,6 +178,8 @@
"org.apache.commons:commons-text:1.10.0",
"org.apache.httpcomponents:httpclient:4.4.1",
"com.fasterxml.jackson.core:jackson-databind:2.15.2",
"commons-io:commons-io:2.12.0",
"org.apache.commons:commons-compress:1.23.0",
"io.circe:circe-core_2.13:0.14.5",
"io.circe:circe-generic_2.13:0.14.5",
"io.circe:circe-parser_2.13:0.14.5"
@ -192,7 +194,7 @@
"devDependency": false,
"location": {
"file": "@@//:MODULE.bazel",
"line": 63,
"line": 65,
"column": 14
}
}
@ -137132,7 +137134,7 @@
"bzlTransitiveDigest": "WLH6tV/jGiZ73lPBSYWRhoilLeqSLs6vQqjK4ph6NG0=",
"recordedFileInputs": {
"@@rules_jvm_external~//rules_jvm_external_deps_install.json": "cafb5d2d8119391eb2b322ce3840d3352ea82d496bdb8cbd4b6779ec4d044dda",
"@@//maven_install.json": "6644c09e6d88b959f15a31712781b98842a6049ced536863825bbe02e50dd1ba"
"@@//maven_install.json": "03f27c22f4542128b7cad590d0101793c45c296c65d232296c1ee91797d202ef"
},
"recordedDirentsInputs": {},
"envVariables": {},
@ -137273,6 +137275,18 @@
"downloaded_file_path": "v1/org/objenesis/objenesis/3.2/objenesis-3.2.jar"
}
},
"org_apache_commons_commons_compress_1_23_0": {
"bzlFile": "@@bazel_tools//tools/build_defs/repo:http.bzl",
"ruleClassName": "http_file",
"attributes": {
"sha256": "c267f17160e9ef662b4d78b7f29dca7c82b15c5cff2cb6a9865ef4ab3dd5b787",
"urls": [
"https://repo.maven.apache.org/maven2/org/apache/commons/commons-compress/1.23.0/commons-compress-1.23.0.jar",
"https://repo1.maven.org/maven2/org/apache/commons/commons-compress/1.23.0/commons-compress-1.23.0.jar"
],
"downloaded_file_path": "v1/org/apache/commons/commons-compress/1.23.0/commons-compress-1.23.0.jar"
}
},
"io_grpc_grpc_api_1_56_1": {
"bzlFile": "@@bazel_tools//tools/build_defs/repo:http.bzl",
"ruleClassName": "http_file",
@ -137586,6 +137600,18 @@
"ignore_empty_files": false
}
},
"commons_io_commons_io_2_12_0": {
"bzlFile": "@@bazel_tools//tools/build_defs/repo:http.bzl",
"ruleClassName": "http_file",
"attributes": {
"sha256": "74bd60c8eebd3d43f77a66c69c86540c257a3a098172f8b1d7fcdc9ed3e139ea",
"urls": [
"https://repo.maven.apache.org/maven2/commons-io/commons-io/2.12.0/commons-io-2.12.0.jar",
"https://repo1.maven.org/maven2/commons-io/commons-io/2.12.0/commons-io-2.12.0.jar"
],
"downloaded_file_path": "v1/commons-io/commons-io/2.12.0/commons-io-2.12.0.jar"
}
},
"com_google_api_grpc_proto_google_common_protos_2_23_0": {
"bzlFile": "@@bazel_tools//tools/build_defs/repo:http.bzl",
"ruleClassName": "http_file",
@ -137753,6 +137779,8 @@
"{ \"group\": \"org.apache.commons\", \"artifact\": \"commons-text\", \"version\": \"1.10.0\" }",
"{ \"group\": \"org.apache.httpcomponents\", \"artifact\": \"httpclient\", \"version\": \"4.4.1\" }",
"{ \"group\": \"com.fasterxml.jackson.core\", \"artifact\": \"jackson-databind\", \"version\": \"2.15.2\" }",
"{ \"group\": \"commons-io\", \"artifact\": \"commons-io\", \"version\": \"2.12.0\" }",
"{ \"group\": \"org.apache.commons\", \"artifact\": \"commons-compress\", \"version\": \"1.23.0\" }",
"{ \"group\": \"io.circe\", \"artifact\": \"circe-core_2.13\", \"version\": \"0.14.5\" }",
"{ \"group\": \"io.circe\", \"artifact\": \"circe-generic_2.13\", \"version\": \"0.14.5\" }",
"{ \"group\": \"io.circe\", \"artifact\": \"circe-parser_2.13\", \"version\": \"0.14.5\" }",
@ -138530,6 +138558,8 @@
"{ \"group\": \"org.apache.commons\", \"artifact\": \"commons-text\", \"version\": \"1.10.0\" }",
"{ \"group\": \"org.apache.httpcomponents\", \"artifact\": \"httpclient\", \"version\": \"4.4.1\" }",
"{ \"group\": \"com.fasterxml.jackson.core\", \"artifact\": \"jackson-databind\", \"version\": \"2.15.2\" }",
"{ \"group\": \"commons-io\", \"artifact\": \"commons-io\", \"version\": \"2.12.0\" }",
"{ \"group\": \"org.apache.commons\", \"artifact\": \"commons-compress\", \"version\": \"1.23.0\" }",
"{ \"group\": \"io.circe\", \"artifact\": \"circe-core_2.13\", \"version\": \"0.14.5\" }",
"{ \"group\": \"io.circe\", \"artifact\": \"circe-generic_2.13\", \"version\": \"0.14.5\" }",
"{ \"group\": \"io.circe\", \"artifact\": \"circe-parser_2.13\", \"version\": \"0.14.5\" }",

View File

@ -42,10 +42,16 @@ rules_scala_toolchain_deps_repositories(fetch_sources = True)
load("@io_bazel_rules_scala//scala:toolchains.bzl", "scala_register_toolchains")
scala_register_toolchains()
load("@io_bazel_rules_scala//testing:scalatest.bzl", "scalatest_repositories", "scalatest_toolchain")
scalatest_repositories()
scalatest_toolchain()
## Note that the default toolchain, enabled via
## > scala_register_toolchains()
## will not work due to a bug with SecurityManager
## https://github.com/bazelbuild/rules_scala/issues/1521
## Workaround is to use our own scala toolchain with custom options.
register_toolchains("//toolchains:enso_toolchain")

View File

@ -10,5 +10,6 @@ scala_library(
"@maven//:org_typelevel_cats_kernel_2_13",
"@maven//:io_circe_circe_core_2_13",
"@maven//:org_slf4j_slf4j_api",
]
##"@maven//:org_scala_lang_scala_library",
],
)

View File

@ -0,0 +1,26 @@
load("@io_bazel_rules_scala//scala:scala.bzl", "scala_library")
java_library(
name = "downloader",
srcs = glob(["src/main/java/**/*.java"]),
deps = [
"//tools/http-test-helper",
"//lib/scala/cli",
":downloader-scala",
"@maven//:org_slf4j_slf4j_api",
"@maven//:org_scala_lang_scala_library"
]
)
scala_library(
name = "downloader-scala",
srcs = glob(["src/main/scala/**/*.{java,scala}"]),
deps = [
"//tools/http-test-helper",
"//lib/scala/cli",
"@maven//:com_typesafe_scala_logging_scala_logging_2_13",
"@maven//:commons_io_commons_io",
"@maven//:org_apache_commons_commons_compress",
##"@maven//:org_scala_lang_scala_library"
]
)

View File

@ -1,7 +1,7 @@
{
"__AUTOGENERATED_FILE_DO_NOT_MODIFY_THIS_FILE_MANUALLY": "THERE_IS_NO_DATA_ONLY_ZUUL",
"__INPUT_ARTIFACTS_HASH": 1105404835,
"__RESOLVED_ARTIFACTS_HASH": 124091257,
"__INPUT_ARTIFACTS_HASH": 335356565,
"__RESOLVED_ARTIFACTS_HASH": -939134540,
"conflict_resolution": {
"com.google.errorprone:error_prone_annotations:2.3.2": "com.google.errorprone:error_prone_annotations:2.11.0"
},
@ -102,6 +102,12 @@
},
"version": "1.9"
},
"commons-io:commons-io": {
"shasums": {
"jar": "74bd60c8eebd3d43f77a66c69c86540c257a3a098172f8b1d7fcdc9ed3e139ea"
},
"version": "2.12.0"
},
"commons-logging:commons-logging": {
"shasums": {
"jar": "daddea1ea0be0f56978ab3006b8ac92834afeefbd9b7e4e6316fca57df0fa636"
@ -156,6 +162,12 @@
},
"version": "1.12.7"
},
"org.apache.commons:commons-compress": {
"shasums": {
"jar": "c267f17160e9ef662b4d78b7f29dca7c82b15c5cff2cb6a9865ef4ab3dd5b787"
},
"version": "1.23.0"
},
"org.apache.commons:commons-lang3": {
"shasums": {
"jar": "d919d904486c037f8d193412da0c92e22a9fa24230b9d67a57855c5c31c7e94e"
@ -657,6 +669,22 @@
"org.apache.commons.codec.language.bm",
"org.apache.commons.codec.net"
],
"commons-io:commons-io": [
"org.apache.commons.io",
"org.apache.commons.io.build",
"org.apache.commons.io.charset",
"org.apache.commons.io.comparator",
"org.apache.commons.io.file",
"org.apache.commons.io.file.attribute",
"org.apache.commons.io.file.spi",
"org.apache.commons.io.filefilter",
"org.apache.commons.io.function",
"org.apache.commons.io.input",
"org.apache.commons.io.input.buffer",
"org.apache.commons.io.monitor",
"org.apache.commons.io.output",
"org.apache.commons.io.serialization"
],
"commons-logging:commons-logging": [
"org.apache.commons.logging",
"org.apache.commons.logging.impl"
@ -763,6 +791,44 @@
"net.bytebuddy.agent",
"net.bytebuddy.agent.utility.nullability"
],
"org.apache.commons:commons-compress": [
"org.apache.commons.compress",
"org.apache.commons.compress.archivers",
"org.apache.commons.compress.archivers.ar",
"org.apache.commons.compress.archivers.arj",
"org.apache.commons.compress.archivers.cpio",
"org.apache.commons.compress.archivers.dump",
"org.apache.commons.compress.archivers.examples",
"org.apache.commons.compress.archivers.jar",
"org.apache.commons.compress.archivers.sevenz",
"org.apache.commons.compress.archivers.tar",
"org.apache.commons.compress.archivers.zip",
"org.apache.commons.compress.changes",
"org.apache.commons.compress.compressors",
"org.apache.commons.compress.compressors.brotli",
"org.apache.commons.compress.compressors.bzip2",
"org.apache.commons.compress.compressors.deflate",
"org.apache.commons.compress.compressors.deflate64",
"org.apache.commons.compress.compressors.gzip",
"org.apache.commons.compress.compressors.lz4",
"org.apache.commons.compress.compressors.lz77support",
"org.apache.commons.compress.compressors.lzma",
"org.apache.commons.compress.compressors.lzw",
"org.apache.commons.compress.compressors.pack200",
"org.apache.commons.compress.compressors.snappy",
"org.apache.commons.compress.compressors.xz",
"org.apache.commons.compress.compressors.z",
"org.apache.commons.compress.compressors.zstandard",
"org.apache.commons.compress.harmony",
"org.apache.commons.compress.harmony.archive.internal.nls",
"org.apache.commons.compress.harmony.pack200",
"org.apache.commons.compress.harmony.unpack200",
"org.apache.commons.compress.harmony.unpack200.bytecode",
"org.apache.commons.compress.harmony.unpack200.bytecode.forms",
"org.apache.commons.compress.java.util.jar",
"org.apache.commons.compress.parallel",
"org.apache.commons.compress.utils"
],
"org.apache.commons:commons-lang3": [
"org.apache.commons.lang3",
"org.apache.commons.lang3.arch",
@ -1152,6 +1218,7 @@
"com.google.truth:truth",
"com.typesafe.scala-logging:scala-logging_2.13",
"commons-codec:commons-codec",
"commons-io:commons-io",
"commons-logging:commons-logging",
"io.circe:circe-core_2.13",
"io.circe:circe-generic_2.13",
@ -1161,6 +1228,7 @@
"junit:junit",
"net.bytebuddy:byte-buddy",
"net.bytebuddy:byte-buddy-agent",
"org.apache.commons:commons-compress",
"org.apache.commons:commons-lang3",
"org.apache.commons:commons-text",
"org.apache.httpcomponents:httpclient",
@ -1211,6 +1279,7 @@
"com.google.truth:truth",
"com.typesafe.scala-logging:scala-logging_2.13",
"commons-codec:commons-codec",
"commons-io:commons-io",
"commons-logging:commons-logging",
"io.circe:circe-core_2.13",
"io.circe:circe-generic_2.13",
@ -1220,6 +1289,7 @@
"junit:junit",
"net.bytebuddy:byte-buddy",
"net.bytebuddy:byte-buddy-agent",
"org.apache.commons:commons-compress",
"org.apache.commons:commons-lang3",
"org.apache.commons:commons-text",
"org.apache.httpcomponents:httpclient",

23
toolchains/BUILD.bazel Normal file
View File

@ -0,0 +1,23 @@
## Discover dependencies via
## > bazel build <target> --extra_toolchains=//:plus_one_strict_deps_filter
load("@io_bazel_rules_scala//scala:scala_toolchain.bzl", "scala_toolchain")
scala_toolchain(
name = "enso_toolchain_impl",
scalacopts = ["-Ywarn-unused"],
scalac_jvm_flags = [
"-Djava.security.manager=allow",
],
## Allows for easier discovery of missing dependencies
##dependency_mode = "plus-one",
##dependency_tracking_method = "ast",
##strict_deps_mode = "error",
visibility = ["//visibility:public"]
)
toolchain(
name = "enso_toolchain",
toolchain_type = "@io_bazel_rules_scala//scala:toolchain_type",
toolchain = "enso_toolchain_impl",
visibility = ["//visibility:public"]
)

View File

@ -1,12 +1,13 @@
java_binary(
java_library(
name = "http-test-helper",
srcs = glob(["src/main/java/**/*.java"]),
main_class = "org.enso.shttp.HTTPTestHelperServer",
#main_class = "org.enso.shttp.HTTPTestHelperServer",
deps = [
"@maven//:org_apache_commons_commons_text",
"@maven//:org_apache_httpcomponents_httpclient",
"@maven//:org_apache_httpcomponents_httpcore",
"@maven//:com_fasterxml_jackson_core_jackson_databind",
"@maven//:com_fasterxml_jackson_core_jackson_core"
]
],
visibility = ["//visibility:public"],
)