有没有办法在gradle中有两个任务,并且都在插件中返回正确的值设置参数
我有:
的build.gradle
apply plugin: 'gradle.plugin'
task FirstTask(type: com.nav.Coding){
param.dictFile = file ("${projectDir}/src/main/resources/customized_struct.xml")
param.outputDirectory = file("${buildDir}/generated/"
}
task SecondTask(type: com.nav.Coding){
param.dictFile = file("${projectDir}/src/main/resources/customized_struct_two.xml")
param.outputDirectory = file("${buildDir}/generated/"
}
出于某种原因,我的输出只是第二个dictFile
,而不是第一个将参数设置到JVM并处理自定义插件时。
命令输出
$ gradle -q FirstTask SecondTask
:com:nav:Coding:FirstTask
Processing C:\dev\src\main\resources\customized_struct_two.xml
This is my output dictFile C:\dev\src\main\resources\customized_struct_two.xml
This is my output outputDirectory C:\dev\build\generated
:com:nav:Coding:SecondTask
Processing C:\dev\src\main\resources\customized_struct_two.xml
This is my output dictFile C:\dev\src\main\resources\customized_struct_two.xml
This is my output outputDirectiory C:\dev\build\generated
BUILD SUCCESSFUL
Total time: 12.79 secs
答案 0 :(得分:1)
我相信你是因为将逻辑置于configuration
阶段而不是execution
阶段的常见错误而陷入困境。我相信你想:
task FirstTask(type: com.nav.Coding){
doFirst {
param.dictFile = file ("${projectDir}/src/main/resources/customized_struct.xml")
param.outputDirectory = file("${buildDir}/generated/"
}
}
task SecondTask(type: com.nav.Coding){
doFirst {
param.dictFile = file("${projectDir}/src/main/resources/customized_struct_two.xml")
param.outputDirectory = file("${buildDir}/generated/"
}
}
这对我来说很奇怪
param
来自哪里? dictFile
任务中为什么没有outputDirectory
和com.nav.Coding
属性?