简体   繁体   中英

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. Can someone help me with writing a gradle task for it?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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