弃用警告

mys*_*eim 18 gradle

我有这个代码:

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
}
Run Code Online (Sandbox Code Playgroud)

我收到了这个警告:

在任务执行时配置复制任务的子规范已被弃用,并计划在Gradle 4.0中删除.请考虑在配置时配置规范,或使用单独的任务进行配置.在build_b2xrs1xny0xxt8527sk0dvm2y $ _run_closure4.doCall

这个警告:

不推荐使用Task.leftShift(Closure)方法,并计划在Gradle 5.0中删除它.请改用Task.doLast(Action).

如何重写我的任务?

Mar*_*ler 0

它可能看起来像这样;这至少应该修复警告之一:

task fatJar(type: Jar) {
    manifest {
        attributes 'Implementation-Title': 'Gradle Jar File Example',
                   'Implementation-Version': version,
                   'Main-Class': 'mvc.MvcMain'
    }
    baseName = project.name + '-all'
    from {
        configurations.compile.collect {
            it.isDirectory() ? it : zipTree(it)
        } 
    }
    with jar
}
Run Code Online (Sandbox Code Playgroud)