salesforce / rules_spring

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

Support rules_jvm_external deps #13

Closed thundergolfer closed 4 years ago

thundergolfer commented 4 years ago

Description

As rules_jvm_external lays out deps differently to the native.maven_jar repo rule used in the example, things don't work right now if you use the former.

I collected the SRCS passed into write_manifest.sh to show this:

com.book.store.api.Application bazel-out/darwin-fastbuild/bin/store-api/src/main/java/com/book/store/api/MANIFEST.MF bazel-out/darwin-fastbuild/bin/external/maven/v1/https/repo1.maven.org/maven2/org/springframework/boot/spring-boot/2.1.3.RELEASE/stamped_spring-boot-2.1.3.RELEASE.jar 
bazel-out/darwin-fastbuild/bin/external/maven/v1/https/repo1.maven.org/maven2/org/springframework/spring-aop/5.1.5.RELEASE/stamped_spring-aop-5.1.5.RELEASE.jar 
bazel-out/darwin-fastbuild/bin/external/maven/v1/https/repo1.maven.org/maven2/org/springframework/spring-core/5.1.5.RELEASE/stamped_spring-core-5.1.5.RELEASE.jar 
bazel-out/darwin-fastbuild/bin/external/maven/v1/https/repo1.maven.org/maven2/org/springframework/spring-jcl/5.1.5.RELEASE/stamped_spring-jcl-5.1.5.RELEASE.jar 
bazel-out/darwin-fastbuild/bin/external/maven/v1/https/repo1.maven.org/maven2/org/springframework/spring-beans/5.1.5.RELEASE/stamped_spring-beans-5.1.5.RELEASE.jar 
bazel-out/darwin-fastbuild/bin/external/maven/v1/https/repo1.maven.org/maven2/org/springframework/spring-context/5.1.5.RELEASE/stamped_spring-context-5.1.5.RELEASE.jar 
bazel-out/darwin-fastbuild/bin/external/maven/v1/https/repo1.maven.org/maven2/org/springframework/spring-expression/5.1.5.RELEASE/stamped_spring-expression-5.1.5.RELEASE.jar 
....

The first ERROR you get is:

ERROR: //tools/springboot/write_manifest.sh could not find spring-boot jar

Fortunately it was quite easy to get at least the basics working with rules_jvm_external by make 2 changes to pattern matching lines here and here.

At https://github.com/thundergolfer/the-one-true-bazel-monorepo/commit/dc7d2c66fbe2816d83f3979b05275f1935a7874a I can now get this rule working I think, as doing bazel run //store-api/src/main/java/com/book/store/api:deployable works 👍.


Note, this may be a dupe/sibling of https://github.com/salesforce/bazel-springboot-rule/issues/4

dan-cohn commented 4 years ago

In addition to difference in dependency layout, recent versions of rules_jvmexternal (at least 3.0 and 3.1) prepend each jar with `stamped`. This causes springboot_pkg.sh (here) to fail to extract the spring-boot-loader classes and place them at the root level of the jar.

This results in

Error: Could not find or load main class org.springframework.boot.loader.JarLauncher

when trying to run the jar.

Changing the condition to $libname == *spring-boot-loader* or $libname == stamped_spring-boot-loader* corrects the problem. The former is backward-compatible and should continue to work with native.maven_jar (although I have not tested it myself).

plaird commented 4 years ago

Apologies for missing this - years ago I toned down my email notifications from GH and forgot about it. I have re-added email notifications to my settings.

I will get this in our current/next sprint and will address. Thanks so much for reporting.

See a related discussion on bazel-eclipse-discuss: https://groups.google.com/forum/?utm_medium=email&utm_source=footer#!topic/bazel-eclipse-discuss/87Va4oGscgM

sromocki commented 4 years ago

All of my deps from rules_jvm_external show up like this: BOOT-INF/lib/bazel-out/darwin-fastbuild/bin/external/maven/v1/https/repo.maven.apache.org/maven2/com/fasterxml/jackson/dataformat/jackson-dataformat-cbor/2.9.8/stamped_jackson-dataformat-cbor-2.9.8.jar

If they aren't root in BOOT-INF/lib will they still work?

plaird commented 4 years ago

If you are using rules_jvm_external, no I don't think this rule will work as-is. Our attempt to transition our internal monorepo last sprint to rules_jvm_external hit some snags, so we haven't yet vetted the associated springboot rule changes. We will have an internal release of another major project our team owns this week, but soon after we should have the cycles to update this repo.

In the meantime, please try what thundergolfer/dan-cohn recommended. Post back if that solution doesn't work for you.

sromocki commented 4 years ago

@plaird I was able to get things to work with their recommended solutions and also changing the directory to which the jars are placed to BOOT-INF/lib

plaird commented 4 years ago

I merged into the master the fixes provided by @thundergolfer and @dan-cohn in PR #20. I will close this ticket, and finish full support (docs, import bundles) in issue #4 .

Thanks for the contributions!