Kotlin Maven plugin isn't looking at annotations generated by kannotator


#1

I believe I've configured the Kotlin Maven plugin to read the annotations generated for me by kannotator:

  https://github.com/sanity/preddit/blob/master/pom.xml#L67

When I run the Kotlin Maven compiler, it picks this up:

[INFO] Using kotlin annotations from /Users/ian/.m2/repository/org/jetbrains/kotlin/kotlin-jdk-annotations/0.5.748/kotlin-jdk-annotations-0.5.748.jar:annotations

Here are the  relevant annotations: https://github.com/sanity/preddit/tree/master/annotations

Kannotator has correctly determined that the HttpServlet.doGet() method’s paramters are not null: https://github.com/sanity/preddit/blob/master/annotations/Maven:%20javax.servlet:servlet-api:2.5/javax/servlet/http/annotations.xml#L15

Because of this, IDEA requires that I use the override keyword when overriding this method, as it should: https://github.com/sanity/preddit/blob/master/src/main/kotlin/preddit/FrontPage.kt#L9

The problem is that when I try a “mvn compile” from the command line, I get the following error:

[ERROR] /Users/ian/workspace/preddit/src/main/kotlin/preddit/FrontPage.kt: (9, 15) ‘doGet’ overrides nothing

I assume this is because the Kotlin Maven compiler isn’t seeing that this method’s parameters are not nullable, even though IDEA itself has no problem with it (indeed, it requires it).  When I delete the annotations directory and use nullable paramters for the method, it compiles fine.

Can anyone suggest what is wrong here?


#2

Hi Ian,

Unfortunately, it seems you have to put the root of each library in annotation paths.

e.g. Here’s a working example from one of my projects (you can omit the ${project.basedir}/…/ prefix in your case).

  <annotationPaths>
  <annotationPath>
           {project.basedir}/../annotations/Maven_com.fasterxml.jackson.core_jackson-core_2.2.0</span> <span > &nbsp;&nbsp;&lt;/annotationPath&gt;</span> <span > &nbsp;&nbsp;&lt;annotationPath&gt;</span> <span >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;{project.basedir}/…/annotations/Maven_com.fasterxml.jackson.core_jackson-databind_2.2.0
  </annotationPath>
  </annotationPaths>

The second usuability hassle is the the Kannotator plugin creates directories starting with "Maven :". On OS X and presumably Linux, the colon gets treated as a path separator and it all falls over. In my example above you'll notice I replaced spaces and colons with underscore (one minor win is that if you rename via the IDE it updates the internal project references to annotations correctly).

Moving forward I think we need:

  1. The maven plugin to be smarter and scan for roots under the directory you give it (or maybe a separate configuration option to tell it you mean a root of roots)
  2. The Kannotator plugin to stop creating directories containing path separators.

Cheers, Andrew


#3

Thank you Andrew - it seems like these issues are really bugs.  Do you happen to know whether issues have been submitted yet?  If not, I can do it.


#4

I don't think they were submitted.


#5

I submitted two issues about an hour ago


#6

In my example above you'll notice I replaced spaces and colons with underscore (one minor win is that if you rename via the IDE it updates the internal project references to annotations correctly).
Andrew, can you elaborate on how exactly you did this in IDEA?

#7

Never mind, I think I figured it out.


#8

FYI - your workaround worked for me, although it's rather tedious - especially in a project with a lot of dependencies.

Hopefully the guys can implement the recursive scan for annotations directories quickly, my guess is that it should be a quick fix.


#9

Sorry for not getting back to you, but my timezone (Australia +10:00) means I'm out of sync with most of the planet.

It is a simple feature - I actually forked kotlin and implemented it on the weekend.

However, there’s no tests for the annotation code - there’s one integration test but it actually isn’t run by the build (needs some profile to be set). And the kotlin plugin module doesn’t build in isolation.

At that point I gave up. :frowning:

I may get back to it, but no promises.

Cheers,
Andrew


#10

We'll do something about it.


#11

Hi Andrey, just wanted to check and see if there has been any progress on this.


#12

No yet, unfortunately