Share abstract base task between multiple projects

Hi -

I have the following projects

  • Child1
  • Child2

In each child I have build.gradle with
(1) an abstract base task class
(2) and the actual task implementing the abstract methods.

I want to move the abstract base class to the parent project and share among all children projects, instead of duplicating.

What’s the best way to do it?

Do I write my own plugin as described in (

Are there other alternatives?



abstract class MyBuild extends DefaultTask {
    Boolean forceBuild = null

   abstract DirectoryProperty getSrcInputDir()

   @Option( option = 'force', description = 'Build even if not stale in cache. Will force build only this repo')
        void setForceBuild(final Boolean ignoreVal) {
        forceBuild = true

   Map<String,String> getInputProperties() {
      def inputMap = [:]
      if(forceBuild==true) {
          inputMap['timestamp'] =
      return inputMap

   void build {
task mybuild(type: MyBuild) {
   description 'my description'
   srcInputDir = file('pathname to the src dir')
   outputDir = file('./output')

You can put common build utilities in the buildSrc project (ie buildSrc/src/main/groovy/...)