palantir / gradle-processors

Gradle plugin for integrating Java annotation processors
Apache License 2.0
62 stars 23 forks source link

Run annotation processors as part of the gradle idea task #76

Open jroitgrund opened 7 years ago

jroitgrund commented 7 years ago

Current behavior: when switching to a new branch that has different dependencies, I need to run gradle idea to fetch those, and then I need to run Rebuild Project in IntelliJ to run the annotation processors again.

Desired behavior: gradle idea also runs the annotation processors such that checking out a commit and running gradle idea is sufficient to start coding.

alicederyn commented 7 years ago

Running javac is the responsibility of IntelliJ, not Gradle. You don't want a code typo preventing you generating the IntelliJ project.

jroitgrund commented 7 years ago

I guess you're talking about the implementation? The way I imagined it, gradle already runs the annotation processors as part of compileJava, it would just need to do the exact same thing but using the intellij "out" directory, instead of its own "build" directory.

On 14 Aug 2017 3:27 pm, "Alice Purcell" notifications@github.com wrote:

Running javac is the responsibility of IntelliJ, not Gradle. You don't want a code typo preventing you generating the IntelliJ project.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/palantir/gradle-processors/issues/76#issuecomment-322205179, or mute the thread https://github.com/notifications/unsubscribe-auth/ABr34p1RL5qTXmJufWJ7fAEu0KVPh_FNks5sYFlqgaJpZM4O2aho .

alicederyn commented 6 years ago

No, I mean gradle idea doesn't run compileJava, so the sources aren't necessarily present nor up-to-date :/

aouledissa commented 4 years ago

I am seeking help here as i couldn't find any valuable resource else where. I am trying to have my custom plugin create a task that when run, it should trigger an annotation processing process. Do you know how to configure this task so it does so? is that even possible? PS: My tasks are written in kotlin but i don't mind groovy examples. Thanks in advance

aouledissa commented 4 years ago

I am seeking help here as i couldn't find any valuable resource else where. I am trying to have my custom plugin create a task that when run, it should trigger an annotation processing process. Do you know how to configure this task so it does so? is that even possible? PS: My tasks are written in kotlin but i don't mind groovy examples. Thanks in advance

Yep this is possible and here is my task configs

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 = variant.getCompileClasspath(null) //this is the missing piece!!
        source = files(projectDir.resolve("src/main/java")).asFileTree
    }
}

Hope this could be helpful to someone.