Repository: bazelbuild/bazel
Issue: incompatible_require_java_toolchain_header_compiler_direct
Labels: team-Rules-Java
incompatible-change

See: https://github.com/bazelbuild/bazel/commit/2ebb0a20b6caee1766820f17bf001350d5463e16. `java_toolchain.header_compiler_direct` should always be set when toolchain resolution is enabled.

No migration is needed for the built-in toolchains, or for custom toolchains using `default_java_toolchain`.

Issue comments:
Hi Liam, could you pls update this issue to follow https://bazel.build/breaking-changes-guide.html? (e.g. the title of the issue is not right, I could fix that myself but that link is quite nicely written and contains useful advice :).
The docs say the title should start with the name of the flag, which is `incompatible_require_java_toolchain_header_compiler_direct`. The [example](https://github.com/bazelbuild/bazel/issues/6611) has a similar title. Did you already update the title, or am I missing something?
Oh sorry for the confusion it was me who should read the docs. I thought the format has to be `<flag-name>: Description` (note the colon). Sorry again :/ 

Pull request review comments:

Patch that resolved the issue:
diff --git a/src/main/java/com/google/devtools/build/lib/rules/java/JavaOptions.java b/src/main/java/com/google/devtools/build/lib/rules/java/JavaOptions.java
index b824ea67be7755..85059953a65ab3 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/java/JavaOptions.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/java/JavaOptions.java
@@ -589,7 +589,7 @@ public ImportDepsCheckingLevelConverter() {
 
   @Option(
       name = "incompatible_require_java_toolchain_header_compiler_direct",
-      defaultValue = "false",
+      defaultValue = "true",
       documentationCategory = OptionDocumentationCategory.UNDOCUMENTED,
       effectTags = {OptionEffectTag.UNKNOWN},
       metadataTags = {


Test patch:
diff --git a/src/test/java/com/google/devtools/build/lib/analysis/mock/BazelAnalysisMock.java b/src/test/java/com/google/devtools/build/lib/analysis/mock/BazelAnalysisMock.java
index 2b7c242d7f4729..2b1f235a28d652 100644
--- a/src/test/java/com/google/devtools/build/lib/analysis/mock/BazelAnalysisMock.java
+++ b/src/test/java/com/google/devtools/build/lib/analysis/mock/BazelAnalysisMock.java
@@ -139,6 +139,7 @@ public void setupMockClient(MockToolsConfig config, List<String> workspaceConten
         "  javac = [':langtools'],",
         "  javabuilder = ['JavaBuilder_deploy.jar'],",
         "  header_compiler = ['turbine_deploy.jar'],",
+        "  header_compiler_direct = ['TurbineDirect_deploy.jar'],",
         "  singlejar = ['SingleJar_deploy.jar'],",
         "  genclass = ['GenClass_deploy.jar'],",
         "  ijar = ['ijar'],",
@@ -152,6 +153,7 @@ public void setupMockClient(MockToolsConfig config, List<String> workspaceConten
         "  javac = [':langtools'],",
         "  javabuilder = ['JavaBuilder_deploy.jar'],",
         "  header_compiler = ['turbine_deploy.jar'],",
+        "  header_compiler_direct = ['TurbineDirect_deploy.jar'],",
         "  singlejar = ['SingleJar_deploy.jar'],",
         "  genclass = ['GenClass_deploy.jar'],",
         "  ijar = ['ijar'],",
@@ -194,7 +196,7 @@ public void setupMockClient(MockToolsConfig config, List<String> workspaceConten
         "filegroup(name='JacocoCoverage', srcs = [])",
         "exports_files(['JavaBuilder_deploy.jar','SingleJar_deploy.jar','TestRunner_deploy.jar',",
         "               'JavaBuilderCanary_deploy.jar', 'ijar', 'GenClass_deploy.jar',",
-        "               'turbine_deploy.jar','ExperimentalTestRunner_deploy.jar'])",
+        "               'turbine_deploy.jar', 'TurbineDirect_deploy.jar', 'ExperimentalTestRunner_deploy.jar'])",
         "sh_binary(name = 'proguard_whitelister', srcs = ['empty.sh'])",
         "toolchain_type(name = 'toolchain_type')",
         "toolchain_type(name = 'runtime_toolchain_type')",
diff --git a/src/test/java/com/google/devtools/build/lib/testutil/FoundationTestCase.java b/src/test/java/com/google/devtools/build/lib/testutil/FoundationTestCase.java
index fc12bddba7604b..cbec362dd06682 100644
--- a/src/test/java/com/google/devtools/build/lib/testutil/FoundationTestCase.java
+++ b/src/test/java/com/google/devtools/build/lib/testutil/FoundationTestCase.java
@@ -140,6 +140,7 @@ protected void assertContainsEventsInOrder(String... expectedMessages) {
 
   protected void writeBuildFileForJavaToolchain() throws Exception  {
     scratch.file("java/com/google/test/turbine_canary_deploy.jar");
+    scratch.file("java/com/google/test/turbine_direct_deploy.jar");
     scratch.file("java/com/google/test/tzdata.jar");
     scratch.overwriteFile(
         "java/com/google/test/BUILD",
@@ -157,6 +158,7 @@ protected void writeBuildFileForJavaToolchain() throws Exception  {
         "    javac = [':javac_canary.jar'],",
         "    javabuilder = [':JavaBuilderCanary_deploy.jar'],",
         "    header_compiler = [':turbine_canary_deploy.jar'],",
+        "    header_compiler_direct = [':turbine_direct_deploy.jar'],",
         "    singlejar = ['SingleJar_deploy.jar'],",
         "    ijar = ['ijar'],",
         "    genclass = ['GenClass_deploy.jar'],",