0

I am working on adding checkstyle to the build process of a java project. The results of the checkstyle will be later displayed on jenkins. I am using java7 & netbeans 7.2.1

For most of the work I am following the instructions on this page: http://checkstyle.sourceforge.net/anttask.html

However, i'm a beginner in java (& jenkins) and some of the instructions do not make sense to me:

1- The doc says: "To use the task in a build file, you will need the following taskdef declaration: ". Question: is this to be added in the build.xml file? or where?

2- Then the doc goes on describing a set of parameters and provides some examples. Are these to be added to build.xml too? or?

3- Checkstyle uses a configuration file. I'll be using the standard sun_checks.xml. Where should this be placed?

If someone can point me out to a step by step tutorial for the whole process, i'd be most grateful. Thx in advance for all answers

I am using the following in my build.xml:

<taskdef resource="checkstyletask.properties"
     classpath="libs/checkstyle-5.6-all.jar"/>

<target name="checkstyle"
        description="Generates a report of code convention violations.">

    <checkstyle config="sun_checks.xml"
                  failureProperty="checkstyle.failure"
                  failOnViolation="false">
        <fileset dir="src" includes="**/*.java"/>
        <formatter type="xml" toFile="checkstyle-results.xml"/>
    </checkstyle>

    <style in="checkstyle-results.xml" out="checkstyle_report.html" style="checkstyle.xsl"/>

</target>
1
  • An alternative approach would be to use Sonar. Checkstyle is one of the tools automatically run on your project. Commented Dec 28, 2012 at 16:45

2 Answers 2

1
  1. yes, you must add it in your build.xml

  2. These attributes and elements are attributes and elements of the <checkstyle> ant task, which you can use in your build file thanks to the taskdef you have added in point 1. And yes, this <checkstyle> task must be used in your build.xml.

  3. You place it wherever you want. you just need to give its path to the <checkstyle> task using its config attribute.

Sign up to request clarification or add additional context in comments.

3 Comments

Thx for the answer JB Nizet Shouldn't i get the report xml file when i "ant all"? Please check the edited question for the script i'm using in build.xml
It's impossible to say, as you don't show what the all target does. ant all doesn't mean "execute all the targets". It means "execute the target named all (and its dependencies).
right right! again, newb mistake. i had to add checkstyle to the "all" target <target name="all" description="build all programs" depends="junit_test, checkstyle"/> thx again
0

I am not sure what build management you are using. If you are using Gradle, you can use gradle-estilo-plugin. It sets up the entire checkstyle configuration you need directly from a gradle config block.

Here is what you'll need to get started:

buildscript {
  repositories {
    mavenCentral()
  }

  dependencies {
    classpath 'net.anshulverma.gradle:gradle-estilo-plugin:0.4.8'
  }
}

apply plugin: 'net.anshulverma.gradle.estilo'

estilo {
  source 'sun'
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.