Question

I'm using sbt and its Proguard plugin to create an executable jar for my program. However, my program relies on scala-compiler.jar at runtime to do compilations. I can't seem to get scala-compiler.jar into my final jar. This page has some very similar information but I can't get it to work beginning to end. Any suggestions?

EDIT: This is the closest I have gotten:

override def proguardOptions = List(
  "-dontshrink -dontoptimize -dontobfuscate -dontpreverify -dontnote " +
  "-ignorewarnings",
  proguardKeepAllScala
)
override def proguardInJars =
  Path.fromFile(scalaLibraryJar) +++
  Path.fromFile(FileUtilities.scalaCompilerJar) +++
  super.proguardInJars

That includes the compiler jar in the proguard min jar, but running it I still get:

Exception: java.lang.NoClassDefFoundError: scala/tools/nsc/settings/Scala Settings
Was it helpful?

Solution

This works, but is sensitive to the location from which sbt is called:

//proguard                                                                    
override def proguardOptions = List(
  "-dontshrink -dontoptimize -dontobfuscate -dontpreverify -dontnote " +
  "-ignorewarnings",
  proguardKeepAllScala
)

val cur =  new File(".").getAbsolutePath
override def proguardInJars =
  Path.fromFile(scalaLibraryJar) +++
  Path.fromFile(
    new File(cur, "project/boot/scala-" + crossScalaVersionString +
             "/lib/scala-compiler.jar")) +++
  super.proguardInJars

I could not use FileUtilities.scalaCompilerJar because that gets the 2.7.7 jar that sbt uses, not the cross scala version compiler.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top