弃用警告

时间:2017-01-12 17:07:03

标签: 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
}

我收到了这个警告:

  

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

和这个警告:

  

不推荐使用Task.leftShift(Closure)方法,并计划在Gradle 5.0中删除它。请使用Task.doLast(动作)   代替。

如何重写我的任务?

2 个答案:

答案 0 :(得分: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
}

答案 1 :(得分:0)

基本上引起这两个警告的行是

task fatJar(type: Jar) << {

您正在使用的Gradle版本(大概是某些3.x版本,leftShift Groovy运算符正在调用doLast方法。所有传递给<<的方法({ {1}}在该任务的leftShift任务操作中执行。

要解决doLast弃用问题

  

Task.leftShift(Closure)方法已被弃用,并计划在Gradle 5.0中删除。请改用Task.doLast(Action)。

您希望将任务更改为:

leftShift

现在,您仍然会看到其他警告:

  

在执行任务时配置复制任务的子级规范已被弃用,并计划在Gradle 4.0中删除。考虑在配置期间配置规范,或使用单独的任务进行配置。

此警告告诉您正在执行时修改task fatJar(type: Jar) { doLast { manifest { attributes 'Implementation-Title': 'Gradle Jar File Example', 'Implementation-Version': version, 'Main-Class': 'mvc.MvcMain' } baseName = project.name + '-all' with jar } } 任务的配置,这是一件不好的事。它搞砸了Gradle的最新检查和增量构建。

解决此警告的方法是,遵循先前CLI输出的建议之一。例如,这里是“在配置时间内配置规范”

fatJar

请注意,由于我们没有添加任何其他操作,因此不再存在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 } 块。

相关问题