2016-08-11 4 views
4

アーカイブを作成して戦争をしてから、別の名前の別のコピーを使いたいと思っています。私はそのコピータスクがこのかなり大きなビルドの残りの部分を減速させたくないということです。それを非同期に実行することは可能ですか?もしそうなら、どうですか?非同期グラデルコピータスク?

+1

ないアイデアは、これが実際に動作するかどうかが、あなたはそれを試してみることができます。http:/ /stackoverflow.com/a/38528039/745574 – RaGe

+0

本当に素敵な@RaGe、これを見つけてくれてありがとう! – Opal

+0

私はこれが働いていると思います。みんなありがとう。あなたは答えとして投稿しますか? – user447607

答えて

1
import java.util.concurrent.* 
... 
def es = Executors.newSingleThreadExecutor() 
... 
war { 
... 
doLast{ 
     es.submit({ 
      copy { 
       from destinationDir.absolutePath + File.separator + "$archiveName" 
       into destinationDir 
       rename "${archiveName}", "${baseName}.${extension}" 

      } 
     } as Callable) 
    } 
} 
+0

そうでしょうか?できます。ファイルはコピーされますが、実際に非同期コピーであるかどうかを調べる方法はIDKにあります。 – user447607

+0

doLastは、他のことが起こる前にそれを止めないようにします。コピーが必要な戦争の創造のように。 – user447607

+0

上記を読んで、私は自分の質問にちょうど答えました。 – user447607

1

場合によってはparallel execution featureを使用すると便利です。これはマルチプロジェクトビルドでのみ機能します(並列実行するタスクは別々のプロジェクトになければなりません)。

project('first') { 
    task copyHugeFile(type: Copy) { 
    from "path/to/huge/file" 
    destinationDir buildDir 
    doLast { 
     println 'The file is copied' 
    } 
    } 
} 

project('second') { 
    task printMessage1 << { 
    println 'Message1' 
    } 

    task printMessage2 << { 
    println 'Message2' 
    } 
} 

task runAll { 
    dependsOn ':first:copyHugeFile' 
    dependsOn ':second:printMessage1' 
    dependsOn ':second:printMessage2' 
} 

デフォルト出力:

$ gradle runAll 

:first:copyHugeFile 
The file is copied 
:second:printMessage1 
Message1 
:second:printMessage2 
Message2 
:runAll 

出力--parallelと:

$ gradle runAll --parallel 

Parallel execution is an incubating feature. 
:first:copyHugeFile 
:second:printMessage1 
Message1 
:second:printMessage2 
Message2 
The file is copied 
:runAll 
+0

dbUnitの技術負債のために使用することはできません。実際にファイルを並行してコピーすることができない理由は本当にありませんので、私はそれを書くことを好みます。 – user447607