Skip to content
Gábor Szárnyas edited this page Jun 19, 2016 · 20 revisions

Groovy

On Linux, Gradle does not install a separate Groovy engine. The Ubuntu PPA packages are quite outdated, so the simplest solution is to use sdkman.

Tutorials

Troubleshooting

Building Groovy script using Grapes & Grab with Gradle

Problem: You're trying to build a Groovy script using Gradle, and the script uses Grapes/Grab to resolve its dependencies. However, gradle build throws an exception (displayed here with gradle build --stacktrace).

* What went wrong:
Execution failed for task ':compileGroovy'.
> org/apache/ivy/core/report/ResolveReport
[...]
* Exception is:
org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':compileGroovy'.
[...]
Caused by: java.lang.NoClassDefFoundError: org/apache/ivy/core/report/ResolveReport
	at org.gradle.api.internal.tasks.compile.ApiGroovyCompiler.execute(ApiGroovyCompiler.java:167)
	at org.gradle.api.internal.tasks.compile.ApiGroovyCompiler.execute(ApiGroovyCompiler.java:54)
	at org.gradle.api.internal.tasks.compile.daemon.CompilerDaemonServer.execute(CompilerDaemonServer.java:55)
	at org.gradle.messaging.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:35)
	at org.gradle.messaging.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
	at org.gradle.messaging.remote.internal.hub.MessageHub$Handler.run(MessageHub.java:364)
	... 2 more
Caused by: java.lang.ClassNotFoundException: org.apache.ivy.core.report.ResolveReport
	... 8 more

Solution: Add the ivy configuration (see the example).

apply plugin: 'groovy'

repositories {
  mavenCentral()
}

configurations {
  ivy
}

dependencies {
  compile group: 'org.codehaus.groovy', name: 'groovy', version: '2.4.6'
  ivy group: 'org.apache.ivy', name: 'ivy', version: '2.4.0'
}

tasks.withType(GroovyCompile) {
  groovyClasspath += configurations.ivy
}

"That said, a better approach is to manage dependencies with Gradle." (Source: http://stackoverflow.com/questions/18173908/error-compiling-a-groovy-project-using-grab-annotation)

So you're generally much better off using Gradle to resolve the dependencies as well:

apply plugin: 'groovy'

dependencies {
  compile localGroovy()
}

sourceSets {
  main {
    groovy {
      srcDir '.'
    }
  }
}

task runScript(dependsOn: 'classes', type: JavaExec) {
  main = 'benchmark'
  classpath = sourceSets.main.runtimeClasspath
}

The localGroovy() dependency places the local Groovy sources to the classpath. The srcDir part sets the source directory to the current directory. To run the script, use the runScript goal:

$ gradle runScript

Sesame cannot find RDF format

Problem: ``` Exception in thread "main" org.openrdf.rio.UnsupportedRDFormatException: No parser factory available for RDF format Turtle (mimeTypes=text/turtle, application/x-turtle; ext=ttl)


**Solution:** 

As described in the [documentation](http://imperceptiblethoughts.com/shadow/), simply add:
```groovy
shadowJar {
  mergeServiceFiles()
}

Re-run Gradle with gradle clean shadowJar.

The related Maven question is discussed on Stack Overflow

Clone this wiki locally