Issue
I am trying to upload my first android library to Maven Central, but there is no proper documentation for Gradle 7.2.0 after some research I found some links but they are outdated too.
Things I have done till now:
- registered on jira
- approved my project on it and got access to nexus repository manager
- generated gpg key
now comes configuring the gradle file: so i have followed this library = https://github.com/vanniktech/gradle-maven-publish-plugin
- in project root build.gradle file i have mentioned
buildscript {
dependencies {
classpath 'com.vanniktech:gradle-maven-publish-plugin:0.20.0' // NEW
classpath 'org.jetbrains.dokka:dokka-gradle-plugin:1.4.10.2' // NEW
}
}
- in library build.gradle i have added this plugin
plugins {
id 'com.android.library'
id 'org.jetbrains.kotlin.android'
id 'com.vanniktech.maven.publish' // NEW
}
- in project root gradle.properties i have written this
SONATYPE_HOST=S01
RELEASE_SIGNING_ENABLED=true
GROUP=io.github.Darkprnce
POM_ARTIFACT_ID=InnerDrawer
VERSION_NAME=1.0.0
POM_NAME=InnerDrawer
POM_PACKAGING=aar
POM_DESCRIPTION=Inner Drawer is a highly customizable navigation drawer.
POM_INCEPTION_YEAR=2022
POM_URL=https://github.com/Darkprnce/InnerDrawer
POM_SCM_URL=https://github.com/Darkprnce/InnerDrawer
POM_SCM_CONNECTION=scm:[email protected]:Darkprnce/InnerDrawer.git
POM_SCM_DEV_CONNECTION=scm:[email protected]:Darkprnce/InnerDrawer.git
POM_LICENCE_NAME=MIT License
POM_LICENCE_URL=http://www.opensource.org/licenses/mit-license.php
POM_LICENCE_DIST=repo
POM_DEVELOPER_ID=Darkprnce
POM_DEVELOPER_NAME=Tarun Yadvendu
POM_DEVELOPER_URL=https://github.com/Darkprnce
signing.keyId=FCF8EDCA
signing.password=[my signing password]
signing.secretKeyRingFile=secret-keys.gpg
ossrhUsername=[my username]
ossrhPassword=[my password]
- then again in library build.gradle i have mentioned publishing code
publishing {
repositories {
maven {
url = "https://s01.oss.sonatype.org/service/local/staging/deploy/maven2"
credentials {
username = ossrhUsername
password = ossrhPassword
}
}
}
}
now comes the issue when i run this command in terminal it gives wrong credentials error
* What went wrong:
Credentials required for this build could not be resolved.
> The following Gradle properties are missing for 'mavenCentral' credentials:
- mavenCentralUsername
- mavenCentralPassword
so if anyone has used this library then help me in this, library is well maintained so no issues in that i only want to know the right way to upload.
Solution
After akarnokd help i was able to upload my library to Maven Central. Step i have taken to resolve this issue:
- First i have renamed the properties in project root => gradle.properties
ossrhUsername=[my username] ==> mavenCentralUsername ossrhPassword=[my password] ==> mavenCentralPassword
- Now the above information is available to everyone, as we have just mention our username and password in a gradle file which will be uploaded with the code. so to prevent that, akarnokd suggested me to create a new gradle.properties file in C:/users/darkprnce/.gradle/gradle.properties and place the below information in that file :
mavenCentralUsername=[my username]
mavenCentralPassword=[my password]
signing.keyId=[last 8 digit of your key]
signing.password=[signing password]
signing.secretKeyRingFile=secring.gpg
we can remove publishing from library build.gradle file as it is already included in library.
run command
./gradlew publish --no-daemon --no-parallel
It will upload the library to Maven Central, then you can close the repository and release it.
Answered By - Tarun Yadvendu
Answer Checked By - David Marino (JavaFixing Volunteer)