I am getting various kinds of error when i tried to use the following script for publishing to maven central.
import java.util.Properties
plugins {
id("org.jetbrains.kotlin.jvm")
id("maven-publish")
id("signing")
}
java {
withSourcesJar()
withJavadocJar()
toolchain.languageVersion.set(JavaLanguageVersion.of(8))
}
val POM_ARTIFACT_ID="sizeunit"
val VERSION_NAME="0.0.1"
val VERSION_CODE=1
val propsFile = File("${rootProject.rootDir.path}/a_secrets/publish.properties")
val props = if(propsFile.exists()) Properties().also { it.load(propsFile.inputStream()) } else null
val GROUP: String = props?.getProperty("GROUP")?:System.getenv("GROUP")?:""
val POM_URL: String = props?.getProperty("POM_URL")?:System.getenv("POM_URL")?:""
val POM_SCM_URL: String = props?.getProperty("POM_SCM_URL")?:System.getenv("POM_SCM_URL")?:""
val POM_SCM_CONNECTION: String = props?.getProperty("POM_SCM_CONNECTION")?:System.getenv("POM_SCM_CONNECTION")?:""
val POM_SCM_DEV_CONNECTION: String = props?.getProperty("POM_SCM_DEV_CONNECTION")?:System.getenv("POM_SCM_DEV_CONNECTION")?:""
val POM_NAME: String = props?.getProperty("POM_NAME")?:System.getenv("POM_NAME")?:""
val POM_INCEPTION_YEAR: String = props?.getProperty("POM_INCEPTION_YEAR")?:System.getenv("POM_INCEPTION_YEAR")?:""
val POM_DESCRIPTION: String = props?.getProperty("POM_DESCRIPTION")?:System.getenv("POM_DESCRIPTION")?:""
val POM_DEVELOPER_ID: String = props?.getProperty("POM_DEVELOPER_ID")?:System.getenv("POM_DEVELOPER_ID")?:""
val POM_DEVELOPER_NAME: String = props?.getProperty("POM_DEVELOPER_NAME")?:System.getenv("POM_DEVELOPER_NAME")?:""
val POM_DEVELOPER_URL: String = props?.getProperty("POM_DEVELOPER_URL")?:System.getenv("POM_DEVELOPER_URL")?:""
val POM_DEVELOPER_EMAIL: String = props?.getProperty("POM_DEVELOPER_EMAIL")?:System.getenv("POM_DEVELOPER_EMAIL")?:""
val POM_LICENSE_NAME: String = props?.getProperty("POM_LICENSE_NAME")?:System.getenv("POM_LICENSE_NAME")?:""
val POM_LICENSE_URL: String = props?.getProperty("POM_LICENSE_URL")?:System.getenv("POM_LICENSE_URL")?:""
val POM_LICENSE_DIST: String = props?.getProperty("POM_LICENSE_DIST")?:System.getenv("POM_LICENSE_DIST")?:""
val mavenCentralPassword: String = props?.getProperty("mavenCentralPassword")?:System.getenv("mavenCentralPassword")?:""
val mavenCentralUsername: String = props?.getProperty("mavenCentralUsername")?:System.getenv("mavenCentralUsername")?:""
val mavenUseSnapshotLink: Boolean = (props?.getProperty("mavenUseSnapshotLink") ?: System.getenv("mavenUseSnapshotLink") ?: "").toBoolean()
val signingPassword: String = props?.getProperty("signing.password")?:System.getenv("signing.password")?:""
val signingSecretKeyRingFile: String = props?.getProperty("signing.secretKeyRingFile")?:System.getenv("signing.secretKeyRingFile")?:""
val signingKeyId: String = props?.getProperty("signing.keyId")?:System.getenv("signing.keyId")?:""
//Configure java doc
tasks.javadoc {
if (JavaVersion.current().isJava9Compatible) {
(options as? StandardJavadocDocletOptions)?.addBooleanOption("html5", true)
}
}
afterEvaluate {
publishing {
publications {
create<MavenPublication>("mavenJava") {
groupId = GROUP
artifactId =POM_ARTIFACT_ID
version = VERSION_NAME
from(components["java"])
pom {
name.set(POM_NAME)
description.set(POM_DESCRIPTION)
url.set(POM_URL)
inceptionYear.set(POM_INCEPTION_YEAR)
licenses {
license {
name.set(POM_LICENSE_NAME)
url.set(POM_LICENSE_URL)
distribution.set(POM_LICENSE_DIST)
}
}
developers {
developer {
id.set(POM_DEVELOPER_ID)
name.set(POM_DEVELOPER_NAME)
email.set(POM_DEVELOPER_EMAIL)
url.set(POM_DEVELOPER_URL)
}
}
scm {
connection.set(POM_SCM_CONNECTION)
developerConnection.set(POM_SCM_DEV_CONNECTION)
url.set(POM_SCM_URL)
}
}
}
}
repositories {
maven {
val repoUrl = if (mavenUseSnapshotLink) "https://s01.oss.sonatype.org/content/repositories/snapshots/" else "https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/"
name = "mavenCentral"
setUrl(repoUrl)
credentials {
username = mavenCentralUsername
password = mavenCentralPassword
}
}
}
}
signing {
val signingKey = File(signingSecretKeyRingFile).readText(charset = Charsets.US_ASCII)
//setRequired { gradle.taskGraph.allTasks.any { it is PublishToMavenRepository } }
useInMemoryPgpKeys(signingKeyId,signingKey,signingPassword)
sign(publishing.publications["mavenJava"])
}
}
I can see the following tasks in my gradle task list but none seems to work .

i keep getting this error :
Execution failed for task ':sizeunit:signMavenJavaPublication'.
> Cannot perform signing task ':sizeunit:signMavenJavaPublication' because it has no configured signatory
this goes away for publishToMavenLocal task when i uncomment the setRequired { gradle.taskGraph.allTasks.any { it is PublishToMavenRepository } line, but for main task of uploading to release repository, i.e publishMavenJavaPublicationToMavenCentralRepository , it still does not work.
can someone please help? also will you consider this method of accessing all the secret data in main block in module's build.gradle.kts file as correct? or is there a better way?
PS : I checked the stack overflow answers of exact match as a google search, but those didn't worked
PS(2): the architecture of the module is a that of a typical multi module android app, but this module is supposed to be a pure java library without any dependency, so i thought that root's build.gradle or setting/gradle.kts would not be requiring any changes, but if that's the case, kindly let me know. repo link
PS(3) : would be great if i could make a generic script for both java only libs and android libs , but for now, i can work with this script getting fixed too
This is the publishing script I currently use, located at
~/.gradle/init.d/publish.gradle. It can be used to release the Java module (not tested Android):You need to adjust the relevant address to your own, and add the following system environment variables. The ZSH configuration I use is as follows:
Hope it is of help to you.