groovy.lang.missingMethodException when running code as a .jar

448 views Asked by At

I have this code in groovy to parse a json file:

File file = new File(configFile)
def config = new JsonSlurper().parse(file)

When I run it in Intellij it works just fine. I then build it to create a .jar then execute it in the terminal with: java -jar file.jar I get the following exception executing it:

    Exception in thread "main" groovy.lang.MissingMethodException: No signature of method: groovy.json.JsonSlurper.parse() is applicable for argument types: (File) values: [./resources/config.json]
Possible solutions: parse(java.io.Reader), use([Ljava.lang.Object;), wait(), any(), grep(), wait(long)
    at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:70)
    at org.codehaus.groovy.runtime.callsite.PojoMetaClassSite.call(PojoMetaClassSite.java:46)
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:47)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:125)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:139)
    at org.forgerock.migrator.ConfigLoader.loadConfig(ConfigLoader.groovy:35)
    at org.forgerock.migrator.ConfigLoader$loadConfig.call(Unknown Source)
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:47)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:125)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:139)
    at org.forgerock.migrator.processor.ProcessorFactory.getProcessor(ProcessorFactory.groovy:42)
    at org.forgerock.migrator.processor.ProcessorFactory$getProcessor.call(Unknown Source)
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:47)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:125)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:139)
    at org.forgerock.migrator.Migration.main(Migration.groovy:35)

I've confirmed the groovy version to be 3.0.1. I have also tried running this on java 8 and 11. Any suggestions would be appreciated. Thanks.

UPDATE:

Here is how I'm running the code with Groovy 3.0.1:

enter image description here

1

There are 1 answers

0
flacoding On

I have resolved this problem. While troubleshooting the problem I decided to completely ignore the compilation warnings and the warning was telling me that it was a conflict of Groovy versions in the project. This conflict came from a dependency I had in pom.xml. This specific dependency was adding Groovy 2.1.9 as a sub-dependency into the project so I had to remove it and the warning went away. Also JsonSlurper started working because now it was actually using version 3.0.1