【发布时间】:2023-01-04 20:12:18
【问题描述】:
使用 Gradle 7.2 和这些插件:
plugins {
id 'com.android.library' // Android Gradle Plugin 7.1.2
id 'maven-publish'
}
它仍然有效,但给了我这个弃用警告:
警告:不会为从 Android Gradle 插件 8.0 发布的 Maven 自动创建软件组件。要选择加入未来的行为,请在
gradle.properties文件中设置 Gradle 属性android.disableAutomaticComponentCreation=true或使用新的发布 DSL。release notes 也提到了它,但这些指的是过时的文档:
从 AGP 8.0 开始,默认情况下将禁用自动组件创建。目前,AGP 7.1 自动为每个构建变体创建一个组件,该组件与构建变体具有相同的名称,以及一个包含所有构建变体的 all 组件。此自动组件创建将被禁用。要转换到新行为,您应该通过将
android.disableAutomaticComponentCreation设置为true来手动禁用自动组件创建。
有关详细信息,请参阅Use the Maven Publish plugin。
但是在文件
gradle.properties中为 AGP 8.0 默认行为启用预览时:android.disableAutomaticComponentCreation=true它找不到属性
components.release:FAILURE: Build failed with an exception. * Where: Script 'publish.gradle' line: 53 * What went wrong: A problem occurred configuring project ':library'. > Could not get unknown property 'release' for SoftwareComponentInternal set of type org.gradle.api.internal.component.DefaultSoftwareComponentContainer.offending line 内容如下:
release(MavenPublication) { from components.release }变体仍然存在,但它不再创建组件:
androidComponents { onVariants(selector().all(), { println "$it.name" }) }我怎样才能升级到这个“新的发布 DSL”并创建一个软件component来发布?
【问题讨论】:
标签: android gradle android-gradle-plugin maven-publish android-gradle-7.0