Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SBT ProGuard plugin: OutOfMemoryError, how to increase heapspace?

When trying to assemble a jar for my project with the sbt-proguard plugin, I invariably get an Exception in thread "main" java.lang.OutOfMemoryError: Java heap space

I tried increasing the heap space for sbt, but it turns out the proguard plugin spawns its own java process and has the -Xmx256M parameter hardcoded. I can't figure out how to change it, short of changing the proguard code itself.

I am using sbt-proguard plugin 0.2.1 with sbt 0.12.3 and Scala 2.10.1 on JDK 7

I have tried the setting javaOptions in proguard := Seq("-Xmx2G") as well as javaOptions in proguard += "-Xmx2G", but the plugin seems to ignore/overwrite this:

> ps aux|grep java
kaeser         47084 105.1  1.1  2927540  94440 s000  R+   10:07AM   0:05.52 /usr/bin/java -Xmx256M -cp /Users/kaeser/.ivy2/cache/net.sf.proguard/proguard-base/jars/proguard-base-4.9.jar proguard.ProGuard -include /Users/kaeser/Documents/workspace/pipeline-runner/target/scala-2.10/proguard/configuration.pro
kaeser         45087   0.0  6.3  5312012 531028 s000  S+    6:03PM   1:24.88 /usr/bin/java -Xmx2G -Xms512M -Xmx2G -Xss1M -XX:MaxPermSize=512m -XX:+CMSClassUnloadingEnabled -XX:+UseConcMarkSweepGC -Xshare:off -jar /usr/local/Cellar/sbt/0.12.3/libexec/sbt-launch.jar

How might I pass Java options to the proguard plugin, or otherwise solve this issue?

like image 340
Justin Kaeser Avatar asked Jul 09 '13 07:07

Justin Kaeser


2 Answers

add javaOptions in proguard := Seq("-Xmx...") line to your project settings

Updated

Ok i guess i know what your problem is. If you print in sbt session the following command:

show proguard::java-options

it will print you [info] List(-Xmx2G), this means that in you proguard configuration heap size is set to 2GB, but if you try this command: show proguard:proguard::java-options it will show you [info] List(-Xmx256M) which is used in the proguardTask. Taking this in consideration i'm guessing that you have something like this in you project settings:

 lazy val main = Project(
    id = "project",
    base = file("."),
    settings = Seq(javaOptions in proguard := Seq("-Xmx2G")) ++ proguardSettings)

Basicly what is happening, proguardSettigns using default configuration and erases your javaOptions settings with the fact that task is using task scope for the command.

So add this line:

javaOptions in (SbtProguard.Proguard, proguard) := Seq("-Xmx2G")

to your settings, it should looks similar to this:

lazy val main = Project(
  id = "project",
  base = file("."),
  settings =  proguardSettings ++ Seq(
    javaOptions in (SbtProguard.Proguard, proguard) := Seq("-Xmx2G")
  )

and now call show proguard:proguard::java-options it will show you [info] List(-Xmx2G). You can also turn on global logging for the session and see if everything is ok: set logLevel in Global := Level.Debug

Update

I prefer Build.scala files, but in *.sbt it's simpler, just add this lines in this order:

import com.typesafe.sbt.SbtProguard._
import com.typesafe.sbt.SbtProguard.ProguardKeys.proguard

proguardSettings

javaOptions in (Proguard, proguard) := Seq("-Xmx2G")

preserving the order and linebreak between the lines

like image 166
4lex1v Avatar answered Nov 11 '22 16:11

4lex1v


The above answer was not working for me with more recent SBT/sbt-proguard.

With the recent sbt-proguard plugin and SBT 0.13.1, I have been able to get the following to work:

name := "project"

organization := "scott.andy"

version := "0.0.0"

scalacOptions := Seq("-deprecation", "-unchecked")

proguardSettings

ProguardKeys.options in Proguard ++= Seq("-dontnote", "-dontwarn", "-ignorewarnings")

ProguardKeys.options in Proguard += ProguardOptions.keepMain("scott.andy.project.Main")

inConfig(Proguard)(javaOptions in ProguardKeys.proguard := Seq("-Xmx2g"))
like image 29
Andy Avatar answered Nov 11 '22 15:11

Andy