使用gradle任务运行不带main方法的groovy类文件

时间:2017-03-20 15:27:23

标签: gradle

我有一个没有main方法的类文件。我只需要在gradle任务的帮助下运行类文件。有人可以帮我写一个gradle任务吗?

1 个答案:

答案 0 :(得分:1)

我猜它会像

buildscript {
    // add your library to the buildscript classpath
    classpath 'foo.bar:mygroovylib:1.0'
}

task runMyGroovy {
    // let's assume your service accepts an input file and writes to an output directory
    File inFile = file('path/to/some/file.xml')
    File outDir = file("$buildDir/myGroovy")

    // set task inputs/outputs to benefit from gradle's up-to-date checks
    inputs.file inFile
    outputs.dir outDir

    doLast {
       // actually do stuff in gradle's execution phase
       def myObject = new MyGroovyObject();
       myObject.doSomethingFantastic(inFile, outDir)
    }
}