2017-01-12 196 views
8

我有這樣的代碼:棄用警告

task fatJar(type: Jar) << { 
    manifest { 
     attributes 'Implementation-Title': 'Gradle Jar File Example', 
       'Implementation-Version': version, 
       'Main-Class': 'mvc.MvcMain' 
    } 
    baseName = project.name + '-all' 
    with jar 
} 

我得到了這樣的警告:

在任務的執行時間配置的副本任務的子功能已被棄用,按計劃將刪除在Gradle 4.0中。 考慮在配置時配置規格,或使用 單獨的任務來執行配置。 在build_b2xrs1xny0xxt8527sk0dvm2y $ _run_closure4.doCall

和這樣的警告:

的Task.leftShift(關閉)方法已被棄用,並計劃在搖籃5.0被刪除。請改用Task.doLast(Action) 。

如何重寫我的任務?

+0

那裏http://mrhaki.blogspot.com/2016/11/gradle-goodness-就是爲什麼一個簡評replace-operator-for.html – Thad

回答

16

刪除< <與doLast包起來{...}

// Since Gradle 3.2 the << (leftShift) operator 
// is deprecated. The operator can confuse 
// people, because without the operator 
// we would configure the deprecatedSample task, 
// instead of adding the action statement: 
// println 'Sample task'. 
task deprecatedSample << { 
    println 'Sample task' 
} 

// To have no confusion we should use 
// the doLast method of a task to add 
// the action statement: 
// println 'Sample task'. 
task newSample { 
    doLast { 
     println 'Sample task' 
    } 
} 
+1

你是http://mrhaki.blogspot.se/2016/11/gradle-goodness-replacing-operator-for.html的作者嗎?否則,你可能想給作者信用。 – jayeffkay