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

前端 未结 8 1634
被撕碎了的回忆
被撕碎了的回忆 2020-12-06 09:02

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

Declar

相关标签:
8条回答
  • 2020-12-06 09:30

    Remove these lines from your code.

    task clean(type: Delete) {
        delete rootProject.buildDir
    }
    
    0 讨论(0)
  • 2020-12-06 09:30

    I had this same issue, unfortunately, for me I put the task clean in the wrong place. I had this:

    allprojects {
        repositories {
            google()
            jcenter()
            mavenCentral()
        }
    
        tasks.withType(JavaCompile) {
            sourceCompatibility = "1.8"
            targetCompatibility = "1.8"
        }
    
    
        task clean(type: Delete) {
            delete rootProject.buildDir
        }
    }
    

    Which needed to be this:

    allprojects {
        repositories {
            google()
            jcenter()
            mavenCentral()
        }
    
        tasks.withType(JavaCompile) {
            sourceCompatibility = "1.8"
            targetCompatibility = "1.8"
        }
    }
    
    task clean(type: Delete) {
        delete rootProject.buildDir
    }
    
    0 讨论(0)
  • 2020-12-06 09:32

    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`
    }
    }
    
    0 讨论(0)
  • 2020-12-06 09:34

    You should not try to override the default clean task, but instead configure it to delete additional stuff like

    clean {
        delete rootProject.buildDir
    }
    

    But check first whether this is not the default behavior of the clean task anyway.

    Alternatively if you want to be able to do a specific clean action individually, you can also define a separate task and add a dependency like

    task customClean(type: Delete) {
        delete rootProject.buildDir
    }
    clean.dependsOn customClean
    
    0 讨论(0)
  • 2020-12-06 09:34

    After so many research i found we have to just comment the line of clean task in bulid.gradle(Project) like below :

    //    task clean(type: Delete) {
    //        delete rootProject.buildDir
    //    }][1][enter image description here][1]
    

    See the image for hint

    0 讨论(0)
  • 2020-12-06 09:47
    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.

    0 讨论(0)
提交回复
热议问题