弃用警告 [英] Deprecation warnings

查看:212
本文介绍了弃用警告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有此代码:

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

Configuring child specs of a copy task at execution time of the task has been deprecated and is scheduled to be removed in Gradle 4.0. Consider configuring the spec during configuration time, or using a separate task to do the configuration. at build_b2xrs1xny0xxt8527sk0dvm2y$_run_closure4.doCall

和此警告:

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

The Task.leftShift(Closure) method has been deprecated and is scheduled to be removed in Gradle 5.0. Please use Task.doLast(Action) instead.

如何重写我的任务?

推荐答案

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

The line that is essentially causing both of the warnings is

task fatJar(type: Jar) << {

在您使用的Gradle版本中(可能是某些3.x版本,leftShift Groovy运算符正在调用doLast方法.传递给<<(leftShift)的所有内容都在doLast该任务的任务动作.

In the Gradle version you are using (which is presumably some 3.x version, the leftShift Groovy operator is calling the doLast method. Everything passed to << (leftShift) is executed in the doLast task action of that task.

要修复leftShift弃用

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

The Task.leftShift(Closure) method has been deprecated and is scheduled to be removed in Gradle 5.0. Please use Task.doLast(Action) instead.

您希望将任务更改为:

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
  }
}

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

Now, however, you will still see the other warning:

不建议在执行任务时配置复制任务的子规范,并计划在Gradle 4.0中删除该子规范.考虑在配置期间配置规范,或使用单独的任务进行配置.

Configuring child specs of a copy task at execution time of the task has been deprecated and is scheduled to be removed in Gradle 4.0. Consider configuring the spec during configuration time, or using a separate task to do the configuration.

此警告告诉您正在执行时修改fatJar任务的配置,这是一件不好的事.搞砸了Gradle的最新检查和增量构建.

This warning is telling you that you are modifying the configuration of your fatJar task at execution time, which is a bad thing to do. It messes upGradle up-to-date checking and incremental builds.

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

The way to fix this warning, is to follow one of the suggestions from the previous CLI output. For example, here is "configuring the spec during configuration time".

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
}

请注意,由于我们没有添加任何其他操作,因此不再有doLast块.

Notice there is no longer a doLast block since we aren't adding any different actions.

这篇关于弃用警告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆