How to call annotation processor from Gradle plugin


Auld Issa

I'm currently working on a Gradle custon plugin that should analyze a specific configuration in each subproject of my root project and then generate some kotlin source code in the build directory. I can't find a way to call my annotation processor from my gradle plugin, which has a custom task for this.

Any ideas how to achieve this? Any resources/tutorials/documentation are also highly welcome.

Thank you in advance and please stay safe.

Auld Issa

After a long search and a lot of trying and failing, I finally found a solution to my problem. Here is my task configuration.

Basically, we have to provide the classpath of the annotation processor as project configuration. In my case, I added this block to my project's build.gradle

allprojects {
    configurations {
        myProcessor //pick any name!!!
    }
}

Then as a dependency in the app build.gradle

dependencies {
    myProcessor "PATH_TO_MY_PROCESSOR_JAR" //or maven dependency if it's uploaded to maven central
}
tasks.register(
"myTaskName",
JavaCompile::class.java
) {
    compiler ->
    with(compiler.options) {
        isFork = true
        isIncremental = true
    }
    with(compiler) {
        group = shuttle.plugin.ShuttlePlugin.TASK_GROUP
        destinationDir = outputDir
        classpath = variant.getCompileClasspath(null)
        options.annotationProcessorPath = configurations.getByName("myProcessor") //this is the missing piece!!
        source = files(projectDir.resolve("src/main/java")).asFileTree
    }
}

However, this task will only compile Java classes , only not Kotlin . Knowing that my plugin only targets android apps, so I don't have direct access to kotlinCompilegradle default tasks?

Related


How to exclude annotation processor dependencies from ProGuard

Trevor A: Getting a ProGuard warning when trying to create a release version of my Android project, preventing the build from completing successfully. Warning: Library class com.google.googlejavaformat.java.filer.FormattingJavaFileObject$1$1 extends or impleme

Gradle Annotation Processor for JOOQ Inspector

Gabor Angeli Does Gradle have equivalent functionality to the Maven configuration described by the JOOQ Type Checker Annotation Processor ( https://www.jooq.org/doc/latest/manual/tools/checker-framework/ ) ? Maven version is: <dependency> <groupId>org.jooq</

How to use custom Java annotation processor with Gradle?

james I've been working on a scalable simple Java annotation processor AbstractProcessor. I have been able to usejavac -Processor MyProcessor mySource.java The problem is using Android Studio to integrate it into a simple Hello World android application. I sta

QueryDSL annotation processor and Gradle plugin

Victor V Can't understand how to configure build.gradle to use querydsl annotation processor without any jpa/jdo/mongo. I want to generate the Q class using the @QueryEntity annotation, so I will be able to write dynamic SQL queries using the DSL support, then

How to exclude annotation processor dependencies from ProGuard

Trevor A: Getting a ProGuard warning when trying to create a release version of my Android project, preventing the build from completing successfully. Warning: Library class com.google.googlejavaformat.java.filer.FormattingJavaFileObject$1$1 extends or impleme

Gradle Annotation Processor for JOOQ Inspector

Gabor Angeli Does Gradle have equivalent functionality to the Maven configuration described by the JOOQ Type Checker Annotation Processor ( https://www.jooq.org/doc/latest/manual/tools/checker-framework/ ) ? Maven version is: <dependency> <groupId>org.jooq</

How to use custom Java annotation processor with Gradle?

james I've been working on a scalable simple Java annotation processor AbstractProcessor. I have been able to usejavac -Processor MyProcessor mySource.java The problem is using Android Studio to integrate it into a simple Hello World android application. I sta

QueryDSL annotation processor and Gradle plugin

Victor V Can't understand how to configure build.gradle to use querydsl annotation processor without any jpa/jdo/mongo. I want to generate the Q class using the @QueryEntity annotation, so I will be able to write dynamic SQL queries using the DSL support, then

How to call annotation processor from Gradle plugin

Auld Issa I'm currently working on a Gradle custon plugin that should analyze a specific configuration in each subproject of my root project and then generate some kotlin source code in the build directory. I can't find a way to call my annotation processor fr

How to use custom Java annotation processor with Gradle?

james I've been working on a scalable simple Java annotation processor AbstractProcessor. I have been able to usejavac -Processor MyProcessor mySource.java The problem is using Android Studio to integrate it into a simple Hello World android application. I fir

QueryDSL annotation processor and Gradle plugin

Victor V Can't understand how to configure build.gradle to use querydsl annotation processor without any jpa/jdo/mongo. I want to generate the Q class using the @QueryEntity annotation, so I will be able to write dynamic SQL queries using the DSL support, then

Gradle Annotation Processor for JOOQ Inspector

Gabor Angeli Does Gradle have equivalent functionality to the Maven configuration described by the JOOQ Type Checker Annotation Processor ( https://www.jooq.org/doc/latest/manual/tools/checker-framework/ ) ? Maven version is: <dependency> <groupId>org.jooq</

How to call annotation processor from Gradle plugin

Auld Issa I'm currently working on a Gradle custon plugin that should analyze a specific configuration in each subproject of my root project and then generate some kotlin source code in the build directory. I can't find a way to call my annotation processor fr

How to use custom Java annotation processor with Gradle?

james I've been working on a scalable simple Java annotation processor AbstractProcessor. I have been able to usejavac -Processor MyProcessor mySource.java The problem is using Android Studio to integrate it into a simple Hello World android application. I sta

How to call annotation processor from Gradle plugin

Auld Issa I'm currently working on a Gradle custon plugin that should analyze a specific configuration in each subproject of my root project and then generate some kotlin source code in the build directory. I can't find a way to call my annotation processor fr

How to call annotation processor from Gradle plugin

Auld Issa I'm currently working on a Gradle custon plugin that should analyze a specific configuration in each subproject of my root project and then generate some kotlin source code in the build directory. I can't find a way to call my annotation processor fr

QueryDSL annotation processor and Gradle plugin

Victor V Can't understand how to configure build.gradle to use querydsl annotation processor without any jpa/jdo/mongo. I want to generate the Q class using the @QueryEntity annotation, so I will be able to write dynamic SQL queries using the DSL support, then