Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wrong sbt script sbtopts files proiority #7179

Open
lobachpavel opened this issue Mar 17, 2023 · 0 comments
Open

wrong sbt script sbtopts files proiority #7179

lobachpavel opened this issue Mar 17, 2023 · 0 comments
Labels

Comments

@lobachpavel
Copy link

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") "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant