SBT ProGuard plugin: OutOfMemoryError, how to increase a bunch of space?

When I try to build a jar for my project using the sbt-proguard plugin, I always get an Exception in thread "main" java.lang.OutOfMemoryError: Java heap space

I tried to increase the heap of space for sbt, but it turned out that the proguard plugin starts its own java process and has the -Xmx256M hardcoded parameter. I cannot figure out how to change it without changing the proguard code itself.

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

I tried 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 to pass Java parameters to proguard plugin or solve this problem?

+4
source share
2 answers

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

Update

Well, I know that I know what the problem is. If you print the following command in an sbt session:

 show proguard::java-options 

it will print you the [info] List(-Xmx2G) , which means that in your proguard configuration the heap size is set to 2GB , but if you try this command: show proguard:proguard::java-options , it will show you the [info] List(-Xmx256M) , which is used in proguardTask. Taking this into account, I assume that you have something similar in the project settings:

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

Basically what happens, proguardSettigns uses the default configuration and erases your javaOptions settings by the fact that the task uses the task pane for this command.

So add this line:

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

to your settings, it should look something like 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 the [info] List(-Xmx2G) . You can also enable the global log for the session and see if everything is fine: set logLevel in Global := Level.Debug

Update

I prefer the Build.scala files, but in *.sbt simpler, just add these lines in the following order:

 import com.typesafe.sbt.SbtProguard._ import com.typesafe.sbt.SbtProguard.ProguardKeys.proguard proguardSettings javaOptions in (Proguard, proguard) := Seq("-Xmx2G") 

maintaining order and line breaks between lines

+7
source

This answer did not work for me with the later SBT / sbt-proguard.

With the recent sbt-proguard plugin and SBT 0.13.1, I was 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")) 
+6
source

Source: https://habr.com/ru/post/1490440/


All Articles