massfords / effectively-final

Java Compiler Plugin to enforce that method params are effectively final.
Apache License 2.0
6 stars 0 forks source link

Gradle Integration #1

Open simonharrer opened 7 years ago

simonharrer commented 7 years ago

Really cool idea to automatically detect those reassign violation; maybe could be integrated into Google's error-prone.

But my actual question is this: I was wondering how to use this in a gradle build. I didn't find any clues. Do you have any leads for this?

massfords commented 7 years ago

I just checked Google's error-prone and was surprised to not see a rule like this. I did this more as an exercise in writing a compiler plugin than anything else. I'll look at contributing but my guess is that someone's already pitched it.

As for Gradle, you're on your own since I'm a Maven user. However, there's nothing Maven specific about the Java Compiler Plugin so it should work in Gradle. The key things to look for are being able to pass -X arg to the compiler and telling it where to find the plugin via the processor path.

Here's a Gradle blog post that covers annotation processing which is the same idea. If you get this working, provide a snippet and I'll include it in the docs.

https://blog.gradle.org/incremental-compiler-avoidance

andob commented 3 years ago

@simonharrer To use this library with gradle, you have to configure the buildscript(s) with:

dependencies {
    annotationProcessor 'com.massfords:effectively-final:1.0'
}
allprojects {
    gradle.projectsEvaluated {
        tasks.withType(JavaCompile) {
            options.compilerArgs << "-Xplugin:EffectivelyFinal"
        }
    }
}

@massfords I opened a pull request, changed the README with documentation about how to use with gradle.