bazel-contrib / bazel-contrib/rules_jvm_external

JavaInfo value has no field or method 'transitive_exports' when upgrading to Bazel 5.x+

Open
#676 1 comment 4 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
373
Forks
301
Avg merge
7d 17h
Merged PRs (30d)
3

Description

Hi-Diddly-Ho, `rules_jvm_external` developers!
We're seeing a build failure with Bazel version 5+ with a missing field in `JavaInfo`. Everything works fine with Bazel 4.2.1, the pinned version in this repo, but the upgrade causes the build to fail.

## Information
Running our build on the older version of Bazel works as expected:
`bazel run --define "maven_repo=file://$HOME/.m2/repository" //java/main/java/org/odict:odict.publish`, and everything gets published, however, when upgrading we get:

```
ERROR: /Users/imelnikov/Documents/dev/odict/java/main/java/org/odict/BUILD.bazel:4:12: in maven_project_jar rule //java/main/java/org/odict:odict-project:
Traceback (most recent call last):
File "/private/var/tmp/_bazel_imelnikov/d792e4c95a32b3f00d6ffc5d5ab946f1/external/rules_jvm_external/private/rules/maven_project_jar.bzl", line 52, column 36, in _maven_project_jar_impl
targets = [] + target[JavaInfo].transitive_exports.to_list()
Error: 'JavaInfo' value has no field or method 'transitive_exports'
Available attributes: annotation_processing, api_generating_plugins, compilation_info, compile_jars, full_compile_jars, java_outputs, outputs, plugins, runtime_output_jars, source_jars, transitive_compile_time_jars, transitive_deps, transitive_native_libraries, transitive_runtime_deps, transitive_runtime_jars, transitive_source_jars
ERROR: /Users/imelnikov/Documents/dev/odict/java/main/java/org/odict/BUILD.bazel:4:12: Analysis of target '//java/main/java/org/odict:odict-project' failed
ERROR: Analysis of target '//java/main/java/org/odict:odict.publish' failed; build aborted:
```

This happens because, from what we can tell, that field no longer exists in the latest versions of Bazel:
https://docs.bazel.build/versions/4.2.0/skylark/lib/JavaInfo.html#transitive_exports
https://docs.bazel.build/versions/5.1.0/skylark/lib/JavaInfo.html#transitive_exports <-- he's dead, Jim

I'd be happy to take a look at this and see if this can be fixed, couldn't find anything useful in Bazel's release notes. Thanks!

Our macro, for helpful reference:

```
java_export(
name = "odict",
maven_coordinates = "{}:{}:{}.{}.{}".format(maven["group"], maven["artifact"], version["major"], version["minor"], version["patch"]),
resources = ["//java/main/cpp:libodict.so"],
visibility = ["//java:__pkg__"],
srcs = glob(["**/*.java"]),
deps = [
"//schema/java",
"@native_utils",
"@odict_java_deps//:com_fasterxml_jackson_core_jackson_annotations",
"@odict_java_deps//:com_fasterxml_jackson_core_jackson_core",
"@odict_java_deps//:com_fasterxml_jackson_core_jackson_databind",
"@odict_java_deps//:org_xerial_snappy_snappy_java",
],
)
```

Contributor guide

Open the contributing guide

Research direction

Reproduce the failure with the Bazel command shown in the issue, then inspect private/rules/maven_project_jar.bzl at the maven_project_jar implementation and its JavaInfo usage. Compare behavior on Bazel 4.2.1 and Bazel 5.x; done means the reported publish target analyzes and runs successfully on the newer Bazel version without regressing the pinned version.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
build-system
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.