@@ -170,8 +170,14 @@ task testSourcesJar(type: Jar) {
170170 from sourceSets. test. allSource
171171}
172172
173+ task mainSourcesJar (type : Jar ) {
174+ archiveClassifier = ' sources'
175+ includes = [' **/*' ]
176+ from sourceSets. main. allSource
177+ }
178+
173179artifacts {
174- archives javadocJar, testJar, testSourcesJar
180+ archives mainSourcesJar, javadocJar, testJar, testSourcesJar
175181}
176182
177183jar {
@@ -186,8 +192,9 @@ jar {
186192publishing {
187193 repositories {
188194 maven {
189- def releasesRepoUrl = " https://oss.sonatype.org/service/local/staging/deploy/maven2/"
190- def snapshotsRepoUrl = " https://oss.sonatype.org/content/repositories/snapshots/"
195+ // https://central.sonatype.org/publish/publish-portal-ossrh-staging-api/
196+ def releasesRepoUrl = " https://ossrh-staging-api.central.sonatype.com/service/local/staging/deploy/maven2/"
197+ def snapshotsRepoUrl = " https://central.sonatype.com/repository/maven-snapshots/"
191198 url = version. endsWith(' SNAPSHOT' ) ? snapshotsRepoUrl : releasesRepoUrl
192199 credentials {
193200 username = ossrhUsername
@@ -201,6 +208,7 @@ publishing {
201208 }
202209 binaryAndSources(MavenPublication ) {
203210 from components. java
211+ artifact mainSourcesJar
204212 artifact javadocJar
205213 artifact testJar
206214 artifact testSourcesJar
@@ -332,5 +340,27 @@ task mockVault(dependsOn: "classes", type: JavaExec) {
332340task mockAll
333341mockAll. dependsOn mockVault
334342
343+ /**
344+ Maven Central publishing notification.
345+ */
346+ task postToNotifyMavenCentral {
347+ doLast {
348+ // https://central.sonatype.org/publish/publish-portal-ossrh-staging-api/#documentation-of-manual-api-endpoints
349+ // https://ossrh-staging-api.central.sonatype.com/swagger-ui/#/default/manual_upload_default_repository
350+ new URL (' https://ossrh-staging-api.central.sonatype.com/manual/upload/defaultRepository/net.gleske' ). openConnection(). with { conn ->
351+ conn. setConnectTimeout(10000 )
352+ conn. setRequestProperty(' Authorization' , ' Bearer ' + " ${ ossrhUsername} :${ ossrhPassword} " . toString(). bytes. encodeBase64(). toString())
353+ conn. setRequestMethod(' POST' )
354+ // make network request
355+ conn. getHeaderFields()
356+ }
357+ }
358+ }
359+ afterEvaluate {
360+ tasks. named(' publishBinaryAndSourcesPublicationToMavenRepository' ) {
361+ finalizedBy ' postToNotifyMavenCentral'
362+ }
363+ }
364+
335365// http://www.gradle.org/docs/current/userguide/gradle_wrapper.html
336366// generate gradlew with: ./gradlew wrapper --gradle-version 7.6
0 commit comments