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


(Eugene Dvorkin) #1

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(ExecuteActionsTaskExecuter.java:68)

at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:46)

at org.gradle.api.internal.tasks.execution.PostExecutionAnalysisTaskExecuter.execute(PostExecutionAnalysisTaskExecuter.java:34)

at org.gradle.api.internal.changedetection.CacheLockHandlingTaskExecuter$1.run(CacheLockHandlingTaskExecuter.java:34)

at org.gradle.cache.internal.DefaultCacheAccess$2.create(DefaultCacheAccess.java:200)

at org.gradle.cache.internal.DefaultCacheAccess.longRunningOperation(DefaultCacheAccess.java:172)

at org.gradle.cache.internal.DefaultCacheAccess.longRunningOperation(DefaultCacheAccess.java:198)

at org.gradle.cache.internal.DefaultPersistentDirectoryStore.longRunningOperation(DefaultPersistentDirectoryStore.java:111)

at org.gradle.api.internal.changedetection.DefaultTaskArtifactStateCacheAccess.longRunningOperation(DefaultTaskArtifactStateCacheAccess.java:83)

at org.gradle.api.internal.changedetection.CacheLockHandlingTaskExecuter.execute(CacheLockHandlingTaskExecuter.java:32)

at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.java:55)

at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:57)

at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:41)

at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:51)

at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:52)

at org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter.execute(ExecuteAtMostOnceTaskExecuter.java:42)

at org.gradle.api.internal.AbstractTask.executeWithoutThrowingTaskFailure(AbstractTask.java:247)

at org.gradle.execution.DefaultTaskGraphExecuter.executeTask(DefaultTaskGraphExecuter.java:192)

at org.gradle.execution.DefaultTaskGraphExecuter.doExecute(DefaultTaskGraphExecuter.java:177)

at org.gradle.execution.DefaultTaskGraphExecuter.execute(DefaultTaskGraphExecuter.java:83)

at org.gradle.execution.SelectedTaskExecutionAction.execute(SelectedTaskExecutionAction.java:36)

at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:61)

at org.gradle.execution.DefaultBuildExecuter.access$200(DefaultBuildExecuter.java:23)

at org.gradle.execution.DefaultBuildExecuter$2.proceed(DefaultBuildExecuter.java:67)

at org.gradle.api.internal.changedetection.TaskCacheLockHandlingBuildExecuter$1.run(TaskCacheLockHandlingBuildExecuter.java:31)

at org.gradle.cache.internal.DefaultCacheAccess$1.create(DefaultCacheAccess.java:111)

at org.gradle.cache.internal.DefaultCacheAccess.useCache(DefaultCacheAccess.java:126)

at org.gradle.cache.internal.DefaultCacheAccess.useCache(DefaultCacheAccess.java:109)

at org.gradle.cache.internal.DefaultPersistentDirectoryStore.useCache(DefaultPersistentDirectoryStore.java:103)

at org.gradle.api.internal.changedetection.DefaultTaskArtifactStateCacheAccess.useCache(DefaultTaskArtifactStateCacheAccess.java:79)

at org.gradle.api.internal.changedetection.TaskCacheLockHandlingBuildExecuter.execute(TaskCacheLockHandlingBuildExecuter.java:29)

at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:61)

at org.gradle.execution.DefaultBuildExecuter.access$200(DefaultBuildExecuter.java:23)

at org.gradle.execution.DefaultBuildExecuter$2.proceed(DefaultBuildExecuter.java:67)

at org.gradle.execution.DryRunBuildExecutionAction.execute(DryRunBuildExecutionAction.java:32)

at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:61)

at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:54)

at org.gradle.initialization.DefaultGradleLauncher.doBuildStages(DefaultGradleLauncher.java:155)

at org.gradle.initialization.DefaultGradleLauncher.doBuild(DefaultGradleLauncher.java:110)

at org.gradle.initialization.DefaultGradleLauncher.run(DefaultGradleLauncher.java:78)

at org.gradle.launcher.cli.RunBuildAction.execute(RunBuildAction.java:42)

at org.gradle.launcher.cli.RunBuildAction.execute(RunBuildAction.java:28)

at org.gradle.launcher.cli.CommandLineActionFactory$ParseAndBuildAction.execute(CommandLineActionFactory.java:201)

at org.gradle.launcher.cli.CommandLineActionFactory$ParseAndBuildAction.execute(CommandLineActionFactory.java:174)

at org.gradle.launcher.cli.CommandLineActionFactory$WithLogging.execute(CommandLineActionFactory.java:170)

at org.gradle.launcher.cli.CommandLineActionFactory$WithLogging.execute(CommandLineActionFactory.java:139)

at org.gradle.launcher.exec.ExceptionReportingAction.execute(ExceptionReportingAction.java:31)

at org.gradle.launcher.exec.ExceptionReportingAction.execute(ExceptionReportingAction.java:20)

at org.gradle.launcher.Main.doAction(Main.java:48)

at org.gradle.launcher.exec.EntryPoint.run(EntryPoint.java:45)

at org.gradle.launcher.Main.main(Main.java:39)

at org.gradle.launcher.ProcessBootstrap.runNoExit(ProcessBootstrap.java:50)

at org.gradle.launcher.ProcessBootstrap.run(ProcessBootstrap.java:32)

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

at org.sonar.plugins.surefire.api.SurefireUtils.getReportsDirectoryFromProperty(SurefireUtils.java:46)

at org.sonar.plugins.surefire.api.SurefireUtils.getReportsDirectory(SurefireUtils.java:35)

at org.sonar.plugins.surefire.SurefireSensor.analyse(SurefireSensor.java:52)

at org.sonar.batch.phases.SensorsExecutor.execute(SensorsExecutor.java:64)

at org.sonar.batch.phases.Phases.execute(Phases.java:93)

at org.sonar.batch.bootstrap.ProjectModule.doStart(ProjectModule.java:143)

at org.sonar.batch.bootstrap.Module.start(Module.java:83)

at org.sonar.batch.bootstrap.BatchModule.analyze(BatchModule.java:115)

at org.sonar.batch.bootstrap.BatchModule.doStart(BatchModule.java:105)

at org.sonar.batch.bootstrap.Module.start(Module.java:83)

at org.sonar.batch.bootstrap.BootstrapModule.doStart(BootstrapModule.java:109)

at org.sonar.batch.bootstrap.Module.start(Module.java:83)

at org.sonar.batch.Batch.execute(Batch.java:104)

at org.sonar.batch.Batch$execute.call(Unknown Source)

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

at org.gradle.api.plugins.sonar.internal.SonarCodeAnalyzer$execute.call(Unknown Source)

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

at org.gradle.api.internal.BeanDynamicObject$MetaClassAdapter.invokeMethod(BeanDynamicObject.java:196)

at org.gradle.api.internal.BeanDynamicObject.invokeMethod(BeanDynamicObject.java:102)

at org.gradle.api.internal.CompositeDynamicObject.invokeMethod(CompositeDynamicObject.java:99)

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(AnnotationProcessingTaskFactory.java:150)

at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$4.execute(AnnotationProcessingTaskFactory.java:145)

at org.gradle.api.internal.AbstractTask$TaskActionWrapper.execute(AbstractTask.java:477)

at org.gradle.api.internal.AbstractTask$TaskActionWrapper.execute(AbstractTask.java:466)

at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:60)

… 53 more

My config: sonar {

server {

url = “http://server.com:9000

}

database {

url=“jdbc:mysql://server:3306/sonar?useUnicode=true&characterEncoding=utf8”

driverClassName=“com.mysql.jdbc.Driver”

username=“sonar”

password=“sonar”

}

project {

coberturaReportPath=file("$buildDir/reports/cobertura/coverage.xml")

language = “java”

}

}

Any idea?


(Peter Niederwieser) #2

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


(Peter Niederwieser) #3

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.


(Eugene Dvorkin) #4

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


(Eugene Dvorkin) #5

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: 'https://github.com/valkolovos/gradle_cobertura/raw/master/repo/gradle_cobertura/gradle_cobertura/1.0/coberturainit.gradle'
 }
  // sonar settings -
 - check new sonar plugin for milestone 5 release
  sonar {
   server {
     url = "server.amazonaws.com:9000"
   }
   database {
       url="jdbc:mysql://server.amazonaws.com:3306/sonar?useUnicode=true&characterEncoding=utf8"
   driverClassName="com.mysql.jdbc.Driver"
   username="usr"
   password="pwd"
   }
   project {
    coberturaReportPath=file("$buildDir/reports/cobertura/coverage.xml")
    language = "java"
   }
       }
  configurations.compile.transitive = true
   sourceCompatibility = 1.6
 targetCompatibility = 1.6
  repositories {
   mavenRepo urls: ["http://repo.maven.apache.org/maven2"]
}
  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 "org.springframework.data:spring-data-mongodb:1.0.1.RELEASE"
 compile "org.springframework.data:spring-data-commons-core:1.2.0.RELEASE"
 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'
        }
        into(project.projectDir)
      }
    }
}

(Peter Niederwieser) #6

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?


(Eugene Dvorkin) #7

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?


(Peter Niederwieser) #8

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


(Eugene Dvorkin) #9
:sonarAnalyze
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.
  BUILD FAILED

(Eugene Dvorkin) #10

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


(Peter Niederwieser) #11

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.


(Peter Niederwieser) #12

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?


(Peter Niederwieser) #13

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


(Eugene Dvorkin) #14

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.


(Peter Niederwieser) #15

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?


(Eugene Dvorkin) #16

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


(Eugene Dvorkin) #17

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.