How to set memory on a per project basis in sbt? - scala

Currently, for a scala project I have to increase the memory to run its test via:
sbt -mem 2000 test
to set it to 2 GB.
I want to store the memory config in a file file inside the project (shared via git) so that every developer has this setting in place. Is that possible and if so how do I achieve that?
When I run:
sbt -v
[process_args] java_version = '8'
# Executing command line:
java
-Xms1024m
-Xmx1024m
-XX:ReservedCodeCacheSize=128m
-XX:MaxMetaspaceSize=256m
-jar
/usr/share/sbt/bin/sbt-launch.jar
I see that it defaults to 1024 MB, yet I fail to see where it gets that default values from nor how how to override it.
Sbt's man pages references as default: $sbt_mem, which is $(get_mem_opts $sbt_mem yet this also does not help my understanding on where to change it.

Try creating .jvmopts file at the root of the project like so
-Xmx2G
Also consider related answer https://stackoverflow.com/a/54725010/5205022

Related

Configuring SBT global settings

I need to permanently turn on the -verbose setting for SBT, without having to type it each time. What's the best way to do this? Putting -verbose in $SBT_OPTS does not have an effect.
-verbose flag can be enabled system-wide by saving it in global sbtopts configuration file. For example, on my machine, it is located at
/usr/local/etc/sbtopts
Here is an example of its contents
# set memory options
-mem 2048
# java version (default: java from PATH, currently $(java -version |& grep version))
-java-home /Library/Java/JavaVirtualMachines/adoptopenjdk-8.jdk/Contents/Home
-verbose
Addressing the comment regarding IntelliJ, note that IntelliJ Scala Plugin currently does not read global sbtopts, however it does have support for local .sbtopts configuration file, but it does not support every option provided by sbt launcher script proper:
Supported options:
-no-share, -no-global, -sbt-boot, -sbt-dir, -ivy, -jvm-debug,
all options with -D and -J prefixes
Unsupported options:
-S prefix seems to be unsupported by sbt-launcher itself
-mem has a bit untrivial algorithm, same thing can be achieved
by configuring -Xmx, -Xms, -XX:ReservedCodeCacheSize options
-sbt-version, -sbt-rc, -sbt-snapshot, -sbt-jar
and -java-home are overriden by IDEA options
Other options have no impact on project importing process
SbtOpts.scala should list all the supported options. One notable absence is support for -mem, which means if we put, say, -mem 4096 in .sbtopts, then IntelliJ will simply ignore it. Similarly, the flag -verbose will not be picked up by IntelliJ sbt runner.
Hence the key is to understand that sbt runner script proper is not the same as IntelliJ custom made sbt runner component.
if you use unix friendly environment, you can create an alias for sbt in your ~/.bash/profile for example
alias sbt=sbt -verbose

Travis CI ignoring MAVEN_OPTS?

My Scala project (Maven-managed) is failing to build on Travis, throwing a GC overhead limit exceeded error despite compiling fine locally with the same MAVEN_OPTS=-Xmx3g -XX:MaxPermSize=512m. I suspect that Travis is somehow ignoring my MAVEN_OPTS: When I try to test against Oracle JDK 8, Travis logs:
$ Setting environment variables from .travis.yml
$ export MAVEN_OPTS="-XX:MaxPermSize=512m -Xmx3g"
which looks good. However, soon after it logs:
Java HotSpot(TM) 64-Bit Server VM warning: ignoring option MaxPermSize=192m; support was removed in 8.0
which is troubling since NOWHERE am I specifying -XX:MaxPermSize=192m, only 512m. (This leads me to believe my -Xmx3g is also being ignored, causing the compilation failure.)
I tried specifying the MAVEN_OPTS in many additional places in my pom, to no avail. For example, for the maven-scala-plugin, I have:
<configuration>
...
<jvmArgs>
<jvmArg>-Xmx3g</jvmArg>
<jvmArg>-XX:MaxPermSize=512m</jvmArg>
</jvmArgs>
</configuration>
And I also have the following under the maven-surefire-plugin and scalatest plugin, though the build is failing during compilation not tests:
<configuration>
<argLine>-Xmx3g -XX:MaxPermSize=512m</argLine>
</configuration>
The following is the entirety of my .travis.yml:
language: java
env:
global:
- MAVEN_OPTS="-XX:MaxPermSize=512m -Xmx3g"
script: mvn clean install
jdk:
- oraclejdk8
- oraclejdk7
I'm using Scala 2.11.2 and scala-maven-plugin 3.2.0.
UPDATE (11/2/15):
This was finally fully resolved here. Quoting:
If you want to use container-based builds (not relying on sudo), you can echo what you want into a $HOME/.mavenrc file and that will take precedence over /etc/mavenrc, like so:
in .travis.yml:
before_script:
- echo "MAVEN_OPTS='-Xmx2g -XX:MaxPermSize=512m'" > ~/.mavenrc
(you could also put this in before_install depending on your setup).
Old answer:
I finally found the answer here, which references this (closed but not resolved) issue on the Travis CI github.
It seems like Travis exports a MAVEN_OPTS environment variable as root via the file /etc/mavenrc, which then does not get overridden by any other MAVEN_OPTS definitions (e.g. via env/global settings in the travis config). The workaround is to delete /etc/mavenrc before setting custom MAVEN_OPTS.
I was able to set custom MAVEN_OPTS and build successfully using the following in my .travis.yml:
script:
- sudo rm /etc/mavenrc
- export MAVEN_OPTS="-Xmx2469m -XX:MaxPermSize=512m"
- mvn clean install
Note that I am NOT using language: java in my travis config, just calling maven directly via the script directive.
export MAVEN_SKIP_RC=true is the recommended way of doing this when dealing with a system that has an /etc/mavenrc. This will make it ignore the defaults and read the MAVEN_OPTS variable.
While it is possible to set -Xmx3g in Travis CI builds, its servers have limited memory to be free for JVM heap in forked surefire tests.
Here is project that use -Xmx2560m for max speed on Travis CI:
https://github.com/plokhotnyuk/actors/blob/8f22977981e0c4d21b67beee994b339eb787ee9a/pom.xml#L151
You can check available memory by - sudo cat /proc/meminfo line added to .travis.yml. Here is output from some Travis CI build: https://travis-ci.org/plokhotnyuk/actors/jobs/55013090#L923
If your project requires bigger heap size then try https://www.shippable.com
Or it is better to use Wercker (much faster builds and without waiting in queue at all) http://wercker.com
This is what finally worked for me.
language: java
sudo: false
jdk:
- oraclejdk8
install: MAVEN_SKIP_RC=true MAVEN_OPTS="-Xss4M" mvn install -DskipTests=true
script: MAVEN_SKIP_RC=true MAVEN_OPTS="-Xss4M" mvn
The MAVEN_SKIP_RC is needed as #adam says and the MAVEN_OPTS are what I needed to get javac to stop blowing out the stack.

Gradle not able to install properly

I am trying to install the gradle 1.3 on window 7 machine and did the following steps
1.Downloaded the gradle-1.3.all.zip from http://www.gradle.org/ url
2.Extracted it to F:\localRepository\gradle-1.3
3.Set the environment variables
GRADLE_HOME=F:\localRepository\gradle-1.3
GRADLE_OPTS=F:\localRepository\gradle-1.3\bin
PATH = F:\localRepository\gradle-1.3\bin;F:\jdk1.7.0_21\bin
JAVA_HOME=F:\jdk1.7.0_21
JAVA_OPTS=F:\jdk1.7.0_21\bin
4.RUN gradle in CMD
5.getting
"Could not find or load main class F:\jdk1.7.0_21\bin"
Can anyone suggest me what I am missing here?
Those JAVA_OPTS look suspicious to me. What are you trying to achieve by setting them to that?
If you look at gradle.bat (in F:\localRepository\gradle-1.3\bin) you'll see this line which actually launches Java to run Gradle:
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.launcher.GradleMain %CMD_LINE_ARGS%
So as far as Java's concerned, your %JAVA_OPTS% looks like the name of the main class. Everything after that just gets parsed as parameters.
JAVA_OPTS is for the parameters you want to pass to the JVM.
Your GRADLE_OPTS also looks a bit unusual.
about the JAVA_OPTS and GRADLE_OPTS I'm citing from Gradle documentation:
JVM OPTIONS
JVM options for running Gradle can be set via environment variables. You can use GRADLE_OPTS >or JAVA_OPTS. Those variables can be used together. JAVA_OPTS is by convention an environment >variable shared by many Java applications. A typical use case would be to set the HTTP proxy >in JAVA_OPTS and the memory options in GRADLE_OPTS. Those variables can also be set at the >beginning of the gradle or gradlew script.
http://www.gradle.org/installation
But in general it's not suitable placeholder for bin folder. You better define your Path variable as:
Path=%JAVA_HOME%\bin;%GRADLE_HOME%\bin;
and remove or redefine your JAVA_OPTS or GRADLE_OPTS variables.

Eclipse run error

When i try to run my code on Eclipse this error appears:
Usage: javaw [-options] class [args...]
(to execute a class)
or javaw [-options] -jar jarfile [args...]
(to execute a jar file)
where options include:
-d32 use a 32-bit data model if available
-d64 use a 64-bit data model if available
-server to select the "server" VM
-hotspot is a synonym for the "server" VM [deprecated]
The default VM is server.
-cp <class search path of directories and zip/jar files>
-classpath <class search path of directories and zip/jar files>
A ; separated list of directories, JAR archives,
and ZIP archives to search for class files.
-D<name>=<value>
set a system property
-verbose:[class|gc|jni]
enable verbose output
-version print product version and exit
-version:<value>
require the specified version to run
-showversion print product version and continue
-jre-restrict-search | -no-jre-restrict-search
include/exclude user private JREs in the version search
-? -help print this help message
-X print help on non-standard options
-ea[:<packagename>...|:<classname>]
-enableassertions[:<packagename>...|:<classname>]
enable assertions with specified granularity
-da[:<packagename>...|:<classname>]
-disableassertions[:<packagename>...|:<classname>]
disable assertions with specified granularity
-esa | -enablesystemassertions
enable system assertions
-dsa | -disablesystemassertions
disable system assertions
-agentlib:<libname>[=<options>]
load native agent library <libname>, e.g. -agentlib:hprof
see also, -agentlib:jdwp=help and -agentlib:hprof=help
-agentpath:<pathname>[=<options>]
load native agent library by full pathname
-javaagent:<jarpath>[=<options>]
load Java programming language agent, see java.lang.instrument
-splash:<imagepath>
show splash screen with specified image
See http://www.oracle.com/technetwork/java/javase/documentation/index.html for more details.
i try to coment my entired code and this error still appear.
It seems you haven't set your java path correctly.
Setting Up Eclipse with Java 1.6 on Windows
How To Install and Get Started with Java Programming
Run eclipse in clean mode
Edit the eclipse.ini file located in your Eclipse install directory and insert -clean as the first line.
If this is happening to a specific project only and other projects are running fine then your default run configuration might have changed. You may try the following
- Run -> Run As -> 1 Java Application.
I fixed this issue by deleting some of my old runtime configurations. Eclipse then started automatically generating them again.

sbt: Unable to specify application configuration in mingw

I am trying to launch an application using sbt's application launcher.
This application is defined as:
#!/bin/sh
java -jar /home/salil.wadnerkar/.conscript/sbt-launch.jar #"/home/salil.wadnerkar/.conscript/n8han/conscript/cs/launchconfig" "$#"
However, when I launch it, it gives me this error:
$ ~/bin/cs n8han/giter8
Error during sbt execution: Could not find configuration file 'C:/MinGW/msys/1.0/home/salil.wadnerkar/.conscript/n8han/conscript/cs/launchconfig'. Searched:
file:/C:/MinGW/msys/1.0/home/salil.wadnerkar/
file:/C:/Users/salil.wadnerkar/
file:/C:/MinGW/msys/1.0/home/salil.wadnerkar/.conscript/
However, the file is present there. So, I think it's because of some quirk in the way sbt handles mingw file path.
Does anybody know how I can get it working?
In Cygwin I used
java -jar "`cygpath -m "$HOME/.conscript/sbt-launch.jar"`" "#file:///C:/Users/cvanvranken/.conscript/n8han/conscript/cs/launchconfig" "$#"
I expect you will be able to get yours to work with something similar, perhaps this:
java -jar /home/salil.wadnerkar/.conscript/sbt-launch.jar "#file:///C:/Users/salil.wadnerkar/.conscript/n8han/conscript/cs/launchconfig" "$#"
or
java -jar /home/salil.wadnerkar/.conscript/sbt-launch.jar "#file:///C:/MinGW/msys/1.0/home/salil.wadnerkar/.conscript/n8han/conscript/cs/launchconfig" "$#"
if those fail, you still definitely need to use the file:// protocol.
Also note the three directories it is searching in the error message
file:/C:/MinGW/msys/1.0/home/salil.wadnerkar/
file:/C:/Users/salil.wadnerkar/
file:/C:/MinGW/msys/1.0/home/salil.wadnerkar/.conscript/
no matter what you put in the launchconfig parameter, if it is not recognized then those directories are searched by default. So you could have gibberish in your parameter and still see the same exact error you are getting now.
you can set the launch config path relative to the .conscript folder -
java -jar /home/salil.wadnerkar/.conscript/sbt-launch.jar #n8han/conscript/cs/launchconfig "$#"