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

Build failures for non-Spring dependency jars with name matching `*spring-boot-*` or `*spring_boot_*` #130

Closed fmeum closed 3 years ago

fmeum commented 3 years ago

Since https://github.com/salesforce/rules_spring/commit/67c64580de5a52977e668455e4c689ae911ff9c0, spring boot rules with names matching *spring-boot-* or *spring_boot_* can with an error such as the following if their corresponding java_library does not contain a META-INF/MANIFEST.MF file:

java.nio.file.NoSuchFileException:
bazel-out/k8-fastbuild/bin/foobar/tests/testdata/spring_boot_example/MANIFEST.MF
    at java.base/sun.nio.fs.UnixException.translateToIOException(UnixException.java:92) 
    at java.base/sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:111)
    at java.base/sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:116)
    at java.base/sun.nio.fs.UnixFileAttributeViews$Basic.readAttributes(UnixFileAttributeViews.java:55)
    at java.base/sun.nio.fs.UnixFileSystemProvider.readAttributes(UnixFileSystemProvider.java:149)
    at java.base/sun.nio.fs.LinuxFileSystemProvider.readAttributes(LinuxFileSystemProvider.java:99)
    at java.base/java.nio.file.Files.readAttributes(Files.java:1763)
    at java.base/java.util.zip.ZipFile$Source.get(ZipFile.java:1225)
    at java.base/java.util.zip.ZipFile$CleanableResource.<init>(ZipFile.java:727)
    at java.base/java.util.zip.ZipFile$CleanableResource.get(ZipFile.java:844)
    at java.base/java.util.zip.ZipFile.<init>(ZipFile.java:247)
    at java.base/java.util.zip.ZipFile.<init>(ZipFile.java:177)
    at java.base/java.util.zip.ZipFile.<init>(ZipFile.java:148)
    at jdk.jartool/sun.tools.jar.Main.extract(Main.java:1389)
    at jdk.jartool/sun.tools.jar.Main.run(Main.java:403)
    at jdk.jartool/sun.tools.jar.Main.main(Main.java:1681)

The root cause is that the .jar corresponding to the java_library target matches the check in https://github.com/salesforce/rules_spring/blob/67c64580de5a52977e668455e4c689ae911ff9c0/springboot/write_manifest.sh#L15, which causes the next command to attempt to unpack META-INF/MANIFEST.MF from the .jar. Since this .jar is build with java_library, it usually does not contain META-INF/MANIFEST.MF, which causes the script to error out.

A fix could be to catch the failure in the jar command and continue with the next match in the loop.

plaird commented 3 years ago

Ouch, sorry for the bug. Thanks for the PR and the fix! I will try to sort out the CLA issue and get it merged and released today.