Sorry if this often repeated question but I could not find answer to my question. I have an Android project with certain number of library modules (subprojects). I need to publish the library from each one of those modules. Instead of duplicating the publishing code in subproject/module gradle file I want to place this code in root project file like:
subprojects {
plugins.apply("maven-publish") // <-- GETTING ERROR HERE
configure<PublishingExtension> {
publications {
create<MavenPublication>("aar") {
from(components["release"])
groupId = "com.example"
version = "1.0.0"
artifactId = project.name // Default to project name, can be overridden
}
}
repositories {
mavenLocal()
}
}
}
However, I get this error from the line marked above. I am using gradle version 8.3.
Failed to apply plugin class ‘org.gradle.api.publish.plugins.PublishingPlugin’.
Cannot run Project.afterEvaluate(Action) when the project is already evaluated.
How can I get this addressed and have publishing from common (root) gradle file?