Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error: LinkageError occurred while loading main class com.github.bazelbuild.rules_jvm_external.jar.AddJarManifestEntry #895

Closed
davido opened this issue May 7, 2023 · 7 comments · Fixed by #1058
Assignees

Comments

@davido
Copy link

davido commented May 7, 2023

I'm trying to build a project with Bazel@HEAD that uses rules_jvm_external, and seeing java.lang.UnsupportedClassVersionError.

I am able to reproduce this issue on this example project:

  $ cd examples/spring_boot
  $ bazel build --java_language_version=20 --tool_java_language_version=20 //src/main/java/hello:app
[...]
ERROR: /root/.cache/bazel/_bazel_root/0cac1bdcd270835faac27b8a4016eec0/external/maven/BUILD:839:11: Stamping the manifest of @maven//:org_springframework_boot_spring_boot_autoconfigure failed: (Exit 1): AddJarManifestEntry failed: error executing StampJarManifest command (from target @maven//:org_springframework_boot_spring_boot_autoconfigure) bazel-out/k8-opt-exec-ST-fd2704146ab2/bin/external/rules_jvm_external/private/tools/java/com/github/bazelbuild/rules_jvm_external/jar/AddJarManifestEntry --source ... (remaining 5 arguments skipped)

Use --sandbox_debug to see verbose messages from the sandbox and retain the sandbox build root for debugging
Error: LinkageError occurred while loading main class com.github.bazelbuild.rules_jvm_external.jar.AddJarManifestEntry
	java.lang.UnsupportedClassVersionError: com/github/bazelbuild/rules_jvm_external/jar/AddJarManifestEntry has been compiled by a more recent version of the Java Runtime (class file version 64.0), this version of the Java Runtime only recognizes class file versions up to 55.0
Target //src/main/java/hello:app failed to build
Use --verbose_failures to see the command lines of failed build steps.
INFO: Elapsed time: 18.723s, Critical Path: 3.36s
INFO: 16 processes: 10 internal, 2 processwrapper-sandbox, 4 worker.

Environment:

  $ echo $JAVA_HOME
  /usr/lib/jvm/java-20-openjdk

  $ java -fullversion
  openjdk full version "20.0.1+9"
@meteorcloudy
Copy link
Contributor

We are having the same problem while trying to upgrade JDK to 21 for Bazel: https://buildkite.com/bazel/google-bazel-presubmit/builds/77440#018dd10c-5240-4174-aeee-be81150ead6c

/cc @zhengwei143 @shs96c @jin

@jin jin self-assigned this Feb 22, 2024
@zhengwei143
Copy link

I asssume this is a matter of bumping up the versions in https://github.com/bazelbuild/rules_jvm_external/blame/master/.bazelrc? Can we though, I assume we might run into some incompatibility issues with other projects?

@jin
Copy link
Collaborator

jin commented Feb 22, 2024

I managed to build bazel with the failing patch in #895 (comment) with this local override patch (#1058). PTAL

The root cause comes from AddJarManifestEntry being (correctly) compiled with Java 21, but it's being executed directly without any toolchains, hence resolving to a potentially older Java version via @local_jdk, and you can't execute a JAR compiled with 21 with an older JRE.

@jin
Copy link
Collaborator

jin commented Feb 22, 2024

re: #895 (comment)

We should do that to pin RJE's own build, but it wouldn't fix this issue, since the upstream project's .bazelrc (in this case from the perspective of bazel -> RJE) isn't read.

@zhengwei143
Copy link

Thanks for #1058! I guess we will have to wait for a release of rules_jvm_external after that is submitted?

@jin
Copy link
Collaborator

jin commented Feb 22, 2024

I think you can use https://bazel.build/rules/lib/globals/module#git_override as a temporary measure without a full BCR push. I see it also has the patches attribute, which Bazel is using now.

@zhengwei143
Copy link

Great, thank you for the speedy work!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants