Distribution Plugin customize base contents to create multiple distributions

Hi,

I am using the Distribution Plugin, and I’d like to now create two distributions where they are both largely the same with exception of some platform-dependent external software. Instead of copying and pasting the same contents {} twice, is there an elegant way to avoid repeating myself?

For example, I only need to change the contents of one directory in the distribution, everything else is boilerplate stuff:

distributions {
  windows {
    contents {
      // boilerplate docs, software, licenses, etc.
      into('ext') { /* Windows-related external software */ }
    }
  linux {
    contents {
      // boilerplate docs, software, licenses, etc.
      into('ext') { /* Linux-related external software */ }
    }
  }
}

The contents closure delegates to a CopySpec. CopySpec has a with method that allows you to include another CopySpec. project.copySpec allows you to create a CopySpec.

def commonSpec = project.copySpec {
    into( 'commonStuff' ) {
        from 'src/common'
    }
}
distributions {
    windows {
        contents {
            with commonSpec
            into( 'ext' ) { ... }
        }
    }
    linux {
        contents {
            with commonSpec
            into( 'ext' ) { ... }
        }
    }
}
1 Like

Thanks @Chris_Dore! I completely overlooked CopySpec's with method.