Friday, June 17, 2011

Gradle Sonar source compatibility

I'm slowly migrating a large project to Gradle. One of the major selling points is the Sonar plugin. I switched a module to Gradle and ran the 'gradle sonar' command. I got a screen full of exceptions that looked like this:

Fail to execute PMD. Following file is ignored:
/Users/spina/Code/apt/StagingGround/Utilities/src/main/java/gov/nasa/gsfc/util/VersionChecker.java
net.sourceforge.pmd.ast.ParseException: Can't use annotations when running in JDK 1.4 mode!
at net.sourceforge.pmd.ast.JavaParser.checkForBadAnnotationUsage(JavaParser.java:32)
at net.sourceforge.pmd.ast.JavaParser.MarkerAnnotation(JavaParser.java:5353)
at net.sourceforge.pmd.ast.JavaParser.Annotation(JavaParser.java:5272)
at net.sourceforge.pmd.ast.JavaParser.Modifiers(JavaParser.java:347)


I was building for Java 7. I did the obvious google searches and didn't find an answer. A bit more work and I found the solution here. Basically, I needed to add the following to my build.gradle file:

sonar {
// Tell sonar where the cobertura codecoverage reports are and what version of java to use.
projectProperties([ 'sonar.java.source': '1.6', 'sonar.dynamicAnalysis': 'reuseReports', 'sonar.cobertura.reportPath': 'build/reports/cobertura/coverage.xml' ])
}


The important bit was this: 'sonar.java.source': '1.6'. Hope this helps someone =).

No comments:

Post a Comment