Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change KAPT class generation path

I want to instruct my Kotlin annotation processor to change the output directory of the generated classes.

I want from my Gradle build script to change the kapt.kotlin.generated argument. I have tried the following to no avail.

  1. Doesn't work, path doesn't change

    kapt { arguments { arg("kapt.kotlin.generated", new File('path')) } }

  2. Doesn't work, path doesn't change

    kapt { javacOptions { option("kapt.kotlin.generated", new File('path')) } }

  3. Doesn't work, NullPointerException when building

    kapt { javacOptions { option("-Akapt.kotlin.generated", new File('path')) } }

Same results for all three when using a string path instead of a file.

I am at a loss, any help would be appreciated.

like image 363
iFanie Avatar asked Nov 06 '22 23:11

iFanie


1 Answers

Use a different option name:

kapt{
    arguments {
        arg("kapt.kotlin.custom.generated",
                rootProject.file("foobar/build/generated/source/kaptKotlin/main").absolutePath)
    }
}

then retrieve the custom option in your annotation processor and use that as the target

like image 199
Manos Batsis Avatar answered Nov 13 '22 02:11

Manos Batsis