我想定义一个gradle
自定义任务。这是结构:
├── buildSrc
│ ├── buildSrc.iml
│ └── src
│ └── main
│ └── groovy
│ └── com
│ └── gocd
│ └── CustomTask.groovy
| -- build.gradle
在CustomTask.groovy文件中:
import com.mongodb.Mongo
import org.gradle.api.DefaultTask
import org.gradle.api.tasks.TaskAction
import org.mongeez.Mongeez
import org.springframework.core.io.ClassPathResource
class CustomTask extends DefaultTask {
@TaskAction
def upgradeMongo() {
Mongeez mongeez = new Mongeez()
mongeez.setFile(new ClassPathResource("mongeez.xml"))
mongeez.setDbName("local_pipeline")
mongeez.setMongo(new Mongo("127.0.0.1", 27017))
mongeez.process()
}
}
我在build.gradle文件中声明了一个gradle任务:
task updateMongo(type: CustomTask)
,之后,我运行 gradle build ,错误是:
/fgcui/myProject/buildSrc/src/main/groovy/com/gocd/CustomTask.groovy: 3:
unable to resolve class com.mongodb.Mongo
@ line 3, column 1.
import com.mongodb.Mongo
^
/Users/fgcui/myProject/buildSrc/src/main/groovy/com/gocd/CustomTask.groovy: 6:
unable to resolve class org.mongeez.Mongeez
@ line 6, column 1.
import org.mongeez.Mongeez
^
/Users/fgcui/myProject/buildSrc/src/main/groovy/com/gocd/CustomTask.groovy: 7:
unable to resolve class org.springframework.core.io.ClassPathResource
@ line 7, column 1.
import org.springframework.core.io.ClassPathResource
^
3 errors
:buildSrc:compileGroovy FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':compileGroovy'.
> Compilation failed; see the compiler error output for details.
我做错了什么?