checkerframework-gradle-plugin icon indicating copy to clipboard operation
checkerframework-gradle-plugin copied to clipboard

Skip checks for generated code

Open apodavalov opened this issue 4 years ago • 2 comments

Is there a way to skip generated code? This is useful for protobufs, autovalue, etc. I know about -AskipDefs=. But it's a not 100% solution since much more (less) classes might be accidentally masked.

apodavalov avatar Jun 25 '20 05:06 apodavalov

Unfortunately, the proposed 'skip option' does work with protobuf generators and AutoValue. At the moment of configuration, JavaCompile task knows nothing about generated java source based on protobuf. The GenerateProtoTask links them to the JavaCompile task once the GenerateProtoTask has been executed. I did some experiments (see below).

 tasks.withType(JavaCompile).configureEach {
            println(name)
            for (src in source) {
                println(src)
            }
            println()
    }

It does not print paths to the generated sources. However, the following snippet does:

    tasks.withType(JavaCompile).configureEach {
        doFirst {
            println(name)
            for (src in source) {
                println(src)
            }
            println()           
        }
    }

Adding the following snippet after println() into the snippet above takes no effect at all (too late?).

            checkerFramework {
                skipCheckerFramework = true
            }

And adding the snippet above after println() in the very first one does take effect.

I am not sure that doFirst solution will work with AutoValue as well since I don't see such generated files in the sources. Probably JavaCompile creates them with annotation processors during the execution.

I am looking for a very easy solution here. The most universal one is just to avoid ${project.buildDir}/generated/ sources at all. That should work for everything. I don't have a lot of time here. However, if you provide some tips/thoughts on how to do that I can give you a try with a pull request :-) Anyway, thanks for the attempt.

apodavalov avatar Aug 07 '20 07:08 apodavalov

Perhaps, if in the main checkerFramework configuration, an array of directory/directory globs in an exclude section would work for defining the directories to exclude.

nathanclayton avatar May 20 '21 20:05 nathanclayton