How do I change the unixStartScriptGenerator.template in the createStartScripts task so that the distTar uses my own template file in the build.gradle file?

I need to change the start of the script that gradle creates for a distTar task . I seem to be able to set unixStartScriptGenerator.template like below, but when I unpack the script from tar, there is no change.

This is my complete build.gradle

:

apply plugin: 'java'
apply plugin: 'war'

// to use the main method in Main, which uses Jetty
apply plugin: 'application'
mainClassName = 'com.example.Main'
project.version = '2017.0.0.0'

repositories {
  mavenLocal()
  mavenCentral()
}

task createStartScripts(type: CreateStartScripts) {
  // based on https://github.com/gradle/gradle/tree/v3.5.0/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins
  def tplName = 'unixStartScriptTemplate.txt'
  // this succeeds. I tried negating it to ensure that it runs, and it failed, so it running.
  assert project.file(tplName).exists();
  unixStartScriptGenerator.template = project.file(tplName).newReader() as TextResource
//  windowsStartScriptGenerator.template = resources.text.fromFile('customWindowsStartScript.txt')
}


dependencies {
 // mostly elided
  compile 'org.apache.logging.log4j:log4j-api:2.8.+'
  compile 'org.apache.logging.log4j:log4j-core:2.8.+'
  compile 'de.bwaldvogel:log4j-systemd-journal-appender:2.2.2'

  testCompile "junit:junit:4.12"
}

task wrapper(type: Wrapper) {
  gradleVersion = '3.5'
}

      

Not that it matters, but my unixStartScriptTemplate.txt template is basically the same as the original unixStartScript.txt , but with some additional comments and a line modifying the JAVACMD.

If there is a better way to install this template, please let me know.

+3


source to share


1 answer


This way you add a new task, while you'd better connect to an existing one, try:



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

      

+1


source







All Articles