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

1 vote

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 Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Fadoua M. Boualem
Published Monday in Trello

Using Trello to manage events

As a Jira power user, I was at first doubtful that Trello could benefit my workflow. Jira already uses boards (ones you can customize!), so why would I even need to use Trello?! In this post you will...

522 views 8 9
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