Skip to content

wrong sbt script sbtopts files proiority #7179

@lobachpavel

Description

@lobachpavel

steps

assume that sbt script is located in /opt/sbt/bin, so sbt home is /opt/sbt/

cd any_project_dir
# put default options
echo "-Dsbt.repository.config=/opt/sbt/conf/repositories" >/opt/sbt/conf/sbtopts
# put project options
echo "-Dsbt.repository.config=repositories" >.sbtopts
# run any sbt command in debug mode
sbt -d sbtVersion

problem

this is the actual output

[addSbt] arg = '-debug'
[residual] arg = 'sbtVersion'
[residual] arg = 'sbtVersion'
[sbt_options] declare -a sbt_options=()
[process_args] java_version = '17'
[addMemory] arg = '1024'
[addJava] arg = '-Xms1024m'
[addJava] arg = '-Xmx1024m'
[addJava] arg = '-Xss4M'
[addJava] arg = '-XX:ReservedCodeCacheSize=128m'
[addJava] arg = '-Dsbt.script=/opt/sbt/bin/sbt'
downloading sbt launcher 1.8.2
[copyRt] java9_rt = '/root/.sbt/1.0/java9-rt-ext-eclipse_adoptium_17_0_6/rt.jar'
copying runtime jar...
[addJava] arg = '-Dscala.ext.dirs=/root/.sbt/1.0/java9-rt-ext-eclipse_adoptium_17_0_6'
# Executing command line:
java
-Dfile.encoding=UTF-8
-Dsbt.repository.config=repositories
-Dsbt.repository.config=/opt/sbt/conf/repositories
-Xms1024m
-Xmx1024m
-Xss4M
-XX:ReservedCodeCacheSize=128m
-Dsbt.script=/opt/sbt/bin/sbt
-Dscala.ext.dirs=/root/.sbt/1.0/java9-rt-ext-eclipse_adoptium_17_0_6
-jar
/root/.sbt/cache/boot/sbt-launch/1.8.2/sbt-launch-1.8.2.jar
-debug
sbtVersion

so our project options have been put at the beginning of cmd line and hence overridden by the dist default options from /opt/sbt/conf/sbtopts
this happens because options from the sbtopts files are pushed to the beginning of the command line

here is the excerpt form the sbt script:

# Here we pull in the default settings configuration.
[[ -f "$dist_sbt_opts_file" ]] && set -- $(loadConfigFile "$dist_sbt_opts_file") "$@"

# Here we pull in the global settings configuration.
[[ -f "$etc_file" ]] && set -- $(loadConfigFile "$etc_file") "$@"

# Pull in the project-level config file, if it exists.
[[ -f "$sbt_opts_file" ]] && set -- $(loadConfigFile "$sbt_opts_file") "$@"

expectation

priority of the files must be exactly inverse (from higher to lower) :

  • project .sbtopts
  • system global settings /etc/sbt/sbtopts
  • dist defafult settings ${sbt_home}/conf/sbtopts

notes

fix is trivial: we just need to reorder the above code like that:

# Pull in the project-level config file, if it exists.
[[ -f "$sbt_opts_file" ]] && set -- $(loadConfigFile "$sbt_opts_file") "$@"

# Here we pull in the global settings configuration.
[[ -f "$etc_file" ]] && set -- $(loadConfigFile "$etc_file") "$@"

# Here we pull in the default settings configuration.
[[ -f "$dist_sbt_opts_file" ]] && set -- $(loadConfigFile "$dist_sbt_opts_file") "$@"

Metadata

Metadata

Assignees

No one assigned

    Labels

    Bugarea/runner-scriptissues around sbt-the-bash-script, or bat script

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions