ammianus
ammianus

Reputation: 488

Gradle Antlr plugin fails Could not initialize class org.antlr.tool.ErrorManager with Antlr 3.5.2

I am trying to run a generate source from Antlr v3 grammar files from an older project, previously generated using Antlr Eclipse plugin. I was trying to use the Gradle Antlr plugin, and trying to use the latest antlr 3 jar as a dependency (3.5.2). My environment is Mac OSX, and using Java 8.

In my build.gradle I have

apply plugin: 'antlr'

dependencies {
  antlr "org.antlr:antlr:3.5.2"
  antlr group:'org.antlr', name: 'ST4', version: '4.1'
}

Running task generateGrammarSource results in error:

Failed to run Gradle ANTLR Worker Could not initialize class org.antlr.tool.ErrorManager

the --stacktrace option has class initialization error for this class

Caused by: java.lang.NoClassDefFoundError: Could not initialize class org.antlr.tool.ErrorManager at org.antlr.Tool.process(Tool.java:426) at org.gradle.internal.reflect.JavaMethod.invoke(JavaMethod.java:73) at org.gradle.api.plugins.antlr.internal.AntlrExecuter$Antlr3Tool.invoke(AntlrExecuter.java:72) at org.gradle.api.plugins.antlr.internal.AntlrExecuter$AntlrTool.doProcess(AntlrExecuter.java:143) at org.gradle.api.plugins.antlr.internal.AntlrExecuter$AntlrTool.process(AntlrExecuter.java:113) at org.gradle.api.plugins.antlr.internal.AntlrExecuter.runAntlr(AntlrExecuter.java:51) at org.gradle.process.internal.worker.request.WorkerAction.run(WorkerAction.java:100) at org.gradle.process.internal.worker.request.WorkerAction.runThenStop(WorkerAction.java:83) ... 8 more

I have not found any similar errors, and looking at source for ErrorManager, it's not clear what the error is.

Upvotes: 0

Views: 661

Answers (1)

ammianus
ammianus

Reputation: 488

Seems I resolved it myself by adding another dependency on antlr-runtime in the build.gradle file

dependencies {
  antlr "org.antlr:antlr:3.5.2"
  antlr "org.antlr:antlr-runtime:3.5.2"
  antlr group:'org.antlr', name: 'ST4', version: '4.1'
}

Upvotes: 0

Related Questions