buildr > ant > maven

I chose buildr as our build tool for project candlepin, primarily because I don’t care for the large amounts of XML required by maven pom files. And ant seems to have become passe with most Java projects.

On project Spacewalk, we used checkstyle to ensure the code was consistently formatted, so I wanted to do this with candlepin as well. At the moment, there isn’t an official checkstyle plugin for buildr, but it has the ability to create ant tasks (in Ruby). Here is my task to run checkstyle against the candlepin codebase.

  #
  # CHECKSTYLE task, a Buildr plugin would be better, but this is faster
  #
  task :checkstyle do
    begin
      ant('checkstyle') do |ant|
        rm_rf 'reports/checkstyle_report.xml'
        mkdir_p 'reports'

        ant.taskdef :resource=>"checkstyletask.properties", :classpath=>Buildr.artifacts(CHECKSTYLE).each(&:invoke).map(&:name).join(File::PATH_SEPARATOR)
        ant.checkstyle :config=>"buildconf/checkstyle.xml" do
          ant.formatter :type=>'plain'
          ant.formatter :type=>'xml', :toFile=>"reports/checkstyle_report.xml"

          ant.property :key=>'javadoc.method.scope', :value=>'public'
          ant.property :key=>'javadoc.type.scope', :value=>'package'
          ant.property :key=>'javadoc.var.scope', :value=>'package'
          ant.property :key=>'javadoc.lazy', :value=>'false'
          ant.property :key=>'checkstyle.cache.file', :value=>'target/checkstyle.cache.src'
          ant.property :key=>'checkstyle.header.file', :value=>'buildconf/LICENSE.txt'

          ant.fileset :dir=>"src/main/java", :includes=>'**/*.java'
        end
      end
    end
  end

Notice the lack of XML :) that’s my favorite part. I think a better integration would be to write a plugin for buildr, but for now this will suffice. Now to go fix all 800 checkstyle errors I found.

About these ads

One response to “buildr > ant > maven

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s