- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我们有一个可选的 gradle 任务 docker
这取决于任务 war
,如果执行,需要生成一个带有额外文件的war文件。这个额外的文件可以添加到 processResources
中的资源中。任务(或可能直接在 war
任务中)。但是,如果任务 docker
,则不能运行相应的代码块。未被请求且不会运行。
我们需要一个 正确条件 在以下 block 中检查任务 docker
正在筹备中:
processResources {
if (/* CONDITION HERE: task docker is requested */) {
from ("${projectDir}/docker") {
include "app.properties"
}
}
}
task docker(type: Dockerfile) {
dependsOn build
...
processResources
是
war
的标准依赖项任务,后者是
build
的标准依赖项任务。
processResources
总是在
build
上执行, 有或没有
docker
收集用于组装 war 的资源的任务,在这种情况下可能不会完全禁用。可以将有问题的代码移动到依赖于
docker
的单独任务中。并处理
processResources
的输出目录, 在
war
之前但是,运行这样的结构会导致这样一个简单的事情变得不那么清晰。
最佳答案
您可以简单地向您的 docker
添加额外的依赖项。任务,使其不仅依赖于build
任务,但也在 processResources
.在这种情况下,您的 processResources
只有在 docker
时才会调用任务应该被执行。
另一种解决方案是使用 TaskExecutionGraph .这使您可以初始化一些变量,该变量可以告诉您是否将执行某些任务。但是您必须了解,该图仅在所有配置完成后才准备好,您只能在执行阶段依赖它。这是一个简短的例子,它是如何使用的:
//some flag, whether or not some task will be executed
def variable = false
//task with some logic executed during the execution phase
task test1 << {
if (variable) {
println 'task2 will be executed'
} else {
println 'task2 will not be executed'
}
}
//according to whether or not this task will run or not,
//will differs test1 task behavior
task test2(dependsOn: test1) {
}
//add some logic according to task execution graph
gradle.taskGraph.whenReady {
taskGraph ->
//check the flag and execute only if it's true
if (taskGraph.hasTask(test2)) {
variable = true
println 'task test2 will be executed'
}
}
docker
,您可以尝试配置您的自定义任务,通过将启用属性设置为 false 来禁用它。任务不在执行图中。在这种情况下,您不必在执行阶段提供一些标志和逻辑。像:
task test1 {
//some logic for execution
doLast {
println "execute some logic"
}
}
task test2(dependsOn: test1) {
}
gradle.taskGraph.whenReady {
taskGraph ->
if (!taskGraph.hasTask(test2)) {
//Disable test1 task if test2 will not run
test1.enabled = false
}
}
关于gradle - gradle.processResources 中的代码块取决于是否请求了另一个任务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33503145/
等级:如何自定义processResources以更改jar中的资源文件路径? 例如: foo/a.xml --> foo/bar/a.xml 类似于: copy tree with gradle
我们有一个可选的 gradle 任务 docker这取决于任务 war ,如果执行,需要生成一个带有额外文件的war文件。这个额外的文件可以添加到 processResources 中的资源中。任务(
在 jar 任务中,我想替换 conf 文件中的一些文本。 jar { ext { excludedClasses = ["com.MyClass1", "com.MyClas
我希望这是一个简单的问题,但我没有找到答案。 我想让 build.gradle 文件通过替换某些变量来设置我的 Spring Boot 应用程序中的版本。这与广告一样有效: def tokens =
我喜欢在我的 gradle 项目中过滤特定的 java 资源。有些文件应该只替换内容,有些文件也应该重命名(并替换不同的内容)。 我的 gradle java 项目设置是: > cat build.g
如何在包含 $ 字符的文件上执行 gradle processResources 而不转义文件中的 $? 按照 Spring Boot reference docs 的建议,我有一些静态 html 文
我花了几个小时来解决我认为与损坏文件有关的问题。基本上我在 spring boot 应用程序中使用 FlyingSaucer 来生成语言兼容的 pdf。我所有的日文/中文/俄文字符都是空白的。经过深入
环境: - Spring Boot - Gradle - Kotlin 我在 Gradle 中配置了自动属性扩展以在我的 application.yml 中使用 gradle 属性 processRe
以下似乎是 gradle 中过滤资源文件子集的常用习惯用法。我明白它的作用,但我无法解读语法: processResources { filesMatching('foo/*.html') {
我必须从 processResources gradle 任务中排除 xsl 和 xsd 类型的文件。目前我只排除了 xsl 文件和我的 build.gradle 片段,如下所示: processRe
我们有一个奇怪的问题,即删除 META-INF 文件夹和编译类以启动的 compileJava 任务随机且不频繁地运行,但 processResources 任务报告是最新的,即使 META-INF
在 IntelliJ 中运行或调试 Java 应用程序时,src 中捆绑的资源需要处理的文件夹。如果实际应用程序恰好是一个 gradle 项目,IntelliJ 需要运行 processResourc
我在基于 groovy 的构建脚本中有以下内容。如何在基于 kotlin 的脚本中执行相同的操作? processResources { filesMatching('application.
我目前正在做一个项目。该项目的资源包含许多 json 文件,这些文件最终都在最终的 jar 中。我已经在处理资源了。就像重命名文件和替换某些其他文件中的某些字符串一样。所以 processResour
我们正在从 Java/Gradle 堆栈迁移到 Scala/SBT。我们的 gradle 构建正在利用一个名为 processResources 的任务和一些名为 ReplaceTokens 的 An
替换我的 Spring Boot 中的属性 application.yml我已经添加: processResources { filesMatching("**/application.yml
我有一个 IDEA 2016.1 Enterprise 和一个 Gradle 2.12 多模块项目。在其中一个模块中,在 src/main/resources 中,我有一个文件,我希望 Gradle
当使用 gradle build 命令从命令行构建时,属性字段被正确替换,但是,当使用 IntelliJ IDEA IDE 时,它不是。 代码在build.gradle ext { port
我是一名优秀的程序员,十分优秀!