Gradle 3 and Antlr


(steve) #1

Over the past few Gradle releases we have seen very different behavior in regards to its Antlr support for various versions. We happen to use both Antlr 2 and Antlr 4.5 in different projects and have had a massively hard time standardizing to any single version of Gradle across them. What are the plans for Antlr support in Gradle 3?

FWIW ATM I need to use Gradle 2.4 on the project using Antlr 4.5 : https://github.com/hibernate/hibernate-semantic-query

Gradle 3 works on the project using Antlr 2 : https://github.com/hibernate/hibernate-orm

However if I try to use Gradle 3 (m2) on that project using Antlr 4.5 (which is ultimately what I want to do), I then get tons of errors from Antlr.


(Eric Wendelin) #2

Hi Steve,

Thank you for the feedback.

I would find it very helpful if you could expand on the sorts of errors you’re getting with Antlr 4.5 with Gradle 3.0 M2. Could you please provide a build scan or at least a stack trace?

Cheers,
Eric


(steve) #3

Hi Eric,

The issue is the same as discussed elsewhere… namely a continuing change in how directory/packages are handled in the plugin. It keeps changing.

But I went ahead and created the build scan for you nonetheless: https://gradle.com/s/sqpg33e46u6i6


(steve) #4

Eric, any thoughts?

Here is what the User Guide has to say:

Production ANTLR grammar files. If the ANTLR grammar is organized in packages, the structure in the antlr folder should reflect the package structure. This ensures that the generated sources end up in the correct target subfolder.

But that is what I have. Yet this set up fails using Antlr 4.5 + any Gradle version newer than 2.4. The underlying problem, as far as I can tell, is that for some reason the lexical token file is created in the source dir and then Antlr tries to find it in the builddir:

error(160): org/hibernate/sqm/parser/hql/internal/antlr/HqlParser.g4:4:12: cannot find tokens file /home/sebersole/projects/hibernate/hibernate-semantic-query/build/generated-src/antlr/main/HqlLexer.tokens

HqlLexer.tokens actually is generated and does exist, but it was generated as /home/sebersole/projects/hibernate/hibernate-semantic-query/src/main/antlr/org/hibernate/sqm/parser/hql/internal/antlr/HqlLexer.tokens (src/main versus build/generated-src/antlr/main/). Also notice that the package dir structure is missing in terms of where Antlr is looking for it


(Eric Wendelin) #5

Hi Steve,

I have reproduced what you’re seeing. According to my testing, Gradle 2.6 works but 2.7 does not.

I have assigned https://issues.gradle.org/browse/GRADLE-3345 to myself and will continue investigating it. We’re branching for Gradle 3.0 tomorrow, so a fix would be more likely in 3.1.


(steve) #6

Thanks Eric! I will continue my comments there


(Kang) #7

I believe I had similar issues with gradle and antlr4. The issue I have is that the compiler cannot find the class files. They currently live in the default package; I believe the compiler should be able to find them there by default. Please advise, if this is indeed the same issue. .
I am using Gradle with Eclipse Buildship, Gradle Jdk 1.8+


(Schalk Cronjé) #8

I ran into similar issues with later versons of Gradle. in the end I had to throw away usage of Gradle’s antlr plugin and roll a custom one out for the Ceylon project - https://github.com/ceylon/ceylon/blob/gradle_build/buildSrc/src/main/groovy/CeylonAntlr.groovy.


(steve) #9

Schalk, I am going to try adopting your solution and adapting it to HIbernate’s build. But I am confused on this CeylonAntlr.Generate#antlrGroup concept. Could you explain that? Or even point me to a usage of it?

Thanks!


(Schalk Cronjé) #10

This is so that we can manage Antlr and it’s associated transitive dependencies in a different configuration. We then use this configuration later on to set up the classpath for the javaexec project extension.


(steve) #11

I think you are describing the antlr Configuration you create for adding Antlr dependencies. I am not asking about that. I asked about antlrGroup which seems to be how you pass the grammars-to-be-processed into the task.


(Schalk Cronjé) #12

Oh right, I misunderstood. Maybe this is best explained by way of usage: https://github.com/ceylon/ceylon/blob/gradle_build/typechecker/typechecker.gradle. The groups are used to contruct relative paths based upon a certain folder.

(This might be very opinionated for the Ceylon build as they only used it in one place in the build).


(steve) #13

Ok, so it just manually deals with packages. I see. Giving it a try, bbl…


(steve) #14

Schalk, oh you are using some older version of Antlr :frowning: Your rewrite does not work at all with Antlr 4 (4.5 at least). I’ve been picking away at it, but there is a lot to change.


(Schalk Cronjé) #15

True. I had to use 3.4 in that specific case. Good to know that it is failing in the later versions and would like to see what you come up with.


(steve) #16

I ended up just hardcoding a lot of values, but this is a version that works for Antlr4 in Gradle 2 and Gradle 3: https://gist.github.com/sebersole/cefdffe5b6569880f31ecb97425d957e