The JavaCompile object does not have full classpath used by Gradle?

I’m making a plugin. One goal is to emit a compilation database like JSON file that describes the build of a Java project. To that end, I am using TaskExecutionListener’s beforeExecute. If the task is an instance of JavaCompile then I get the class path:

    ((JavaCompile)task).getClasspath().getFiles()

However, builds for some projects that use Kotlin and Java (calling the kotlin code from Java) do not seem to produce a complete classpath. For example, assembling okhttp includes tasks :okhttp:compileKotlin followed by :okhttp:compileJava. The compileJava task does not include any classpath for the classes produced by the Kotlin task - taking the JavaCompile object’s cp, arguments, files, and output directory and using javac manually results in missing symbols.

What is going on? Shouldn’t the full classpath be available via getClasspath() or is there a reason Gradle can compile without it? Is there another dataflow I need to look for that includes classpath information?

The JavaCompile classpath is the classpath used to compile your java classes. It’s not polluted with Gradle’s classpath.

Try buildscript.configurations.classpath.files

Lance,

Thanks for the reply. As I understand it, I’m not actually looking for Gradle’s classpath. The Kotlin files under question are part of the project being compiled and produce project classes that are needed by future compilation steps.

I guess the Kotlin plugin adds its classes in a doFirst action. Try doing your logic after the task finishes instead.

That’ll teach me for skim reading :blush: