com.diffplug.gradle.spotless && task clean(type: Delete){} Error:Cannot add task 'clean' as a task with that name already exists
com.diffplug.gradle.spotless && task clean(type: Delete){} Error:Cannot add task 'clean' as a task with that name already exists
这是我的build.gradle
buildscript {
ext {
...
}
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.5.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"
classpath "androidx.navigation:navigation-safe-args-gradle-plugin:$navigationVersion"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
plugins {
id "com.diffplug.gradle.spotless" version "3.26.0"
}
allprojects {
repositories {
google()
jcenter()
}
}
spotless {
kotlin {
target "**/*.kt"
ktlint(ktlintVersion).userData(['max_line_length' : '100'])
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
原来编译成功,但是在引入spotless
的时候,出现了这个错误:
com.diffplug.gradle.spotless && task clean(type: Delete){} Error:Cannot add task 'clean' as a task with that name already exists
所以,我猜这两部分是有冲突的,但我不知道具体原因。
plugins {
id "com.diffplug.gradle.spotless" version "3.26.0"
}
//...
task clean(type: Delete) {
delete rootProject.buildDir
}
您在项目级别 build.gradle
中定义了此任务(在您的评论中发布):
task clean(type: Delete) {
delete rootProject.buildDir
}
Android Studio 的 Gradle wrapper
已经定义了 clean
任务,因此无需重新定义它。只需从您的项目级 build.gradle
文件中删除该任务。
添加到 R.Desai 的回答中,
实际上 Gradle 的 BasePlugin 只清理应用程序级别的构建目录。医生说
clean — Delete Deletes the build directory and everything in it, i.e.
the path specified by the Project.getBuildDir() project property.
Check the docs here for more info.
但是,解决方法是一样的。 spotless 插件与您定义的“干净”任务冲突,因为它在引擎盖下具有相同的实现,它会清理项目级构建目录。这是他们 github 回购 "Duplicate clean task #521"
中的问题
这是我的build.gradle
buildscript {
ext {
...
}
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.5.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"
classpath "androidx.navigation:navigation-safe-args-gradle-plugin:$navigationVersion"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
plugins {
id "com.diffplug.gradle.spotless" version "3.26.0"
}
allprojects {
repositories {
google()
jcenter()
}
}
spotless {
kotlin {
target "**/*.kt"
ktlint(ktlintVersion).userData(['max_line_length' : '100'])
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
原来编译成功,但是在引入spotless
的时候,出现了这个错误:
com.diffplug.gradle.spotless && task clean(type: Delete){} Error:Cannot add task 'clean' as a task with that name already exists
所以,我猜这两部分是有冲突的,但我不知道具体原因。
plugins {
id "com.diffplug.gradle.spotless" version "3.26.0"
}
//...
task clean(type: Delete) {
delete rootProject.buildDir
}
您在项目级别 build.gradle
中定义了此任务(在您的评论中发布):
task clean(type: Delete) {
delete rootProject.buildDir
}
Android Studio 的 Gradle wrapper
已经定义了 clean
任务,因此无需重新定义它。只需从您的项目级 build.gradle
文件中删除该任务。
添加到 R.Desai 的回答中,
实际上 Gradle 的 BasePlugin 只清理应用程序级别的构建目录。医生说
clean — Delete Deletes the build directory and everything in it, i.e. the path specified by the Project.getBuildDir() project property.
Check the docs here for more info.
但是,解决方法是一样的。 spotless 插件与您定义的“干净”任务冲突,因为它在引擎盖下具有相同的实现,它会清理项目级构建目录。这是他们 github 回购 "Duplicate clean task #521"
中的问题