Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Skip checks for generated code #106

Open
apodavalov opened this issue Jun 25, 2020 · 2 comments
Open

Skip checks for generated code #106

apodavalov opened this issue Jun 25, 2020 · 2 comments

Comments

@apodavalov
Copy link

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.

9999years pushed a commit to 9999years/checkerframework-gradle-plugin that referenced this issue Jul 22, 2020
Sometimes, checkers should be disabled for a particular compile task.

Add a `checkerFramework` extension to each compile task which can be
used for configuration.

Partially fixes kelloggm#110 (task-dependent configuration) and kelloggm#106 (skip
checks for autogenerated code).
@apodavalov
Copy link
Author

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.

@nathanclayton
Copy link

nathanclayton commented May 20, 2021

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants