rules_java icon indicating copy to clipboard operation
rules_java copied to clipboard

Profile issue when running bazel build command in java_binary

Open gabrielmirandat opened this issue 10 months ago • 3 comments

I am getting different behaviors when running a java_binary using bazel build and bazel run.

java_library(
  name = "artifact",
  srcs = glob(["src/main/java/**/*.java"]),
  javacopts = [
      "-source",
      "21",
      "-target",
      "21",
  ],
  resources = glob(["src/main/resources/**"]) + ["@newrelic_java//:newrelic.yml"],
  ...
)

java_binary(
    name = "uber",
    main_class = "...OrdersApplication",
    runtime_deps = [":artifact"],
)
  1. When running with bazel run and setting correct profile everything works fine (profile is loaded)
export SPRING_PROFILES_ACTIVE=local
bazel run //orders:uber
...
...OrdersApplication     : The following 1 profile is active: "local"
  1. When generating jar with bazel build and running jar, it seems it cannot find resources/profiles
export SPRING_PROFILES_ACTIVE=local
bazel build //orders:uber_deploy.jar
java -jar bazel-bin/orders/uber_deploy.jar
...
...OrdersApplication     : No active profile set, falling back to 1  default profile: default

I already tried other ways to set the profile, like using the command line -Dspring.profiles.active=local or --spring.profiles.active=local, but nothing seems to work.

Can anyone give some help on that?

gabrielmirandat avatar Dec 18 '24 23:12 gabrielmirandat