【问题标题】:How do I change unixStartScriptGenerator.template in the createStartScripts task so that distTar uses my custom template file in build.gradle?如何更改 createStartScripts 任务中的 unixStartScriptGenerator.template 以便 distTar 在 build.gradle 中使用我的自定义模板文件?
【发布时间】: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 的行。

如果有更好的方法来设置这个模板,请告诉我。

【问题讨论】:

标签: java gradle build.gradle software-distribution gradle-plugin


【解决方案1】:

这样你添加了一个新任务,而你应该挂钩到现有的任务,试试:

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

【讨论】:

  • 只需一个编辑:设置模板应该是unixStartScriptGenerator.template = ...
猜你喜欢
  • 2012-02-05
  • 1970-01-01
  • 1970-01-01
  • 2016-05-19
  • 2019-05-29
  • 2023-03-29
  • 2016-10-19
  • 2016-12-01
  • 2018-04-21
相关资源
最近更新 更多