templatesgradlebuild-script

Getting gradle to generate different startup scripts based on distribution


I'm using gradle 7.2 with the java, application, and distribution plugins. In my gradle.build, is a section for statupScripts:

tasks.withType(CreateStartScripts) {
  def tplName = 'unixStartScriptTemplate.txt'
  assert project.file(tplName).exists()
  unixStartScriptGenerator.template = resources.text.fromFile(tplName)
}

The same template will be applied to all distributions.

distributions {
  distroA {
        ...
  }
  distroB {
        ...
  }
}

Can someone help with having gradle generate startup scripts based on the distributions. I would like to have a template for distroA and a slightly different template for distroB

Thanks

The desired output would be a .tar and .zip generated for each distribution, where the startup scripts for each distribution could be tailored / different for that distribution.


Solution

  • By default there is only the main distribution and the application plugin is the one that creates one CreateStartScripts task and configures the main distribution to package it.

    So if you have additional distributions that all are also getting the start scripts, you most probably configured that yourself. So just do not use the CreateStartScripts task that was created by the application plugin, but define own tasks of that type with the templates you want to have and package them into your distributions instead of the one added by the application plugin.