title: How to alter classpath for Java executable in ctx.actions.run?
body: <p>In my Java-based Bazel project I use a code generator written in Java. The generator is part of the root project, and used in sub-projects as well.</p>
  
  <p>What I want to achieve is to include the output of the root project (a .jar file) as a dependency for the code generation in sub-projects to grant the code generator  access to all compiled files of the root project (through the classpath). Is that possible in Bazel?</p>
  
  <p>What I see is that the classpath for key generation in the child project only includes the dependencies of the code generator binary (//parent:SettingsGenerator in the script below).</p>
  
  <p>In my custom rule I invoke the code generator basically like this:</p>
  
  <pre><code>def _generate_settings(ctx):
      ...
      ctx.actions.run(
          inputs = [ctx.file._src] + [ctx.files.deps],
          outputs = [keys, settings, loader],
          mnemonic = "GenKeysAndSettings",
          arguments = [args],
          executable = ctx.executable._tool,
      )
      return [DefaultInfo(
          files=depset([keys, settings, loader]),
          runfiles=ctx.runfiles(files=ctx.files.deps)
      )]
  
  gen_settings = rule(
      implementation = _generate_settings,
      attrs = {
          "lang": attr.string(),
          "deps": attr.label_list(
              allow_files = True
          ),
          "_tool": attr.label(
              cfg = "host",
              executable = True,
              default = Label("//parent:SettingsGenerator"),
          ),
          "_src": attr.label(
              single_file = True,
              default = Label("//parent:Name")
          ),
      }
  )
  </code></pre>
  
  <p>The parent project BUILD:</p>
  
  <pre><code>load("//parent:settings.bzl", "gen_settings")
  
  gen_settings(
      name = "GenerateSettings",
      lang = ""
  )
  java_library(
      name = "parent",
      srcs = glob(["src/main/java/**/*.java"]) + [
          ":GenerateSettings",
      ],
      ...
  )
  java_binary(
      name = "SettingsGenerator",
      srcs = glob(["src/main/java/**/SettingsGenerator.java"]),
      main_class = "my.company.SettingsGenerator",
      ...
  )
  </code></pre>
  
  <p>The child project BUILD:</p>
  
  <pre><code>gen_settings(
      name = "GenerateSettings",
      lang = "Java",
      deps = ["//parent"]
  )
  ...
  </code></pre>
  
  <p>My workaround is to include the .jar file as input and use a custom classloader in the generator. But it would be nice if I could control the classpath directly from Bazel.</p>
  
  <p>Any help would be appreciated. Thank you.</p>