Skip to content

Instantly share code, notes, and snippets.

@cacoco
Created July 18, 2012 17:13
Show Gist options
  • Save cacoco/3137530 to your computer and use it in GitHub Desktop.
Save cacoco/3137530 to your computer and use it in GitHub Desktop.
Apache Buildr Task for Generating Java sources using the Java Annotation Processor
AWS_JAVA_SDK_BUILD_TOOLS = ["com.amazonaws:aws-java-sdk:jar:1.3.10",
"com.amazonaws:aws-java-sdk-flow-build-tools:jar:1.3.10"]
# The following is assumed to be embedded inside a project definition, otherwise
# you will need to pass the project to the task.
...
# Task for Generating Sources via Java APT, note this overwrites any current source
task :apt do
rm_rf project.path_to(:src, :generated, :java)
mkdir_p project.path_to(:src, :generated, :java)
classpath = Buildr.artifacts(AWS_JAVA_SDK_BUILD_TOOLS).each(&:invoke).map(&:to_s)
classpath << project.path_to(:target, :classes)
Buildr.ant("apt") do |ant|
ant.apt :includeantruntime => false,
:fork => true,
:optimize => "on",
:srcdir => project.path_to(:src, :main, :java), # what files to use as input
:classpath => classpath.join(File::PATH_SEPARATOR), # what's the classpath, the aws build tools jar needs to be here
:source => "1.5", # APT only works with 1.5 or lower...
:verbose => true do
ant.compilerarg :line => "-proc:only" # don't compile, process only
ant.compilerarg :line => "-s #{project.path_to(:src, :generated, :java)}" # where to put the generated source
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment