I have been trying to publish the library through GitHub Packages and for that I am following this Medium post: Publishing Android libraries to GitHub Packages
This is my build.gradle file:
import java.util.Properties
plugins {
id("com.android.library")
id("org.jetbrains.kotlin.android")
id("maven-publish")
}
val getVersionName = "1.0.0"
val getArtifactId = "dynamic-map"
val githubProperties = Properties()
githubProperties.load(
rootProject.file("github.properties").inputStream()
) // Load GitHub credentials from github.properties file
android {
...
}
dependencies {
...
}
afterEvaluate {
val gitUsername = githubProperties.getProperty("gpr.usr")
val gitPassword = githubProperties.getProperty("gpr.key")
println("GitHub Username: $gitUsername")
println("GitHub Token: $gitPassword")
publishing {
publications {
create<MavenPublication>("release") {
from(components["release"])
groupId = "com.gaurav.kumar"
artifactId = getArtifactId
version = getVersionName
artifact("$buildDir/outputs/aar/${getArtifactId}-release.aar")
}
}
repositories {
maven {
name = "DynamicMapRepo"
url = uri("https://maven.pkg.github.com/Cypher103360/DynamicMap")
credentials {
username = gitUsername
password = gitPassword
}
}
}
}
}
When I try to publish it through this command: ./gradlew publish, I get this:
gaurav@gaurav-ThinkPad-E15-Gen-4:~/AndroidStudioProjects/DynamicMap$ ./gradlew publish
> Configure project :dynamic-map
GitHub Username: Cypher103360
GitHub Token: *****
> Task :dynamic-map:publishReleasePublicationToDynamicMapRepoRepository FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':dynamic-map:publishReleasePublicationToDynamicMapRepoRepository'.
> Failed to publish publication 'release' to repository 'DynamicMapRepo'
> Invalid publication 'release': multiple artifacts with the identical extension and classifier ('aar', 'null').
* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
> Get more help at https://help.gradle.org.
BUILD FAILED in 1s
25 actionable tasks: 21 executed, 4 up-to-date
Can someone please help me?
The artifact was successfully published without the need for explicitly specifying the artifact file. In Maven publication, the plugin can automatically determine the artifact to be published based on the components you include in the publication.
By excluding the explicit artifact line:
This approach relies on the default behavior of the Maven publication plugin, and it seems to be working well in my case.