salesforce / rules_spring

Bazel rule for building Spring Boot apps as a deployable jar
BSD 3-Clause "New" or "Revised" License
224 stars 48 forks source link

genmanifest subrule fails on Linux with 'jar: command not found' in rules_spring 2.1 #119

Closed plaird closed 3 years ago

plaird commented 3 years ago

Reported from an internal user on Linux, but this is not platform specific. This bug was introduced in rules_spring 2.1.

The jar command should be coming from the Bazel configuration. But in #111 we added the usage of jar to the genmanifest subrule without wiring it to the Bazel env correctly. https://github.com/salesforce/rules_spring/blob/master/springboot/write_manifest.sh#L18

See the springboot_pkg.sh invocation of jar to see how to do that correctly: https://github.com/salesforce/rules_spring/blob/master/springboot/springboot_pkg.sh#L93

The workaround on rules_spring 2.1 is to have the user set the PATH to include JAVA_HOME/bin

$ bazel build test/service/...
INFO: Invocation ID: 41ba14f3-70f1-4bef-b5bd-75163c650e2c
INFO: Analyzed 36 targets (0 packages loaded, 0 targets configured).
INFO: Found 36 targets...
ERROR: /home/mbenioff/dev/bazel-repo/test/service/BUILD:39:11: Executing genrule //test/service:test/service/service_genmanifest failed (Exit 127): bash failed: error executing command /bin/bash -c ... (remaining 1 argument(s) skipped)
Use --sandbox_debug to see verbose messages from the sandbox bash failed: error executing command /bin/bash -c ... (remaining 1 argument(s) skipped)
Use --sandbox_debug to see verbose messages from the sandbox
external/rules_spring/springboot/write_manifest.sh: line 18: jar: command not found
INFO: Elapsed time: 1.339s, Critical Path: 1.09s
INFO: 13 processes: 5 internal, 4 linux-sandbox, 4 worker.
FAILED: Build did NOT complete successfully
plaird commented 3 years ago

Merged, and this fix will be released in the next minor version (2.2). I don't want to cut a patch release 2.1.1 just for this. The workaround is fairly easy, hopefully uncommon as most Spring Boot devs likely have the JDK in path, and I expect to release 2.2 in the next few weeks anyway.

I added a release note about this to the 2.1 release text.

Thanks @mcamenzind for jumping on this!

plaird commented 3 years ago

More on this...

The raw jar command that was added in 2.1.0 was not the only case. There was a java invocation further down in the file (see #121), which has been there for forever. So this issue has been around for a long time, the jar command was just another case of it.

We have had a couple of users hit this internally all of a sudden, which makes me want to get a patch release out. I am working on sending 2.1.1 shortly which includes this fix.