我将 Gradle 从 6.8 升级到 7.1.1 后,出现了以下问题:
A problem occurred evaluating script.
> Failed to apply plugin class 'org.gradle.api.publish.plugins.PublishingPlugin'.
> Cannot run Project.afterEvaluate(Action) when the project is already evaluated.
我的publish.gradle
文件抛出异常:
configure(subprojects.findAll({ it.name in ["subpr1", "subpr2", "subpr3"] })) {
subproject ->
apply plugin: 'com.android.library'
apply plugin: 'maven-publish' <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
我在我的build.gradle
文件中没有找到任何evaluation*
或evaluate*
任务的用法。
有什么想法可以解决这个问题吗?
我的根build.gradle
文件:
buildscript {
ext.gradle_version = "7.0.0"
repositories {
google()
mavenCentral()
gradlePluginPortal()
}
dependencies {
classpath "com.android.tools.build:gradle:$gradle_version"
}
}
ext {
...
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
}
def properties = new Properties()
properties.load(new FileInputStream("local.properties"))
allprojects {
repositories {
google()
mavenCentral()
gradlePluginPortal()
maven {
url = uri("...")
credentials {
username = properties.getProperty("...")
password = properties.getProperty("...")
}
}
}
}
apply plugin: 'android-reporting'
task publishAll() {
subprojects.each { pr ->
dependsOn {
pr.tasks.findAll { task -> task.name.startsWith('publish') }
}
}
outputs.upToDateWhen { false }
}
publishAll.outputs.upToDateWhen { false }
task clean(type: Delete) {
delete rootProject.buildDir
}
apply from: 'publish.gradle'
我猜测这里出了问题,或者与迁移指南的 "afterEvaluate现在是一个错误"有关。
task publishAll() {
subprojects.each { pr ->
dependsOn {
pr.tasks.findAll { task -> task.name.startsWith('publish') }
}
}
outputs.upToDateWhen { false }
}
publishAll.outputs.upToDateWhen { false }
subproject1
的 build.gradle
文件:
plugins {
id 'com.android.library'
}
android {
compileSdkVersion rootProject.ext.compileSdkVersion
buildToolsVersion rootProject.ext.buildToolsVersion
defaultConfig {
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionName rootProject.ext.cyfaceBackendVersion
testInstrumentationRunner rootProject.ext.testInstrumentationRunner
}
productFlavors {
a {
dimension "project"
}
b {
dimension "project"
}
mock {
dimension "mode"
}
full {
dimension "mode"
}
}
buildTypes {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
testOptions {
unitTests {
includeAndroidResources = true
returnDefaultValues = true
}
}
compileOptions {
sourceCompatibility rootProject.ext.sourceCompatibility
targetCompatibility rootProject.ext.targetCompatibility
}
lintOptions {
disable 'ObsoleteLintCustomCheck'
}
}
dependencies {...}
apply from: 'publish.gradle'
往上移一点到build.gradle
中,我会得到另一个错误,我的publish.gradle
中稍后的classpath += files(configurations.compile)
行会抛出MissingPropertyException: Could not get unknown property 'compile'
。 - hb0