Gradle Multiproject - OpenClover

时间:2017-11-11 15:46:25

标签: java gradle build.gradle gradle-plugin clover

我正在尝试将Open Clover集成到我的Gradle构建过程中,并遵循以下指南:

当我将其添加到build.gradle时 - 我收到以下错误:

* * 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..

我的build.gradle文件如下:

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)
    }
}

util.gradle的内容如下

ext.scriptFile = {
    String fileName ->
        return new File(new File(rootDir, 'gradle'), fileName)
}

有人可以提供任何帮助来解决这个问题吗?

1 个答案:

答案 0 :(得分:3)

使用以下脚本将clover集成到项目中:

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}"
        }
    }
}

如果可以使用即用型插件,则无需手动集成。