Declaring custom 'clean' task when using the standard Gradle lifecycle plugins is not allowed

Viewed 33639

I am adding a library to jCenter so to do that I needed to add some plugins to my project's build.gradle file. However, I am getting the error

Declaring custom 'clean' task when using the standard Gradle lifecycle plugins is not allowed.

I can see the task clean block and when I delete it the error goes away. I assume that is all I need to do, but was it doing something important before? If I remove the plugins sometime and forget to add the clean block back in, what dire consequences are in store?

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.3.1'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

plugins {
    id "com.jfrog.bintray" version "1.7.3"
    id "com.github.dcendents.android-maven" version "1.5"
}

allprojects {
    repositories {
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

This and this this did not satisfactorily answer the question.

7 Answers

Remove these lines from your code.

task clean(type: Delete) {
    delete rootProject.buildDir
}

In the given code:

allprojects {
repositories {
    google()
    jcenter()
    mavenCentral()
}

tasks.withType(JavaCompile) {
    sourceCompatibility = "1.8"
    targetCompatibility = "1.8"
}


task clean(type: Delete) {
    delete rootProject.buildDir
}
}

replace the task clean with task delete then it will work:

allprojects {
repositories {
    google()
    jcenter()
    mavenCentral()
}

tasks.withType(JavaCompile) {
    sourceCompatibility = "1.8"
    targetCompatibility = "1.8"
}


task delete(type: Delete) {
    delete rootProject.buildDir`
}
}
enter code hereallprojects {
repositories {
    google()
    jcenter()
    maven {
        url 'https://maven.google.com'
    }
}

}

task clean(type: Delete) {
    delete rootProject.buildDir
}

if you have added maven in your "build.gradle" then checkout all the brackets. The code should be as above. It should solve the problem. It is possible that brackets are placed in different places.

6m Okay, I get an error in Gradle that it cannot clean the root project file.

:25 AM Gradle sync failed: Declaring custom ‘clean’ task when using the standard Gradle lifecycle plugins is not allowed.

error code info-ide.actionsShowFilePathAction Exit Code 1

Clean Triggers nom run clean dependsOn"npmInstall"

In the Gradle doc 4.7 The Project in the directory where the Build is executed is also configured but only when Gradle is executed without any tasks. This way the default tasks behave correctly when projects are configured on demand.

Configuration on demand Gradle 4.6 Android plugin for Gradle 3.01 or 3.1.0 with Gradle Gradle properties file org.gradleconfigureondemand=false

So what I did was to comment out the task clean and now I get a build that words,

I think what happened is that this script works if you had built and modified the project. When you download the project you have not built it for the first time. Therefore there is no Root Project Path to clean as it has never been built yet. This causes it to fail. By commenting it out the first time you don’t get the error.

Here is the code. // Top-level build file where you can add configuration options common to all sub-projects/modules.

` buildscript { ext.kotlin_version = ‘1.2.41’

     ext.support_version = '26.1.0'

repositories {
    google()
    jcenter()
}

dependencies {
    classpath 'com.android.tools.build:gradle:3.1.2'
    classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
apply plugin: ‘kotlin’

allprojects {
repositories {
google()
jcenter()
}
}

/*
task clean(type: Delete) {
delete rootProject.buildDir

} */

'
Related