簡體   English   中英

如何在createStartScripts任務中更改unixStartScriptGenerator.template,以便distTar在build.gradle中使用我的自定義模板文件?

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

我需要修改gradle為distTar任務生成的啟動腳本。 似乎能夠設置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 與原始的unixStartScript.txt大致相同,但有一些額外的注釋和一行更改JAVACMD。

如果有更好的方法來設置此模板,請告訴我。

這樣你添加一個新任務,而你應該掛鈎到現有任務,嘗試:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM