salesforce / rules_spring

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

Add root classloader support for custom classes #188

Closed plaird closed 10 months ago

plaird commented 10 months ago

This feature is a simple partial solution to #129 . It is for cases where a service needs to inject more classes into the root of the executable jar. This means the classes are written directly into the root of the jar, not in BOOT-INF/classes or BOOT-INF/libs.

It works by creating a java_library target with the special name: rootclassloader_lib

java_library(
    name = "rootclassloader_lib",
    srcs = glob(["src_root/main/java/**/*.java"]),
)

then adding the java_library to the deps attribute of the springboot rule:

springboot(
    name = "demoapp",
    boot_app_class = "com.sample.SampleMain",
    java_library = ":demoapp_lib",

    # inject the root classloaded classes
    deps = [ ":rootclassloader_lib", ],
    ...

I am not comfortable making this an official feature since it is a bit hacky, using a naming convention. But adding it in, such that anyone can have a solution for root classes in #129 .