Code coverage and code analysis plugin


(smurfs.doll) #1

Hi I am working on a multi module grails project and i have used gradle to build it. Can anyone please let me know a code coverage plugin and code analysis plugin that can be used in gradle.? I tried using https://github.com/valkolovos/gradle_cobertura/raw/master/repo/gradle_cobertura/gradle_cobertura/1.2/coberturainit.gradle’ but, it does not recognize the groovy files even though i mention the sourcesets

Thanks Smurf


(Andrew Oberstar) #2

As of Gradle 1.6, there’s a new Jacoco plugin.


(smurfs.doll) #3

Thanks. can it be used for groovy file as well? Because it has been mentioned that it is a code coverage library for java.


(smurfs.doll) #4

Thanks. can it be used for groovy file as well? Because it has been mentioned that it is a code coverage library for java.


(Andrew Oberstar) #5

It “works” for all languages that generate JVM bytecode. I do notice less accurate (i.e. lower) coverage percentages with Groovy code.

I think it’s a known issue for languages like Groovy and Scala that the normal Java code coverage libraries don’t work to the same level.


(smurfs.doll) #6

ok. I tried the Jacoco plugin in my grails project, but it skips the jacocotestreport. Can you please let me know, if i need to configure the sourceset for groovy and if so, can you please tell me how to configure it?

build.gradle

buildscript{
 repositories{
  mavenCentral()
  mavenRepo url: "http://repo.grails.org/grails/repo"
  }
 dependencies{
  classpath "org.grails:grails-gradle-plugin:2.0.0-SNAPSHOT"//,
  // classpath "org.ajoberstar:gradle-jacoco:0.2.0"
      }
 }
apply plugin: 'grails'
apply plugin: "application"
apply plugin: "jacoco"
jacoco {
    toolVersion = "0.6.2.201302030002"
    reportsDir = new File(buildDir, "customJacocoReportDir")
}
  version = '2.2-SNAPSHOT'
  grails{
grailsVersion "2.2.2"
}

Output ----------

C:\Study\Grails3.3.2_codenarc\tt>gradle jacocoTestReport
:compileJava UP-TO-DATE
:processResources UP-TO-DATE
:classes UP-TO-DATE
:jacocoTestReport SKIPPED
  BUILD SUCCESSFUL

Thanks Smurf


(Andrew Oberstar) #7

‘jacocoTestReport’ uses the new ‘mustRunAfter’ features, which only control ordering, not dependencies. You need to run both the ‘test’ and ‘jacocoTestReport’ tasks to get what you are looking for.

A little more information on the reasoning here.


(smurfs.doll) #8

Thanks Andrew. I will try and let you know in case of issues. I have one more question. In maven multi module project, we have a packaging type as pom and we use that in the parent project which has the dependencies of all the child modules.

In gradle, can we do the same in a multi module grails plugin project? Because, the pom.xml got generated for all the child modules. But, i do not find a pom for the parent which has all the dependencies of the child. Can you please help me on that?

Regards Smurf


(Luke Daley) #9

This won’t work. You’ll need a Jacoco plugin for Grails, not Gradle.

The Grails plugin only does dependency management and invocation of Gradle applications. Grails is still the main build system, so you need a plugin that hooks in there.


(smurfs.doll) #10

I do not understand exactly. As per org.grails:grails-gradle-plugin:2.0.0-SNAPSHOT, i have removed all the dependency management section from BuildConfig.groovy and placed it in build.gradle so that gradle can handle the dependency management. Is that the correct approach?

Thanks Smurf


(Luke Daley) #11

Yes, but that’s all Gradle knows about the Grails project. It does not know where the source code is, or how to compile it, or how to run tests. Grails does all of that. Therefore, you need a Grails plugin for code coverage in order to analyse your project.


(smurfs.doll) #12

Is it a good idea to use http://wiki.gradle.org/display/GRADLE/Plugins#Plugins-CoberturaPlugin? Because, i can specify the sourceset here?

Also, I have one more question. In maven multi module project, we have a packaging type as pom and we use that in the parent project which has the dependencies of all the child modules.

In gradle, can we do the same in a multi module grails plugin project? Because, the pom.xml got generated for all the child modules. But, i do not find a pom for the parent which has all the dependencies of the child.

Can you please help me on that?


(Luke Daley) #13

In gradle, can we do the same in a multi module grails plugin project? Because, the pom.xml got generated for all the child modules. But, i do not find a pom for the parent which has all the dependencies of the child.

Please open another question.


(smurfs.doll) #14

Done http://forums.gradle.org/gradle/topics/generate_packaging_as_pom_type_is_not_generated_for_the_parent_project?rfm=1