With Gradle 7.2
and these plugins:
plugins {
id 'com.android.library' // Android Gradle Plugin 7.1.2
id 'maven-publish'
}
It still works, but gives me this deprecation warning:
WARNING: Software Components will not be created automatically for Maven publishing from Android Gradle Plugin 8.0. To opt-in to the future behavior, set the Gradle property
android.disableAutomaticComponentCreation=true
in thegradle.properties
file or use the new publishing DSL.
Also the release notes mention it, but these refer to outdated documentation:
Starting AGP 8.0, automatic component creation will be disabled by default. Currently, AGP 7.1 automatically creates a component for each build variant, which has the same name as the build variant, and an an all component that contains all the build variants. This automatic component creation will be disabled. To transition to the new behavior, you should manually disable automatic component creation by setting
android.disableAutomaticComponentCreation
totrue
.
For more information, see Use the Maven Publish plugin.
But when enabling preview for the AGP 8.0 default behavior in file gradle.properties
:
android.disableAutomaticComponentCreation=true
It cannot find property 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.
The offending line reads:
release(MavenPublication) {
from components.release
}
The variant is is still there, but it doesn't create a component anymore:
androidComponents {
onVariants(selector().all(), {
println "$it.name"
})
}
How can I upgrade to this "new publishing DSL" and create a software component to publish?
CodePudding user response:
According to PublishingOptions
, one has to define an android.publishing
block:
android {
publishing {
singleVariant('release') {
withSourcesJar()
withJavadocJar()
}
// ...
}
}
To define multiple variants at once:
android {
publishing {
multipleVariants {
withSourcesJar()
withJavadocJar()
allVariants()
}
}
}
Then eg. components.getByName('release')
will be known again.