I am trying to integrate Open Clover into my Gradle build process and was following the following guide:
When I added it to my build.gradle
- I got the following error:
* * What went wrong:
A problem occurred evaluating root project 'Enjin-Coin-Java-SDK'.
> Could not find method cloverCompile() for arguments [org.openclover:clover:4.2.0] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler..
My build.gradle file is as follows:
buildscript {
repositories {
mavenCentral()
maven { url 'https://plugins.gradle.org/m2/' }
}
dependencies {
classpath 'org.openclover:clover:4.2.0'
}
}
plugins {
id 'com.github.johnrengelman.shadow' version '1.2.4'
id 'java'
}
sourceSets {
clover {
java {
srcDir "$buildDir/sources-instr"
}
}
}
apply from: 'gradle/util.gradle'
subprojects {
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'java'
apply plugin: 'maven'
apply plugin: 'com.github.johnrengelman.shadow'
group = 'com.myproject'
version = '0.0.1-SNAPSHOT'
idea {
module {
scopes.PROVIDED.plus += [configurations.shadow]
}
}
tasks.build.dependsOn(shadowJar)
artifacts.archives shadowJar
tasks.withType(AbstractCompile) {
classpath += configurations.shadow
}
ext {
mockito = '2.9.0'
junit = '4.12'
powermock = '1.7.3'
}
repositories {
mavenLocal()
mavenCentral()
}
dependencies {
// testCompile dependencies
testCompile group: 'org.mockito', name: 'mockito-core', version: mockito
testCompile group: 'junit', name: 'junit', version: junit
testCompile group: 'org.powermock', name: 'powermock-api-mockito2', version: powermock
testCompile group: 'org.powermock', name: 'powermock-module-junit4', version: powermock
cloverCompile 'org.openclover:clover:4.2.0'
}
jar {
archiveName = "${project.name}-slim.jar"
}
shadowJar {
archiveName = "${project.name}.jar"
}
install {
repositories.mavenInstaller {
pom.artifactId = "sdk-${project.name}"
}
}
}
configurations {
cloverRuntime
cloverRuntime.extendsFrom cloverCompile
}
task cloverInstr() {
inputs.files sourceSets.main.allJava
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
}))
String[] args = argsList.toArray()
com.atlassian.clover.CloverInstr.mainImpl(args)
}
}
cloverClasses.dependsOn cloverInstr
test {
def cloverClasspath = configurations.testRuntime + configurations.cloverRuntime + sourceSets.test.output + sourceSets.clover.output
classpath = cloverClasspath
}
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)
}
}
The contents of util.gradle are as follows
ext.scriptFile = {
String fileName ->
return new File(new File(rootDir, 'gradle'), fileName)
}
Can anyone offer any assistance in how to resolve this?
Use the following script to integrate clover into your project:
buildscript {
repositories {
mavenCentral()
maven { url 'https://plugins.gradle.org/m2/' }
jcenter()
}
}
plugins {
id 'com.github.johnrengelman.shadow' version '1.2.4'
id "com.bmuschko.clover" version "2.1.3"
}
apply from: 'gradle/util.gradle'
subprojects {
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'java'
apply plugin: 'maven'
apply plugin: 'com.github.johnrengelman.shadow'
apply plugin: 'com.bmuschko.clover'
group = 'com.myproject'
version = '0.0.1-SNAPSHOT'
idea {
module {
scopes.PROVIDED.plus += [configurations.shadow]
}
}
tasks.build.dependsOn(shadowJar)
artifacts.archives shadowJar
tasks.withType(AbstractCompile) {
classpath += configurations.shadow
}
ext {
mockito = '2.9.0'
junit = '4.12'
powermock = '1.7.3'
}
repositories {
mavenLocal()
mavenCentral()
}
dependencies {
// testCompile dependencies
testCompile group: 'org.mockito', name: 'mockito-core', version: mockito
testCompile group: 'junit', name: 'junit', version: junit
testCompile group: 'org.powermock', name: 'powermock-api-mockito2', version: powermock
testCompile group: 'org.powermock', name: 'powermock-module-junit4', version: powermock
clover 'org.openclover:clover:4.2.0'
}
jar {
archiveName = "${project.name}-slim.jar"
}
shadowJar {
archiveName = "${project.name}.jar"
}
install {
repositories.mavenInstaller {
pom.artifactId = "sdk-${project.name}"
}
}
}
There's no need for manual integration if ready-to-use plugin is available.