https://kotlinlang.org logo
Title
f

Fudge

05/14/2020, 6:51 PM
I'm having an issue where applying the kapt plugin in gradle prevents it from running other java annotation processors during
compileJava
. Any idea why that could be happening?
Looks like they now run when I apply
kapt
on them, but the problem I had still persists :/
g

gildor

05/15/2020, 6:53 AM
you want to run APT for some annotation processors and Kapt for another?
Kapt doesn’t run as part of compileJava, you have to specify APs explicitly using configuration
kapt
, actually I even not sure that compileJava runs Apt, I think Gradle now requires using configuration
annotationProcessor
for them
f

Fudge

05/16/2020, 9:55 PM
When it runs normally in
compileJava
you can pass different compiler arguments for each
xCompileJava
task for different source sets, how can I do the same with the
xKapt
tasks?
This is what I ended up with. The following sights may be disturbing.
protected void passArgument(KaptTask compileTask, String key, String value) {
		// Kapt doesn't provide an api to pass the AP args directly to the task so we need to do this hackery.
		CompilerPluginOptions options;
		if (compileTask instanceof KaptWithoutKotlincTask) {
			KaptWithoutKotlincTask task = (KaptWithoutKotlincTask) compileTask;
			// We are now entering the danger zone
			//noinspection KotlinInternalInJava aka @ts-ignore
			options = task.getProcessorOptions$kotlin_gradle_plugin();
		} else {
			KaptWithKotlincTask task = (KaptWithKotlincTask) compileTask;
			//noinspection KotlinInternalInJava aka @ts-ignore
			options = task.getPluginOptions$kotlin_gradle_plugin();
		}

		options.addPluginArgument(Kapt3KotlinGradleSubplugin.Companion.getKAPT_SUBPLUGIN_ID(), new SubpluginOption(key, value));
	}
Aaaand it doesn't work with
KaptWithKotlincTask
since it's encoded
g

gildor

05/17/2020, 6:37 AM
Do you need different arguments for different Kapt tasks? There is an extension on project level (but it will be applied to all tasks): https://kotlinlang.org/docs/reference/kapt.html#java-compiler-options
actually I even not sure that compileJava runs Apt
Yes, it does, checked this. But it’s not recommended way and Gradle recommends to have annotation processors separately and use
annotationProcessor
annotation This behaviour probably can be changed with kapt.include.compile.classpath=true, but it’s not recommended
f

Fudge

05/17/2020, 3:22 PM
Thank you, I managed to work around being able to only supply args to all tasks at once