I cannot stand Maven. It makes me nauseous. However that does not seem to be the case for other institutionalised developers. Here’s what I did on a project where I wanted to isolate its craziness and still use jruby and rake.
namespace :maven do
M2_HOME = "binaries/apache-maven-3.0.3"
desc "Run the maven package goal"
task :package => :clean do
mvn "package"
end
desc "Run the application"
task :application => :clean do
mvn "test-compile", "exec:java", "-Dexec.mainClass=com.example.Application", "-Dexec.classpathScope=test"
end
desc "Run the maven dependencies report"
task :dependencies do
mvn "dependency:tree", "-DoutputFile=deps.txt"
end
def mvn(*args)
require 'java'
m2_conf = "#{M2_HOME}/bin/m2.conf"
classpath = "#{M2_HOME}/boot/plexus-classworlds-2.4.jar"
java.lang.System.setProperty('maven.home', M2_HOME)
java.lang.System.setProperty('classworlds.conf', m2_conf)
require classpath
include_class Java::org.codehaus.plexus.classworlds.launcher.Launcher
exit_code = Launcher.mainWithExitCode(args.flatten.to_java(:string))
puts "Maven has completed with exit code: #{exit_code}"
fail 'Build failed' if exit_code != 0
end
end
You foul rancid beast.