2

Has anyone had any success in integrating the gradle-clover-plugin with Grails 3? The closest I've got with build.gradle is:

clover {
    additionalSourceDirs = [new File("src/main/groovy"), new File("grails-app")] as Set
    additionalTestDirs = [new File("src/test/groovy/"), new File("src/integration-test/groovy")] as Set
    includes = ['/*.groovy', '/.java']
    testIncludes = ['/Spec.java']
    report {
        html = true
        xml = true
    }
}

grails test-app:

[clover-clean] Clover Version 3.2.0, built on October 21 2013 (build-908)
[clover-clean] Loaded from: C:\Users\abc3\.gradle\caches\modules-2\files-2.1\com.cenqua.clover\clover\3.2.0\e09feecf14644d92003ab037c30e483cf86b3e82\clover-3.2.0.jar
[clover-clean] Clover: Commercial License registered to Abc Inc.
[clover-setup] Clover Version 3.2.0, built on October 21 2013 (build-908)
[clover-setup] Loaded from: C:\Users\abc3\.gradle\caches\modules-2\files-2.1\com.cenqua.clover\clover\3.2.0\e09feecf14644d92003ab037c30e483cf86b3e82\clover-3.2.0.jar
[clover-setup] Clover: Commercial License registered to Abc Inc.
[clover-setup] Clover is enabled with initstring 'C:\Users\abc3\MyApp\build/.clover/clover.db-test'
[javac] : warning: 'includeantruntime' was not set, defaulting to build.sysclasspath=last; set to false for repeatable builds
[javac] : warning: 'includeantruntime' was not set, defaulting to build.sysclasspath=last; set to false for repeatable builds
[copy] Copied 2 empty directories to 2 empty directories under C:\Users\abc3\MyApp\build\classes\main
[copy] Copied 2 empty directories to 2 empty directories under C:\Users\abc3\MyApp\build\classes\test
[move] Moving 14 files to C:\Users\abc3\MyApp\build\classes
[move] Moved 3 empty directories to 1 empty directory under C:\Users\abc3\MyApp\build\classes
[move] Moving 4 files to C:\Users\abc3\MyApp\build\classes
[move] Moved 3 empty directories to 1 empty directory under C:\Users\abc3\MyApp\build\classes
:compileIntegrationTestJava UP-TO-DATE
:compileIntegrationTestGroovy UP-TO-DATE
:processIntegrationTestResources UP-TO-DATE
:integrationTestClasses UP-TO-DATE
:integrationTest UP-TO-DATE
:mergeTestReports UP-TO-DATE

Clover appears to run but I do not get any reporting.

Nothing is created in C:\Users\abc3\MyApp\build/.clover; I do not have a .clover directory.

  • Grails Version: 3.1.10
  • Groovy Version: 2.4.7
  • JVM Version: 1.8.0_71

Any ideas?

Thanks

Mark

Mark Thomas
  • 141
  • 1
  • 6

3 Answers3

3

I've used the Gradle-Clover-Plugin for a Grails 3.2.4 application (which was using Gradle 3.0 wrapper). It is working, and all I did in the build.gradle file was:

First adding the classpath dependency:

buildscript {
    dependencies {
        classpath 'com.bmuschko:gradle-clover-plugin:2.1.0'
    }
}

Then applying the plugin:

apply plugin: 'com.bmuschko.clover'

Then adding the clover dependency:

dependencies {
    clover 'org.openclover:clover:4.2.0'
}

Then adding some configuration:

clover {
    // Although Clover is now open source the plugin 
    // still expects to find the license file. 
    // Any file will work.
    licenseLocation = File.createTempFile('clover', '.license').absolutePath

    // This is neededed to see which tests targeted code
    // In this particular project I'm only using Spock
    // specifications
    testIncludes = ['**/*Spec.groovy']

    // I would like to have both html and xml report
    report {
      html = true
      xml = true
    }
}

And finally execute:

./gradlew cloverGenerateReport
dlinsin
  • 19,249
  • 13
  • 42
  • 53
Mario
  • 101
  • 4
  • The command did not work for me, looks like the tasks have changed in the latest plugin (2.2.1) to cloverGenerateReport and cloverAggregateReports https://github.com/bmuschko/gradle-clover-plugin#tasks – mbonness May 17 '18 at 16:38
2

I could make it work with grails 3.3.2 and gradle 4.4, but It was a tedious task. This is what I did:

  1. gradle.properties

    grailsVersion=3.3.2 gormVersion=6.1.8.RELEASE gradleWrapperVersion=4.4 org.gradle.jvmargs=-Xms256m -Xmx2048m

  2. build.gradle

    apply plugin: 'java'
    apply plugin: 'com.bmuschko.clover'
    
    dependencies {
        clover 'org.openclover:clover:4.2.0'
        ...
        compile 'org.codehaus.groovy:groovy-all:2.4.7'
        ...
    }
    
    sourceSets.main.output.classesDir = new File(buildDir, "classes/main")
    integrationTest.testClassesDirs = sourceSets.integrationTest.output.classesDirs
    
    clover {
        licenseLocation = File.createTempFile('clover', '.license').absolutePath             
    
        excludes = ['**/Application.groovy',     
                    '**/BootStrap.groovy',
                    '**/UrlMappings.groovy',
                    '**/*GrailsPlugin.groovy',
                    '**/*Mock.groovy',
        ]
    
        testIncludes = ['**/*Spec.groovy']
        report {
            html = true
            xml = true
        }
    }   
    

I hope it will help you.

GSAN
  • 648
  • 6
  • 29
0

The grails-clover-plugin works with Grails 1 and 2, which are based on Gant. The Grails 3 is based on Gradle, so the plugin is incompatible.

For Grails 3 I'd try to write a Clover-Gradle integration in the Gradle build script rather than trying to adopt the grails-clover-plugin.

Please have a look at the code snippet recently published on this page:

https://confluence.atlassian.com/display/CLOVER/Gradle+Clover+Plugin

Marek
  • 748
  • 6
  • 13