Spring boot 如何在gradle中为Spring Boot项目和EclipseIDE调用外部命令?
在我的Spring Boot 2.0 gradle项目中,每次在eclipse IDE中修改并保存bar.tmpl.html时,我都需要调用以下命令:Spring boot 如何在gradle中为Spring Boot项目和EclipseIDE调用外部命令?,spring-boot,gradle,handlebars.js,Spring Boot,Gradle,Handlebars.js,在我的Spring Boot 2.0 gradle项目中,每次在eclipse IDE中修改并保存bar.tmpl.html时,我都需要调用以下命令: handlebars src/main/resources/static/templates/bar.tmpl.html -f src/main/resources/static/js/bar.tmpl.js 此命令在spring项目目录根目录下的shell中运行时有效 我想在使用devtools在STS-eclipseide中开发时自动化这个
handlebars src/main/resources/static/templates/bar.tmpl.html -f src/main/resources/static/js/bar.tmpl.js
此命令在spring项目目录根目录下的shell中运行时有效
我想在使用devtools在STS-eclipseide中开发时自动化这个过程。每次对把手模板文件进行编辑时,应自动运行上述命令重新生成项目
如何实现这一点?您可以编写自定义类型的任务来运行命令并使其执行。或者,您可以将任务挂接到生命周期中的某个点,例如processResources任务
执行类型任务以运行命令:
task updateHandelbar(type: Exec) {
inputs.files "${projectDir}/src/main/resources/static/templates/bar.tmpl.html"
outputs.files "${projectDir}/src/main/resources/static/templates/bar.tmpl.html"
commandLine 'cmd', '/c', 'handlebars src/main/resources/static/templates/bar.tmpl.html -f src/main/resources/static/js/bar.tmpl.js'
}
将任务挂接到生命周期中的任何一点:
task updateHandelbar(type: Exec) {
inputs.files "${projectDir}/src/main/resources/static/templates/bar.tmpl.html"
outputs.files "${projectDir}/src/main/resources/static/templates/bar.tmpl.html"
commandLine 'cmd', '/c', 'handlebars src/main/resources/static/templates/bar.tmpl.html -f src/main/resources/static/js/bar.tmpl.js'
}
语法:.shoudlRunAfter()
示例:
processResources.shouldlrunafter(updateHandelbar)
连续运行任务并等待文件更改:
task updateHandelbar(type: Exec) {
inputs.files "${projectDir}/src/main/resources/static/templates/bar.tmpl.html"
outputs.files "${projectDir}/src/main/resources/static/templates/bar.tmpl.html"
commandLine 'cmd', '/c', 'handlebars src/main/resources/static/templates/bar.tmpl.html -f src/main/resources/static/js/bar.tmpl.js'
}
这将持续执行任务。表示在输入文件更改时重新运行任务:
gradlew <someTask> -continuous
gradlew-连续
每个代码片段的组合可能会使您获得预期的行为。不符合Pluto我遵循了您的答案,但它不起作用。“把手”命令永远不会运行。此外,即使这样做有效,eclipse IDE也不会看到生成的文件,除非我在eclipse中手动刷新eclipse项目,因为在eclipse之外对项目文件所做的任何更改,否则eclipse将不会看到它。如何运行应用程序?Gradle与任何IDE或刷新IDE的资源无关。它完全独立于任何平台运行。如果您依赖Eclipse构建链而不使用Gradle(即Gradle包装器)来运行应用程序,则不会调用任何任务。我在Eclipse中运行我的应用程序。但是为了测试您的解决方案,我按照您的建议运行。/gradlew processResources-continuous语句
processResources.shouldRunAfter(updateHandelbar)
旨在作为一个示例,说明如何将任务挂接到项目生命周期中适合它的某个点。如果您的生命周期未使用processResources任务,则永远不会调用它。要测试updateHandelbar任务,必须运行gradlew updateHandelbar
。我仍然不知道你是如何运行你的应用程序的。您在eclipse中有运行配置吗?您是否在comandline上使用gradlew
?您正在运行什么gradle任务来执行应用程序?