clover 4 with gradle

I am using the build.gradle provided by you . The issue I am facing is that the source files are not being picked up. The clover directory is not getting created and hence the report is not getting generated.  The command I am using is ./gradlew clean test cloverInstr cloverReport. 

Could you please help me . My project structure is:

Root Project
     A (child)
     B (child)
     C (child)
apply plugin: 'java'
apply plugin: 'maven'


repositories {
  jcenter()
  maven {
    url "Our internal repo"
  }
}

dependencies {
  testCompile 'junit:junit:4.12'
}

buildscript {
  repositories {
    jcenter()
    // mavenCentral()
    //mavenLocal()
    maven {
      url "our internal repo"
    }
  }
  dependencies {
    classpath 'com.atlassian.clover:clover:4.1.1'
  }
}

sourceSets {
  clover {
    java {
      srcDir "$buildDir/sources-instr"
    }
  }
}


dependencies {
  cloverCompile 'com.atlassian.clover:clover:4.1.1'
}

configurations {
  cloverRuntime
  cloverRuntime.extendsFrom cloverCompile
}

task cloverInstr() {
  inputs.files sourceSets.main.allJava
  println "The source set is"
  println "${sourceSets.main}"
  outputs.dir "$buildDir/sources-instr"
  doFirst {
    def argsList = ["--initstring", "${buildDir}/clover/clover.db",
"-d", "${buildDir}/sources-instr"]
    argsList.addAll(inputs.files.files.collect({ file ->
      file.absolutePath
      println "In doFirts"
    }))
    String[] args = argsList.toArray()
    println "the args list is"
    println "${args}"
    com.atlassian.clover.CloverInstr.mainImpl(args)
  }
}

cloverClasses.dependsOn cloverInstr


test {
  def cloverClasspath = configurations.testRuntime + configurations.cloverRuntime + sourceSets.test.output + sourceSets.clover.output
  classpath = cloverClasspath
}

allprojects {
  task cloverReport {
    inputs.dir "${buildDir}/clover"
    outputs.dir "${reportsDir}/clover"
    onlyIf {
      file("${buildDir}/clover/clover.db").exists()
    }
    doFirst {
      def argsList = ["--initstring", "${buildDir}/clover/clover.db",
"-o", "${reportsDir}/clover"]
      String[] args = argsList.toArray()
      com.atlassian.clover.reporters.html.HtmlReporter.runReport(args)
    }
  }
}

1 answer

1 accepted

This widget could not be displayed.

Hi, you should do the source instrumentation before testing it. I think the implicit dependencies between outputs of cloverInstr and inputs of test should handle it, but potentially they don't

I would try running 

./gradlew clean cloverInstr test cloverReport

 

Hi Grzegorz 

Thanks for your response. I ve been trying with 

./gradlew clean cloverInstr test cloverReport 

The clover.db is created and the instrumentation is done. 

The issue that Im facing now is compilation fails for the files at source-instr files. The failure is due to the packages missing , like the import statements are not fetching the packages in the source-instr folder. 

test {

def cloverClasspath = configurations.testRuntime + configurations.cloverRuntime + sourceSets.test.output + sourceSets.clover.output
classpath = cloverClasspath

}

 

Is there a way to to add the source-instr to the classpath 

 

I guess none of the main sources dependencies are picked up when you try to compile Clover sources set.  So when Gradle compiles cloverSourceSet, it takes cloverCompile configuration.

And as far I can see, you don't configure any dependencies on that configuration. I think you're missing the following code snippet:

configurations {

cloverCompile.extendsFrom compile

}

 

Thankyou!! ...that worked smile

Suggest an answer

Log in or Sign up to answer
Atlassian Summit 2018

Meet the community IRL

Atlassian Summit is an excellent opportunity for in-person support, training, and networking.

Learn more
Community showcase
Published 55m ago in Bitbucket

Branch Management with Bitbucket

As a project manager, I have discovered that different developers want to bring their previous branching method with them when they join the team. Some developers are used to performing individual wo...

15 views 0 3
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you