我正在向 jCenter 添加一个库,为此我需要向项目的 build.gradle 文件添加一些插件。但是,我收到错误
不允许在使用标准 Gradle 生命周期插件时声明自定义“清理”任务。
我可以看到
task clean
块,当我删除它时,错误就会消失。我想这就是我需要做的全部事情,但是它之前做过一些重要的事情吗?如果我有时删除插件并忘记重新添加 clean
块,将会产生什么可怕的后果?
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
}
您不应尝试覆盖默认的
clean
任务,而应将其配置为删除其他内容,例如
clean {
delete rootProject.buildDir
}
但首先要检查这是否不是 clean 任务的默认行为。
或者,如果您希望能够单独执行特定的清理操作,您也可以定义一个单独的任务并添加依赖项,例如
task customClean(type: Delete) {
delete rootProject.buildDir
}
clean.dependsOn customClean
从代码中删除这些行。
task clean(type: Delete) {
delete rootProject.buildDir
}
在给定的代码中:
allprojects {
repositories {
google()
jcenter()
mavenCentral()
}
tasks.withType(JavaCompile) {
sourceCompatibility = "1.8"
targetCompatibility = "1.8"
}
task clean(type: Delete) {
delete rootProject.buildDir
}
}
将
task clean
替换为 task delete
然后就可以了:
allprojects {
repositories {
google()
jcenter()
mavenCentral()
}
tasks.withType(JavaCompile) {
sourceCompatibility = "1.8"
targetCompatibility = "1.8"
}
task delete(type: Delete) {
delete rootProject.buildDir`
}
}
我也遇到了同样的问题,不幸的是,对我来说,我把
task clean
放在了错误的位置。我有这个:
allprojects {
repositories {
google()
jcenter()
mavenCentral()
}
tasks.withType(JavaCompile) {
sourceCompatibility = "1.8"
targetCompatibility = "1.8"
}
task clean(type: Delete) {
delete rootProject.buildDir
}
}
需要是这样的:
allprojects {
repositories {
google()
jcenter()
mavenCentral()
}
tasks.withType(JavaCompile) {
sourceCompatibility = "1.8"
targetCompatibility = "1.8"
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
enter code hereallprojects {
repositories {
google()
jcenter()
maven {
url 'https://maven.google.com'
}
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
如果您已在“build.gradle”中添加了maven,请检查所有括号。代码应该如上。它应该可以解决问题。括号可能放置在不同的位置。
因为
buildDir
已被弃用。
我们来使用吧
tasks.register('clean', Delete) {
delete rootProject.layout.buildDirectory
}
6米 好的,我在 Gradle 中收到错误,无法清理根项目文件。
:25 AM Gradle 同步失败:不允许在使用标准 Gradle 生命周期插件时声明自定义“清理”任务。
错误代码 info-ide.actionsShowFilePathAction 退出代码 1
清洁触发器 nom run clean dependentsOn"npmInstall"
在 Gradle 文档 4.7 中 执行 Build 的目录中的 Project 也会被配置,但仅限于在没有任何任务的情况下执行 Gradle 时。这样,当按需配置项目时,默认任务就会正确运行。
按需配置Gradle 4.6 适用于 Gradle 3.01 或 3.1.0 的 Android 插件 Gradle 属性文件 org.gradleconfigureondemand=false
所以我所做的就是把任务注释干净,现在我得到了一个构建,
我认为如果您构建并修改了项目,该脚本就可以工作。 当您下载该项目时,您还没有第一次构建它。因此,没有需要清理的根项目路径,因为它尚未构建。这会导致它失败。 通过第一次将其注释掉,您就不会收到错误。
这是代码。 // 顶级构建文件,您可以在其中添加所有子项目/模块通用的配置选项。
` 构建脚本 { 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
} */
'