Java 升级到Gradle 2.0后:找不到属性';编译';关于根项目
为了避免在构建Java源代码时出现有关特殊字符的警告,我在升级到gradle 2.0之前运行良好的Java 升级到Gradle 2.0后:找不到属性';编译';关于根项目,java,gradle,Java,Gradle,为了避免在构建Java源代码时出现有关特殊字符的警告,我在升级到gradle 2.0之前运行良好的gradle.build中放了这一行: tasks.withType(Compile) { options.encoding = "UTF-8" } 升级后,此操作失败,出现以下错误: Could not find property 'Compile' on root project 如何修复此问题?将行更改为 tasks.withType(JavaCompile) { options.enco
gradle.build中放了这一行:
tasks.withType(Compile) { options.encoding = "UTF-8" }
升级后,此操作失败,出现以下错误:
Could not find property 'Compile' on root project
如何修复此问题?将行更改为
tasks.withType(JavaCompile) { options.encoding = "UTF-8" }
修复了这个问题。用于基于Groovy的项目。应该是:
tasks.withType(GroovyCompile) {
options.debug = true
}
使用task.withType(JavaCompile)
我的代码:
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"
}
}
Compile
早就被弃用,取而代之的是JavaCompile
,最终在2.0中被删除。@PeterNiederwieser:很高兴知道,谢谢。我没有注意到这一点,因为在使用Gradle pre 2.0编译时没有收到任何弃用警告。@PeterNiederwieser如何为所有编译任务(不仅仅是java)设置编码?它以前是Compile
,我是否应该使用任务。改为使用类型(AbstractCompile)
?Compile
已重命名为JavaCompile
。要设置Groovy源代码的编码,请使用tasks.withType(GroovyCompile){groovyOptions.encoding=“UTF-8”}
。对于Scala源代码,请使用tasks.withType(ScalaCompile){scalaCompileOptions.encoding=“UTF-8”}
。从来没有比这更简单的方法。虽然这可以解决OP问题,但请只添加代码的基本部分,并提供解释。