Skip to content

Instantly share code, notes, and snippets.

@mrdziuban mrdziuban/scala_repl.rb
Last active Mar 6, 2018

Embed
What would you like to do?
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
You can’t perform that action at this time.