sbt-antlr4 icon indicating copy to clipboard operation
sbt-antlr4 copied to clipboard

consider not adding antlr4 generated files to `managedSourceDirectories`

Open mpollmeier opened this issue 6 years ago • 5 comments

It looks to me like adding the antlr specific sources to sbt's managedSourceDirectories (https://github.com/ihji/sbt-antlr4/blob/3d36e6c/src/main/scala/com/simplytyped/Antlr4Plugin.scala#L80) isn't a good idea, since sbt already has the root directory src_managed in the classpath (tested only with sbt 1.0.3). The resulting classpath contains the antlr generated sources twice then: src_managed and src_managed/antlr4.

While sbt deals with that fine, Intellij compiles the classes twice and fails, complaining about "duplicate classes".

Changing this might be a can of worms though, and I haven't tested the zoo of different sbt versions and IDEs. Maybe it's best to just add a note in the readme? You probably know this topic better than me - what's your thoughts?

mpollmeier avatar Dec 21 '17 01:12 mpollmeier

@mpollmeier Thanks for your comment. antlr4 subdirectory path was added because of the issue in sbt-idea plugin. You can see the commit log here: https://github.com/ihji/sbt-antlr4/commit/b706e722d57afb118cd42427649e170d26354d87

I think it's okay to remove antlr4 subdirectory path in the next version. It seems that many people are now using Intellij's native support of sbt instead of sbt-idea plugin.

ihji avatar Dec 21 '17 19:12 ihji

Interesting how everything revolves around intellij on this issue. Thanks for the clarification, and the plugin :) Shall we leave this issue open as a reminder to remove, and in case others are having the same problem?

mpollmeier avatar Dec 22 '17 03:12 mpollmeier

Is there a workaround for this? Can I just set javaSource in Antlr4 such that modern IntelliJ with the built-in SBT support will play nice?

jackkoenig avatar Jun 13 '18 23:06 jackkoenig

I have found that

javaSource in Antlr4 := (sourceManaged in Compile).value

helps, but I still need to run sbt "antlr4:antlr4Generate" to make IntelliJ happy.

Is there a better way to do this?

jackkoenig avatar Jun 13 '18 23:06 jackkoenig

The recommendation is now against using (sourceManaged in Compile).value altogether. Instead each plugin should roll out their own directory under target, and append to managedSourceDirectories in Compile. See https://github.com/sbt/sbt/issues/1664#issuecomment-213057686

benmccann avatar Apr 24 '20 18:04 benmccann