简体   繁体   English

使用gradle任务运行没有主要方法的groovy类文件

[英]Run a groovy class file without main method using gradle task

I have a class file which does not have a main method. 我有一个没有主要方法的类文件。 I need to run the class file only when needed with the help of a gradle task. 我只需要在gradle任务的帮助下运行类文件。 Can someone help me with writing a gradle task for it? 有人可以帮我编写gradle任务吗?

I'd guess it'd be something like 我猜可能是这样

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)
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM