【发布时间】:2017-10-11 00:34:06
【问题描述】:
我需要修改 gradle 为distTar 任务生成的启动脚本。我seem to be able to set unixStartScriptGenerator.template 如下所示,但是当我从 tar 解压脚本时,我的更改不存在。
这是我完整的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'
}
没关系,但我的模板 unixStartScriptTemplate.txt 与 the original unixStartScript.txt 基本相同,但有一些额外的 cmets 和更改 JAVACMD 的行。
如果有更好的方法来设置这个模板,请告诉我。
【问题讨论】:
-
这样你添加了一个新任务,而你应该挂钩到现有的任务,请参阅:gist.github.com/Opalo/88be0c6c1c03061581efab84bec9f96c
-
@Opal,这行得通!让它成为答案?
-
太棒了!给你!
标签: java gradle build.gradle software-distribution gradle-plugin