Create jar for a scala hello world project with gradle

  1. versions JDK: jdk1.7.0_04 gradle: 2.1 scala: 2.11.2

2.build.gradle: apply plugin: ‘scala’

repositories {

maven { url “http://10.177.60.141:8888/nexus/content/groups/public/” } }

dependencies {

compile ‘org.scala-lang:scala-library:2.11.2’

compile ‘org.scala-lang:scala-compiler:2.11.2’ }

  1. src/main/scala/HelloWorld.scala

package main.scala

object HelloWorld {

def main(args: Array[String]): Unit = {

println(“hello world”)

} }

  1. execute “gradle build -stacktrace” , result: D:\Workfiles\Scala\gradle_project>gradle build -stacktrace :compileJava UP-TO-DATE :compileScala FAILED

FAILURE: Build failed with an exception.

  • What went wrong: Execution failed for task ‘:compileScala’. > scala/runtime/Nothing$

  • Try: Run with --info or --debug option to get more log output.

  • Exception is: org.gradle.api.tasks.TaskExecutionException: Execution failed for task ‘:compile Scala’.

at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.ex ecuteActions(ExecuteActionsTaskExecuter.java:69)

at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.ex ecuteActions(ExecuteActionsTaskExecuter.java:61)

… 44 more

Caused by: java.lang.ClassNotFoundException: scala.runtime.Nothing$

… 76 more

BUILD FAILED

Total time: 12.063 secs

when I use “scala 2.9.3”, gradle build result :

Caused by: java.lang.ClassNotFoundException: scala.ScalaObject

Can someone help me? Thx

when I user “scala 2.9.3”, gradle build result :

Caused by: java.lang.ClassNotFoundException: scala.ScalaObject

Please post the output of ‘gradle -v’ and the full stack traces (all wrapped in HTML code tags). Also remove the ‘scala-compiler’ dependency.

D:\Workfiles\Scala\gradle_project>gradle -v

------------------------------------------------------------ Gradle 2.1 ------------------------------------------------------------

Build time:

2014-09-08 10:40:39 UTC Build number: none Revision:

e6cf70745ac11fa943e19294d19a2c527a669a53

Groovy:

2.3.6 Ant:

Apache Ant™ version 1.9.3 compiled on December 23 2013 JVM:

1.7.0_04 (Oracle Corporation 23.0-b21) OS:

Windows 7 6.1 x86

After remove the scala-compiler dependency:

D:\Workfiles\Scala\gradle_project>gradle build :compileJava UP-TO-DATE :compileScala Download http://10.177.60.141:8888/nexus/content/groups/public/org/scala-lang/sc ala-compiler/2.11.2/scala-compiler-2.11.2.jar :compileScala FAILED

FAILURE: Build failed with an exception.

  • What went wrong: Execution failed for task ‘:compileScala’. > scala/runtime/Nothing$

Haven’t ever seen this before (and we have pretty extensive tests for this). Some things you can try:

  • Build the Scala samples that ship with the gradle-all distribution (without altering them in any way) * Try with Scala 2.10 * Use Maven Central rather than your Nexus * Set ‘tasks.withType(ScalaCompile) { scalaCompileOptions.useAnt = false }’ (also try with ‘scalaCompileOptions.useAnt = true’ and ‘scalaCompileOptions.fork = true|false’) * Try with an earlier Gradle version * Reinstall the JDK used to run Gradle, to make sure it’s not polluted with Scala libs * Post the full stack trace (’–full-stacktrace’)

Use another maven, build succeed. thx

apply plugin: ‘scala’

repositories {

maven { url “http://10.158.230.174:8081/nexus/content/groups/public/” }

}

dependencies {

compile ‘org.scala-lang:scala-library:2.10.4’

}