gpt4 book ai didi

Gradle 7 迁移 : Failed to apply PublishPlugin (maven-publish): Cannot run afterEvaluate when the project is already evaluated

转载 作者:行者123 更新时间:2023-12-05 04:47:07 39 4
gpt4 key购买 nike

将 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'

我的猜测是这里有问题和/或它与迁移指南部分有关 "afterEvalute is now an error" .

task publishAll() {
subprojects.each { pr ->
dependsOn {
pr.tasks.findAll { task -> task.name.startsWith('publish') }
}
}
outputs.upToDateWhen { false }
}
publishAll.outputs.upToDateWhen { false }

subproject1build.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'

evaluate 阶段之后执行,因此,错误:

Cannot run afterEvaluate when the project is already evaluated

解决方法是在buildSrc中写一个convention gradle plugin

要跟进,请参阅例如这个video来自 Gradle。

关于Gradle 7 迁移 : Failed to apply PublishPlugin (maven-publish): Cannot run afterEvaluate when the project is already evaluated,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68586807/

39 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com