I need to modify the start script that gradle generates for the distTar task. I seem to be able to set unixStartScriptGenerator.template as shown below, but when I unpack the script from the tar my changes are not there.
This is my full 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's 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 should matter, but my template, unixStartScriptTemplate.txt, is mostly the same as the original unixStartScript.txt, but with some extra comments and a line changing JAVACMD.
If there is a better way to set this template, please let me know.
This way you add a new task whereas you should rather hook into existing one, try:
tasks.withType(CreateStartScripts) {
def tplName = 'unixStartScriptTemplate.txt'
assert project.file(tplName).exists()
unixStartScriptGenerator.template = resources.text.fromFile(tplName)
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With