Skip to content

Instantly share code, notes, and snippets.

@pmahoney
Created August 31, 2012 21:59
Show Gist options
  • Save pmahoney/3559745 to your computer and use it in GitHub Desktop.
Save pmahoney/3559745 to your computer and use it in GitHub Desktop.
# Runs maven if we are a JRuby process. Currently not used.
#
# See http://watchitlater.com/blog/2011/08/jruby-rake-and-maven/
def mvn(*args)
mvn = catch(:mvn) do
ENV['PATH'].split(::File::PATH_SEPARATOR).each do |path|
Dir.glob(::File.join(path, 'mvn')).each do |file|
if ::File.executable?(file)
throw :mvn, if ::File.symlink?(file)
::File.readlink(file)
else
file
end
end
end
end
end
raise 'No maven found on $PATH' unless mvn
mvn_home = ::File.expand_path(::File.join(mvn, '..', '..'))
m2_conf = ::File.expand_path(::File.join(mvn_home, 'bin', 'm2.conf'))
java.lang.System.setProperty('maven.home', mvn_home)
java.lang.System.setProperty('classworlds.conf', m2_conf)
Dir[::File.join(mvn_home, 'boot', '*.jar')].each do |jar|
require jar
end
launcher = Java::org.codehaus.plexus.classworlds.launcher.Launcher
exit_code = launcher.mainWithExitCode(args.flatten.to_java(:string))
raise "Maven exited #{exit_code}" unless exit_code == 0
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment