Java 升级到 Gradle 2.0 后:在根项目中找不到属性“编译”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/24668746/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-14 13:57:17  来源:igfitidea点击:

After upgrading to Gradle 2.0: Could not find property 'Compile' on root project

javagradle

提问by Matthias Braun

To avoid warnings regarding special characters when building my Java source code, I put this line in my gradle.buildwhich worked fine before upgrading to Gradle 2.0:

为了避免在构建我的 Java 源代码时出现关于特殊字符的警告,我gradle.build在升级到 Gradle 2.0 之前将这一行放在我的工作正常的行中:

tasks.withType(Compile) { options.encoding = "UTF-8" }

After upgrading, this fails with the following error:

升级后,这失败并出现以下错误:

Could not find property 'Compile' on root project

How can I fix that?

我该如何解决?

采纳答案by Matthias Braun

Changing the line to

将线更改为

tasks.withType(JavaCompile) { options.encoding = "UTF-8" }

fixed the issue.

解决了这个问题。

回答by AKS

For Groovy based projects. It'd be:

对于基于 Groovy 的项目。应该是:

tasks.withType(GroovyCompile) {
    options.debug = true
}

回答by liu shuai

Use task.withType(JavaCompile).

使用task.withType(JavaCompile).

My code:

我的代码:

buildscript {
    repositories {
        jcenter()
    }

    dependencies {
        classpath 'com.bmuschko:gradle-tomcat-plugin:2.2.3'
    }

  tasks.withType(JavaCompile) {
      options.debug = true
      options.debugOptions.debugLevel = "source,lines,vars"
      options.encoding = "UTF-8"
  }
}