Gradle and Sonar plugin - Execution failed for task 'sonarAnalyze' - java.lang.ClassCastException: java.util.ArrayList cannot be cast to java.lang.String

I have exception executing Sonar plugin:

My stack trace: * Exception is: org.gradle.api.tasks.TaskExecutionException: Execution failed for task ‘:sonarAnalyze’.

at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(

at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(

at org.gradle.api.internal.tasks.execution.PostExecutionAnalysisTaskExecuter.execute(

at org.gradle.api.internal.changedetection.CacheLockHandlingTaskExecuter$

at org.gradle.cache.internal.DefaultCacheAccess$2.create(

at org.gradle.cache.internal.DefaultCacheAccess.longRunningOperation(

at org.gradle.cache.internal.DefaultCacheAccess.longRunningOperation(

at org.gradle.cache.internal.DefaultPersistentDirectoryStore.longRunningOperation(

at org.gradle.api.internal.changedetection.DefaultTaskArtifactStateCacheAccess.longRunningOperation(

at org.gradle.api.internal.changedetection.CacheLockHandlingTaskExecuter.execute(

at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(

at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(

at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(

at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(

at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(

at org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter.execute(

at org.gradle.api.internal.AbstractTask.executeWithoutThrowingTaskFailure(

at org.gradle.execution.DefaultTaskGraphExecuter.executeTask(

at org.gradle.execution.DefaultTaskGraphExecuter.doExecute(

at org.gradle.execution.DefaultTaskGraphExecuter.execute(

at org.gradle.execution.SelectedTaskExecutionAction.execute(

at org.gradle.execution.DefaultBuildExecuter.execute(

at org.gradle.execution.DefaultBuildExecuter.access$200(

at org.gradle.execution.DefaultBuildExecuter$2.proceed(

at org.gradle.api.internal.changedetection.TaskCacheLockHandlingBuildExecuter$

at org.gradle.cache.internal.DefaultCacheAccess$1.create(

at org.gradle.cache.internal.DefaultCacheAccess.useCache(

at org.gradle.cache.internal.DefaultCacheAccess.useCache(

at org.gradle.cache.internal.DefaultPersistentDirectoryStore.useCache(

at org.gradle.api.internal.changedetection.DefaultTaskArtifactStateCacheAccess.useCache(

at org.gradle.api.internal.changedetection.TaskCacheLockHandlingBuildExecuter.execute(

at org.gradle.execution.DefaultBuildExecuter.execute(

at org.gradle.execution.DefaultBuildExecuter.access$200(

at org.gradle.execution.DefaultBuildExecuter$2.proceed(

at org.gradle.execution.DryRunBuildExecutionAction.execute(

at org.gradle.execution.DefaultBuildExecuter.execute(

at org.gradle.execution.DefaultBuildExecuter.execute(

at org.gradle.initialization.DefaultGradleLauncher.doBuildStages(

at org.gradle.initialization.DefaultGradleLauncher.doBuild(


at org.gradle.launcher.cli.RunBuildAction.execute(

at org.gradle.launcher.cli.RunBuildAction.execute(

at org.gradle.launcher.cli.CommandLineActionFactory$ParseAndBuildAction.execute(

at org.gradle.launcher.cli.CommandLineActionFactory$ParseAndBuildAction.execute(

at org.gradle.launcher.cli.CommandLineActionFactory$WithLogging.execute(

at org.gradle.launcher.cli.CommandLineActionFactory$WithLogging.execute(

at org.gradle.launcher.exec.ExceptionReportingAction.execute(

at org.gradle.launcher.exec.ExceptionReportingAction.execute(

at org.gradle.launcher.Main.doAction(


at org.gradle.launcher.Main.main(

at org.gradle.launcher.ProcessBootstrap.runNoExit(


at org.gradle.launcher.GradleMain.main( Caused by: java.lang.ClassCastException: java.util.ArrayList cannot be cast to java.lang.String

at org.sonar.plugins.surefire.api.SurefireUtils.getReportsDirectoryFromProperty(

at org.sonar.plugins.surefire.api.SurefireUtils.getReportsDirectory(

at org.sonar.plugins.surefire.SurefireSensor.analyse(

at org.sonar.batch.phases.SensorsExecutor.execute(

at org.sonar.batch.phases.Phases.execute(

at org.sonar.batch.bootstrap.ProjectModule.doStart(

at org.sonar.batch.bootstrap.Module.start(

at org.sonar.batch.bootstrap.BatchModule.analyze(

at org.sonar.batch.bootstrap.BatchModule.doStart(

at org.sonar.batch.bootstrap.Module.start(

at org.sonar.batch.bootstrap.BootstrapModule.doStart(

at org.sonar.batch.bootstrap.Module.start(

at org.sonar.batch.Batch.execute(

at org.sonar.batch.Batch$ Source)

at org.gradle.api.plugins.sonar.internal.SonarCodeAnalyzer.execute(SonarCodeAnalyzer.groovy:51)

at org.gradle.api.plugins.sonar.internal.SonarCodeAnalyzer$ Source)

at org.gradle.api.plugins.sonar.SonarAnalyze.analyze(SonarAnalyze.groovy:48)

at org.gradle.api.internal.BeanDynamicObject$MetaClassAdapter.invokeMethod(

at org.gradle.api.internal.BeanDynamicObject.invokeMethod(

at org.gradle.api.internal.CompositeDynamicObject.invokeMethod(

at org.gradle.api.plugins.sonar.SonarAnalyze_Decorated.invokeMethod(Unknown Source)

at org.gradle.util.ReflectionUtil.invoke(ReflectionUtil.groovy:23)

at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$4.execute(

at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$4.execute(

at org.gradle.api.internal.AbstractTask$TaskActionWrapper.execute(

at org.gradle.api.internal.AbstractTask$TaskActionWrapper.execute(

at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(

… 53 more

My config: sonar {

server {

url = “


database {






project {


language = “java”



Any idea?

Which Gradle version? Please use HTML code tags for any output and code snippets you post. Otherwise they are very hard to read.

Are you somehow setting the Sonar project property ‘sonar.surefire.reportsPath’ from within the build script? The problem is that this property is set to an ArrayList instead of a String, but I don’t think the Sonar plugin itself would ever do that.

Hi Peter, My version of Gradle is 1.0

$ gradle -version

------------------------------------------------------------ Gradle 1.0 ------------------------------------------------------------

Gradle build time: Tuesday, June 12, 2012 12:56:21 AM UTC Groovy: 1.8.6 Ant: Apache Ant™ version 1.8.2 compiled on December 20 2010 Ivy: 2.2.0 JVM: 1.7.0_04 (Oracle Corporation 23.0-b21) OS: Windows 7 6.1 amd64

No. I do not setting any surefire property.

Here is my simple build script:

apply plugin: 'maven'
apply plugin: 'groovy'
apply plugin: 'war'
apply plugin: 'sonar'
   group = 'com.test'
 version = '1.0.0.CI-SNAPSHOT'
    buildscript {
  apply from: ''
  // sonar settings -
 - check new sonar plugin for milestone 5 release
  sonar {
   server {
     url = ""
   database {
   project {
    language = "java"
  configurations.compile.transitive = true
   sourceCompatibility = 1.6
 targetCompatibility = 1.6
  repositories {
   mavenRepo urls: [""]
  compileJava.enabled = false
sourceSets {
 main {
      groovy {
   srcDir 'src/main/java'
 test {
  groovy {
   srcDir 'src/test/java'
       dependencies {
 groovy group: 'org.codehaus.groovy', name: 'groovy', version: '1.8.6'
    compile "org.springframework:spring-webmvc:3.1.1.RELEASE"
 compile "org.springframework:spring-context:3.1.1.RELEASE"
 compile "log4j:log4j:1.2.14"
 compile "org.springframework:spring-aop:3.1.1.RELEASE"
 compile ""
 compile ""
 compile "org.codehaus.groovy:groovy:1.8.6"
 compile "cglib:cglib-nodep:2.2"
 compile "joda-time:joda-time:2.0"
 compile "javax.servlet:jstl:1.2"
 testCompile "junit:junit:4.7"
 testCompile "org.springframework:spring-test:3.1.1.RELEASE"
 testCompile "org.spockframework:spock-core:0.6-groovy-1.8"
 testCompile "org.objenesis:objenesis:1.2"
 testCompile "org.hamcrest:hamcrest-core:1.2"
 testCompile "org.spockframework:spock-spring:0.6-groovy-1.8"
    compile "javax.servlet:servlet-api:2.5"
 compile "javax.servlet.jsp:jsp-api:2.1"
 compile "org.aspectj:aspectjrt:1.6.12"
 compile "org.aspectj:aspectjweaver:1.6.12"
         task replacePoms(dependsOn: install) << {
    def pomsDir = new File(project.buildDir, "poms")
    def defaultPomName = "pom-default.xml"
    def defaultPom = new File(pomsDir, defaultPomName)
    if (defaultPom.exists()) {
      File pomFile = new File(project.projectDir, "pom.xml")
      if (pomFile.exists()) {
        pomFile.renameTo(new File(project.projectDir, "pom.xml.bak"))
      project.copy {
        from(pomsDir) {
          include defaultPomName
          rename defaultPomName, 'pom.xml'

What does this print?

sonar.project.withProjectProperties { props ->
    println props["sonar.surefire.reportsPath"]
    println props["sonar.surefire.reportsPath"]?.getClass()

Also, which version of the Sonar server are you using?

Sonar version is v.3.0.1.

I don’t see anything that may print this line. Where do you see this printout? Could be version of sonar plugin?

I’m asking you to add above code to your build script and tell me what it prints when you run the ‘sonarAnalyze’ task.

C:\Documents and Settings\edvorkin\Documents\workspace-sts-2.9.1.RELEASE\PlatformV2\build\test-results
class java.lang.String
  FAILURE: Build failed with an exception.
  * What went wrong:
Execution failed for task ':sonarAnalyze'.
> java.util.ArrayList cannot be cast to java.lang.String
  * Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

My project contain both java and groovy code. Is it possible that I am experience the problem because of that?

Looks like everything is fine on Gradle’s side. Do you have a pom.xml in the project directory? Maybe Sonar accidentally picks that up.

The only other idea I have is that Sonar made an incompatible change on their side, although I don’t really believe that’s the cause of this error. Still, I only tested the Sonar plugin with Sonar versions 2.9 through 2.12 or 2.13.

Maybe. Groovy analysis with Sonar is known not to work due to Gradle and Sonar using different Groovy versions. Can you deactivate any Sonar plugins you have configured on the server side and try again?

Unless you set the language to be analyzed to Groovy (in the Gradle build script), the presence of Groovy code shouldn’t matter though.

Peter, thank you for looking into the issue on Saturday. I did not setup anything specific to the Groovy in the script. you see the script above.

Sonar plugin on the server side? All I have is a Sonar server running with mySQL on amazon cloud and gradle build script I am running on my local windows machine so far.

I am thinking about 1. Getting the latest version of Sonar server and 2. getting source code and execute build from the debugger if possible to see the reason of exception.

Sonar plugin on the server side?

AFAIK, you can configure Sonar plugins in the UI, which will then get executed on the client side during analysis. Have you ruled out that an existing pom.xml is causing the problem?

No. I did not configure any sonar plugins. I removed pom.xml but that did not help

I have resolved the problem. I have cleaned up my project, removing all eclipse related folders, all maven related folders and all other files except source and build.gradle. I have cleaned up build.gradle file removing code coverage plugin as well. Then I have imported the project as a new gradle project into Eclipse using STS Eclipse. this way I got working eclipse project. Then in cygwin session I managed to run gradle tasks as well as sonarAnalyze task.

I think the problem was due to this project was original Maven project and, as you said, plugin was

probably getting wrong values.

I also upgraded to the latest version of Sonar server, so I can confirm that gradle works with sonar 3.1.1

Thanks for all your help.