How do I extend gradle's clean task to delete a file?

前端 未结 5 813
傲寒
傲寒 2021-02-01 00:29

So far i\'ve added the following to my build.gradle

apply plugin: \'base\' 
clean << {
    delete \'${rootDir}/api-library/auto-generated-classes/\'
    pr         


        
5条回答
  •  囚心锁ツ
    2021-02-01 01:13

    In order to extend the clean task, you can use

    clean.doFirst {}
    

    or

    clean.doLast {}
    

    These will allow you to inject your own actions into the clean process. In order to delete files and directories you can use the "file" API which doesn't require any additional plugins.

    Here is an example that will delete both a file and a directory as the last step in the clean task:

    clean.doLast {
        file('src/main/someFile.txt').delete()
        file('src/main/libs').deleteDir()
    }
    

提交回复
热议问题