Creating common task for all subprojects

(sreenivas karthikeyan) #1


How to create a common task in root build.gradle which can be executed for all modules.



task findbugs(type: FindBugs) {
ignoreFailures = true
effort = “max"
reportLevel = “low"
excludeFilter = new File(”${rootDir}/…/Tools/findBugs/exclude.xml”)
classes = files("${project.buildDir}/intermediates/classes/debug")
source 'src’
include “/*.java"
exclude "
reports {
xml.enabled = true
xml.withMessages = true
html.enabled = false
xml {
destination “$project.buildDir/reports/${}.xml”
classpath = files()

task findbugsHtml << {
if (file("${buildDir}/reports/${}.xml").exists()) {
ant.xslt(in: “${buildDir}/reports/${}.xml”,

To run it for App module

gradle clean :App:findbugs

Multiproject checkstyles not working
(Przemek Wesołek) #2

Just wrap your definitions in allprojects (or subprojects), they will be executed in the context of every project then.

subprojects {
    task sayHello {
        doLast { println "Hello from ${}" }

// make "delegation to all" task on root project
task sayAllHello
subprojects { pr -> sayAllHello.dependsOn("${pr.path}:sayHello") }

(sreenivas karthikeyan) #3


I have already kept the definition in subproject{}
but, I’m getting below error while running gradle clean

A problem occurred configuring project ‘:App’.

Failed to notify project evaluation listener.
Could not find method findbugs() for arguments [{type=class org.gradle.api.plugins.quality.FindBugs}, build_d7dwedg7sz2ompeyuks09tmxx$_run_closure1_closure5_closure14_closure17@113ebb2f] on project ‘:App’.

(sreenivas karthikeyan) #4

Oh, It was a silly mistake
Works well now.
Thanks a lot