何在createStartScripts任务中更改unixSta

何在createStartScripts任务中更改unixSta

本文介绍了如何在createStartScripts任务中更改unixStartScriptGenerator.template,以便distTar在build.gradle中使用我的自定义模板文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要修改gradle为生成的启动脚本。任务。我,但是当我从tar中解压缩脚本时,所做的更改就不存在了。

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.

这是我完整的 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与,但带有一些额外的注释和

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.

如果有更好的方法来设置t他的模板,请让我知道。

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)
}

这篇关于如何在createStartScripts任务中更改unixStartScriptGenerator.template,以便distTar在build.gradle中使用我的自定义模板文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-01 06:57