Skip to content

Instantly share code, notes, and snippets.

@mrdziuban
Last active March 6, 2018 07:18
Show Gist options
  • Save mrdziuban/54098117df1c1511b782538e69ec4ab6 to your computer and use it in GitHub Desktop.
Save mrdziuban/54098117df1c1511b782538e69ec4ab6 to your computer and use it in GitHub Desktop.
Start a Scala REPL with the highest version of each jar in $HOME/.ivy2/cache on the classpath
#!/usr/bin/env ruby
################################################################################
# #
# Starts a Scala REPL with the highest version of each jar in #
# $HOME/.ivy2/cache on the classpath. #
# #
# See below for installation instructions #
# #
################################################################################
scala_version = /version (\d+\.\d+)/i.match(`scala -version 2>&1`)[1].to_sym
version_exclusions = {
:"2.10" => ['2.11', '2.12'],
:"2.11" => ['2.10', '2.12'],
:"2.12" => ['2.10', '2.11']
}
jars = Dir["#{ENV['HOME']}/.ivy2/cache/**/*.jar"]
.select { |j| !!(j =~ /\d+\.\d+(\.\d+)?(-((M|(RC))\d+)|SNAPSHOT)?\.jar$/i) }
.reject { |j| !!(j =~ /(scala_)?(#{version_exclusions[scala_version].map { |e| Regexp.escape(e) }.join('|')})(-)?/i) }
.group_by { |j| j.split('/').last.split(/\d\./)[0] }
.values
.map { |js| js.max_by { |j| Gem::Version.new(/([\d\.]+)\.jar$/i.match(j)[1]) } }
exec("scala -cp #{jars.join(':')}")
__END__
To install and run (requires ruby):
curl -sSL https://gist.github.com/mrdziuban/54098117df1c1511b782538e69ec4ab6/raw > ./repl \
&& chmod +x ./repl \
&& ./repl
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment