import org.gradle.api.Plugin;
import org.gradle.api.Project;
import org.gradle.api.file.DirectoryProperty;
import org.gradle.api.tasks.TaskContainer;
import org.gradle.api.tasks.TaskProvider;
import org.gradle.api.tasks.compile.JavaCompile;
import org.gradle.language.cpp.tasks.CppCompile;

public abstract class JniPlugin implements Plugin<Project> {

    @Override
    public void apply(Project project) {
        project.getPluginManager().withPlugin("java", plugin -> {
            TaskContainer tasks = project.getTasks();
            TaskProvider<JavaCompile> compileJavaProvider = tasks.named("compileJava", JavaCompile.class);
            configureCompileJava(compileJavaProvider);

            tasks.withType(CppCompile.class)
                .configureEach(task -> task.includes(
                    compileJavaProvider.flatMap(it -> it.getOptions().getHeaderOutputDirectory())
                ));
        });
    }

    private void configureCompileJava(
        TaskProvider<JavaCompile> compileJavaProvider
    ) {
        compileJavaProvider.configure(compileJava -> {
            DirectoryProperty headerOutputDirectory = compileJava.getOptions().getHeaderOutputDirectory();
            headerOutputDirectory.convention(compileJava.getProject().getLayout().getBuildDirectory().dir("generated/jni-headers"));
            // The nested output is not marked automatically as an output of the task regarding task dependencies.
            // So we mark it manually here.
            // See https://github.com/gradle/gradle/issues/6619.
            compileJava.getOutputs().dir(compileJava.getOptions().getHeaderOutputDirectory());
            // Cannot do incremental header generation, since the pattern for cleaning them up is currently wrong.
            // See https://github.com/gradle/gradle/issues/12084.
            compileJava.getOptions().setIncremental(false);
        });
    }
}

@@ -58,54 +58,8 @@
 ct;%0A
-import org.gradle.api.file.DirectoryProperty;%0A
 impo
@@ -93,24 +93,24 @@
 kContainer;%0A
+
 import org.g
@@ -585,63 +585,8 @@
 ss);
-%0A            configureCompileJava(compileJavaProvider);
 %0A%0A  
@@ -780,16 +780,16 @@
 tory())%0A
+
         
@@ -821,982 +821,7 @@
    %7D
-%0A%0A    private void configureCompileJava(%0A        TaskProvider%3CJavaCompile%3E compileJavaProvider%0A    ) %7B%0A        compileJavaProvider.configure(compileJava -%3E %7B%0A            DirectoryProperty headerOutputDirectory = compileJava.getOptions().getHeaderOutputDirectory();%0A            headerOutputDirectory.convention(compileJava.getProject().getLayout().getBuildDirectory().dir(%22generated/jni-headers%22));%0A            // The nested output is not marked automatically as an output of the task regarding task dependencies.%0A            // So we mark it manually here.%0A            // See https://github.com/gradle/gradle/issues/6619.%0A            compileJava.getOutputs().dir(compileJava.getOptions().getHeaderOutputDirectory());%0A            // Cannot do incremental header generation, since the pattern for cleaning them up is currently wrong.%0A            // See https://github.com/gradle/gradle/issues/12084.%0A            compileJava.getOptions().setIncremental(false);%0A        %7D);%0A    %7D
 %0A%7D%0A

Remove now unnecessary workaround