-
Notifications
You must be signed in to change notification settings - Fork 357
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
Better instructions for working with Maven #445
Comments
Thanks for the suggestions. Having Maven do all the downloading of the Checker Framework is more idiomatic, so that is a good idea. Thanks! The same goes for Gradle. I'm not sure it fits as well with Ant, though. What is the purpose of the checker-qual dependency? Is it used anywhere? We have users who use JDK 7, so the instructions should indicate how to do that as well. Luckily, it's only a small change from what you have proposed. Would it be possible to write your instructions as a diff to the manual? In particular, it would be nice to have explicit indications of where each of the XML snippets goes -- in what file and where in the file. A pull request would be delightful, but we could also continue the conversation here in the issue. |
Hi. I'm on vacation, currently, so I have little time to make a PR, but in a few weeks I might be able to do that. I think 'checker-qual' is necessary for users who want checker-specific annotations like '@MonotonicNonNull'? All the XML snippets go in the pom.xml file, Maven users know immediately in which session each snippet goes :) but I'm happy to make that clearer later. I might write instructions for Gradle also, if you'll wait for my PR. Cheers. |
Thanks! I appreciate it. This will be very nice for other Checker Framework and Maven/Gradle users. (The explicit discussion of where everything goes may help novice Maven users, and I think it doesn't have to be too wordy or pedantic for the experts.) Enjoy your vacation! I look forward to hearing from you when you return. |
A ping: if you are back from your vacation and have a chance to write the instructions for the manual, that would be great. Thanks! |
Hi, I came back this week! Will definitely do it this week, thanks for reminding. |
Here's my first PR: #461 |
I've managed to get Gradle to do the same thing as Maven and get the anotated JDK off Maven Central... and pass its local path to the Java Compiler... When I compile with the NullnessChecker enabled, it works as expected, but it prints this:
It does NOT print the warning about not finding the annotated JDK... This is strange as I am using Oracle's JVM to run everything:
You can check out the demo project at https://github.com/renatoathaydes/checker-gradle-demo |
I haven't looked into it carefully, but here is a possibility. The warnings about unknown enum constants look similar to the ones you reported in issue #439, where the solution was to use the correct annotated JDK. Might this one be similar? |
That's what I had thought too... but in that case, it was not finding the annotated JDK... now I am sure it is finding the annotated JDK because I don't get the warning that the JDK was not found, and also, If I try to use |
@renatoathaydes this is fantastic! Thanks! I got it working with Java 8 in pdurbin/maven-hello-world@3c08628 but I can't get it working with Java 7. Any ideas for me? Please see details at pdurbin/maven-hello-world#3 |
The "unknown enum constant" warnings are being raised because the nullness annotations (e.g. |
Maybe just that enum should be added to the classpath and/or the Checker Framework jar -- if that's not too complicated or brittle and if the copyrights permit. |
One other note: the error message parsing performed by |
@atomicknight Thanks for pointing that out, Abraham. It sounds like a bug in |
Could we also give instruction about how to make checker framework work in maven multiple module projects? -- I made checker work in simple maven project, but failed to make it work in modules projects. Underlying Exception: org.checkerframework.framework.source.SourceChecker$CheckerError: InvocationTargetException when invoking constructor for class org.checkerframework.checker.nullness.KeyForAnnotatedTypeFactory; Underlying cause: Could not load class 'org.checkerframework.checker.nullness.qual.UnknownKeyFor' for field 'value' in annotation @org.checkerframework.framework.qual.PolymorphicQualifier(org.checkerframework.checker.nullness.qual.UnknownKeyFor.class); Stack trace: org.checkerframework.framework.source.SourceChecker.errorAbort(SourceChecker.java:682) Thanks... |
@jefferyyuan, can you be more specific? You didn't say what you did nor give a reproducible test case, and that makes it difficult for other people to help you. Thanks. Also, this text is identical to something sent to the checker-framework-discuss mailing list. Please post your information in one place rather than having identical text in two different places. |
@mernst thanks so much for your quick reply and sorry for the duplicate post. The problem is not related with maven modules, but related with google errorprone. Is there a way that we can run both? Thanks At first it throws: So I added checker libraries into maven-compiler-plugin's dependencies, now it throws exception: The whole configuration:
Or online version : https://github.com/jefferyyuan/code-quality-mvn/blob/master/code-quality-simple/pom.xml |
Just to follow up on the However, this will not address the issue if a JDK toolchain is used or if a compiler other than |
There are new instructions for how to work with Maven, so I think this can be closed. If that's not the case, please let us know. |
typetools/checker-framework#445 suggests that these two do not work together.
…gtext` and `nomsgtext` (typetools#445)
Hi. I submitted a few issues I had working with the checker framework, mostly due to the fact I was trying to avoid using the annotated JDK. The main reason for that was that I could not accept adding a system dependency (to a file somewhere in the local machine) or adding the jar to my source control to be able to refer to the annotated JDK jar.
After much trouble, I've come to a good solution that lets Maven take care of finding the jar and providing it to the checker framework.
I submit this issue as a request to add this to the documentation as the preferred way to use checker in Maven (similar approaches should work in Ant and Gradle).
First of all, to enable the checker framework, I simply add it as an annotation processor in the pom. This is done in the declaration of the
maven-compiler-plugin
. Then, I just add some compiler arguments that get passed to the NullnessChecker, like the location of my stubs (to annotate library methods), and importantly, the location of the annotated JDK in a system-independent, no setup way (Maven will download the jdk jar and figure out its location):Notice that the location of the annotated JDK8 comes from the
annotatedJdk8
property, which we have not yet set. To set it, two things need to be added to the pom:maven-dependency-plugin
to execute theproperties
goal, which will set the above property to the right value:Then, of course, we need to make the jdk jar a dependency in the pom:
This approach requires absolutely no setup in any machine where this build is run to make checker framework work.
It works best if all this configuration is done in a Maven profile, so that it's still possible to compile the code without running the checker framework. In this case, the dependencies above, as well as the maven-compiler-plugin dependency should be added inside the profile declaration... and optionally, the annotations in the Java code could come from a jar which contains only the
javax.annotation
annotations (eg.javax.annotation.Nullable
), such asfindbugs
, to completely un-couple the compilation to the checker-framework:The text was updated successfully, but these errors were encountered: