@@ -4,7 +4,9 @@ import java.net.URI
44
55plugins {
66 kotlin(" multiplatform" )
7- `maven- publish`
7+
8+ id(" maven-publish" )
9+ id(" signing" )
810}
911
1012kotlin {
@@ -103,20 +105,83 @@ tasks.withType(AbstractPublishToMaven::class).all {
103105publishing {
104106 repositories {
105107 maven {
106- name = " bintray"
107- val bintrayUsername = " hotkeytlt"
108- val bintrayRepoName = " maven"
109- val bintrayPackageName = " better-parse"
110- url = URI (
111- " https://api.bintray.com/maven/$bintrayUsername /$bintrayRepoName /$bintrayPackageName /;publish=0"
112- )
108+ name = " central"
109+ val sonatypeUsername = " h0tk3y"
110+ url = URI (" https://oss.sonatype.org/service/local/staging/deploy/maven2" )
113111
114112 credentials {
115- username = bintrayUsername
116- password = findProperty(" bintray_api_key " ) as ? String
113+ username = sonatypeUsername
114+ password = findProperty(" sonatypePassword " ) as ? String
117115 }
118116 }
119117 }
120118}
121119
120+ // Add a Javadoc JAR to each publication as required by Maven Central:
121+
122+ val javadocJar by tasks.creating(Jar ::class ) {
123+ archiveClassifier.value(" javadoc" )
124+ // TODO: instead of a single empty Javadoc JAR, generate real documentation for each module
125+ }
126+
127+ publishing {
128+ publications.withType<MavenPublication >().all {
129+ artifact(javadocJar)
130+ }
131+ }
132+
133+ fun customizeForMavenCentral (pom : org.gradle.api.publish.maven.MavenPom ) = pom.withXml {
134+ fun groovy.util.Node.add (key : String , value : String ) {
135+ appendNode(key).setValue(value)
136+ }
137+
138+ fun groovy.util.Node.node (key : String , content : groovy.util.Node .() -> Unit ) {
139+ appendNode(key).also (content)
140+ }
141+
142+ asNode().run {
143+ add(" name" , " better-parse" )
144+ add(
145+ " description" ,
146+ " A library that provides a set of parser combinator tools for building parsers and translators in Kotlin."
147+ )
148+ add(" url" , " https://github.com/h0tk3y/better-parse" )
149+ node(" organization" ) {
150+ add(" name" , " com.github.h0tk3y" )
151+ add(" url" , " https://github.com/h0tk3y" )
152+ }
153+ node(" issueManagement" ) {
154+ add(" system" , " github" )
155+ add(" url" , " https://github.com/h0tk3y/better-parse/issues" )
156+ }
157+ node(" licenses" ) {
158+ node(" license" ) {
159+ add(" name" , " Apache License 2.0" )
160+ add(" url" , " https://raw.githubusercontent.com/h0tk3y/better-parse/master/LICENSE" )
161+ add(" distribution" , " repo" )
162+ }
163+ }
164+ node(" scm" ) {
165+ add(" url" , " https://github.com/h0tk3y/better-parse" )
166+ add(" connection" , " scm:git:git://github.com/h0tk3y/better-parse" )
167+ add(" developerConnection" , " scm:git:ssh://github.com/h0tk3y/better-parse.git" )
168+ }
169+ node(" developers" ) {
170+ node(" developer" ) {
171+ add(" name" , " h0tk3y" )
172+ }
173+ }
174+ }
175+ }
176+
177+ publishing {
178+ publications.withType<MavenPublication >().all {
179+ customizeForMavenCentral(pom)
180+
181+ // Signing requires that
182+ // `signing.keyId`, `signing.password`, and `signing.secretKeyRingFile` are provided as Gradle properties
183+ signing.sign(this @all)
184+ }
185+ }
186+
122187// endregion
0 commit comments