sanjeevjha sanjeevjha - 19 days ago 10
Groovy Question

How to integrate GMetrics tool with grails 3x application

Actually i need to integrate GMetrics static code analysis tool with grails 3x application but i'm not able to do it.

Please help me out if somebody already did it.

Answer

You need the following snippets in your build.gradle file

configurations {
    gmetrics
}
dependencies {
    ...
    gmetrics 'org.gmetrics:GMetrics:0.7'
}
task gmetrics {
    doLast {
        //use GMetrics ant task - http://gmetrics.sourceforge.net/gmetrics-ant-task.html
        ant.taskdef(name: 'gmetrics', classname: 'org.gmetrics.ant.GMetricsTask', classpath: configurations.gmetrics.asPath)
        //ensure reporting directory created
        ant.mkdir(dir: "${project.reporting.baseDir.path}/gmetrics")
        ant.gmetrics() {
            report(type: 'org.gmetrics.report.BasicHtmlReportWriter') {
                option(name: 'outputFile', value: "${project.reporting.baseDir.path}/gmetrics/gmetrics.html")
            }
            report(type: 'org.gmetrics.report.XmlReportWriter') {
                option(name: 'outputFile', value: "${project.reporting.baseDir.path}/gmetrics/gmetrics.xml")
            }
            fileset(dir: 'src') {
                include(name: '**/*.groovy')
                //exclusions to filter out any classes with inner classes - sonar doesn't support
                exclude(name: '**/*Config*')
            }
            fileset(dir: 'grails-app') {
                include(name: '**/*.groovy')
                //exclusions to filter out any classes with inner classes - sonar doesn't support
                exclude(name: '**/*Config*')
            }
        }
    }
}

Then you can invoke the gmetrics task, and find the report in build/reports/gmetrics/