2017-02-22 5 views
0

build.gradleファイルにjavaexecタスクがあり、100個以上のファイルを順番に処理しています。このタスクに増分ビルドの動作を追加したいと思います。 カスタムタスクでこのインクリメンタル機能を実装する方法を教えてください。Gradle - カスタムjavaexecタスクの増分動作を追加する

+0

こんにちは、歓迎StackOverflow。ヘルプページ、特に[ここではどのトピックについて聞かせていただけますか?](http://stackoverflow.com/help/on-topic)と[質問しないでください。」](http://stackoverflow.com/help/dont-ask)。さらに重要なことは、[Stack Overflow question checklist](http://meta.stackexchange.com/q/156810/204922)をお読みください。また、[最小、完全、および検証可能な例](http://stackoverflow.com/help/mcve)についても知りたいことがあります。 – languitar

答えて

0
I have tried the following: 

class IncrementalReverseTask extends DefaultTask { 
    @InputDirectory 
    def File inputDir 

    @OutputDirectory 
    def File outputDir 

    @Input 
    def inputProperty 

    @TaskAction 
    void execute(IncrementalTaskInputs inputs) { 
     println inputs.incremental ? "CHANGED inputs considered out of date" 
            : "ALL inputs considered out of date" 
     if (!inputs.incremental) 
      project.delete(outputDir.listFiles()) 

     inputs.outOfDate { change -> 
      println "Modified: ${change.file.name}" 
      def targetFile = new File(outputDir, change.file.name) 
      targetFile.text = change.file.text.reverse() 
     } 

     inputs.removed { change -> 
      println "removed: ${change.file.name}" 
      def targetFile = new File(outputDir, change.file.name) 
      targetFile.delete() 
     } 
    } 
} 

then create a task like this 

task incrementalReverse(type: IncrementalReverseTask) { 
    inputDir = file('resource/inputs') 
    outputDir = file('resource/outputs') 
    inputProperty = project.properties['taskInputProperty'] ?: "original" 
} 

The above incremental task checks for changes in files in inputs folder. 
関連する問題