Gradle Error while building a scala code

Hi,

I am facing one issue with gradle while building scala code.

$gradle makeJar
Error : org.gradle.api.tasks.TaskExecutionException : Execution failed for task ‘:compileScala’.
Caused by : java.lang.NoClassDefFoundError: scala/Function1

$gradle -v
Gradle version - 1.6
groovy - 1.8.6
Ant - 1.8.4
ivy - 2.2.0
jvm - 1.7.0_55
OS - Linux 2.6x

My build.gradle file is below -

sourceCompatibility = ‘1.6’
apply plugin: ‘scala’
def mypath = ‘file://’+new File(‘test/lib’).absolutePath
repositories {
flatDir dirs:"${mypath}"
}
configurations{
scalaPackage
}
sourceSets{
main{
scala{
srcDirs = [‘test/src/scala’]
}
}
}
dependencies {
compile fileTree(dir: mypath, includes: [’*.jar’])
}
task sourcePath{
sourceSets.main.scala.srcDirs = sourceSets.main.scala.srcDirs
sourceSets.main.java.srcDirs = []
}
task makeJar(type: Jar, dependsOn: compileScala){
archivename = "mytest.jar"
destinationDir = file(“test/oplib”)
from "build/classes"
classpath = configurations.scalaPackage
}
compileScala.dependsOn sourcePath

Here my scala source code is present in - ./test/src/scala/test.scala
scala jar files present in - ./test/lib
expected output location - ./test/oplib

Is there anything wrong with build.gradle file which might be resulting in this error. Kindly suggest.

Many Thanks, Pralay

I’m not sure if this relates to your final error but what do you want to achieve with this custom task ?

What it actually does is

  • during the configuration phase, set to main scala srcDirs to themselves
  • during the configuration phase, empty the main java srcDirs (which where never set anyway)
    this task does nothing during the execution phase

Hi Francois,

You are right. But this custom task didn’t contribute to final error, as i have tried to run again without this task and i got the same error.

Execution failed for task ‘:compileScala’.

scala/Function1

$gradle makeJar --stacktrace

java.lang.NoClassDefFoundError: scala/Function1

Thanks, Pralay