@@ -36,27 +36,41 @@ val signingSecretKeyRingFile: Provider<String> =
3636 providers.gradleProperty(" signing.secretKeyRingFile" )
3737
3838
39- val javadocJarStub by tasks.registering(Jar ::class ) {
40- group = JavaBasePlugin .DOCUMENTATION_GROUP
41- description = " Stub javadoc.jar artifact (required by Maven Central)"
42- archiveClassifier.set(" javadoc" )
43- }
44-
4539
4640tasks.withType<AbstractPublishToMaven >().configureEach {
4741 // Gradle warns about some signing tasks using publishing task outputs without explicit
4842 // dependencies. I'm not going to go through them all and fix them, so here's a quick fix.
4943 dependsOn(tasks.withType<Sign >())
5044
45+ doLast {
46+ logger.lifecycle(" [${this .name} ] ${project.group} :${project.name} :${project.version} " )
47+ }
48+ }
49+
50+
51+ signing {
5152 if (sonatypeRepositoryCredentials.isPresent()) {
52- dependsOn(javadocJarStub)
53+ if (signingKeyId.isPresent() && signingKey.isPresent() && signingPassword.isPresent()) {
54+ useInMemoryPgpKeys(signingKeyId.get(), signingKey.get(), signingPassword.get())
55+ } else {
56+ useGpgCmd()
57+ }
5358 }
59+ }
5460
55- doLast {
56- logger.lifecycle(" [${this .name} ] ${project.group} :${project.name} :${project.version} " )
61+
62+ afterEvaluate {
63+ // Register signatures afterEvaluate, otherwise the signing plugin creates the signing tasks
64+ // too early, before all the publications are added.
65+ // Use .all { }, not .configureEach { }, otherwise the signing plugin doesn't create the tasks
66+ // soon enough.
67+ publishing.publications.withType<MavenPublication >().all {
68+ signing.sign(this )
69+ logger.lifecycle(" configuring signature for publication ${this .name} " )
5770 }
5871}
5972
73+ val javadocJarStub = javadocStubTask()
6074
6175publishing {
6276 if (sonatypeRepositoryCredentials.isPresent()) {
@@ -65,11 +79,10 @@ publishing {
6579 name = " sonatype"
6680 credentials(sonatypeRepositoryCredentials.get())
6781 }
68- // publish to local dir, for testing
69- // maven {
70- // name = "maven-internal"
71- // url = uri(rootProject.layout.buildDirectory.dir("maven-internal"))
72- // }
82+ // // publish to local dir, for testing
83+ // maven(rootProject.layout.buildDirectory.dir("maven-internal")) {
84+ // name = "maven-internal"
85+ // }
7386 }
7487 publications.withType<MavenPublication >().configureEach {
7588 createKxsTsGenPom()
@@ -79,29 +92,14 @@ publishing {
7992}
8093
8194
82- signing {
83- if (sonatypeRepositoryCredentials.isPresent()) {
84- if (signingKeyId.isPresent() && signingKey.isPresent() && signingPassword.isPresent()) {
85- useInMemoryPgpKeys(signingKeyId.get(), signingKey.get(), signingPassword.get())
86- } else {
87- useGpgCmd()
88- }
89-
90- // sign all publications
91- sign(publishing.publications)
92- sign(javadocJarStub.get())
93- }
94- }
95-
96-
97- plugins.withType(KotlinMultiplatformPlugin ::class ).configureEach {
95+ plugins.withType<KotlinMultiplatformPlugin >().configureEach {
9896 publishing.publications.withType<MavenPublication >().configureEach {
99- artifact(javadocJarStub)
97+ // artifact(javadocJarStub)
10098 }
10199}
102100
103101
104- plugins.withType( JavaPlugin :: class ).configureEach {
102+ plugins.withType< JavaPlugin >( ).configureEach {
105103 afterEvaluate {
106104 if (! isKotlinMultiplatformJavaEnabled()) {
107105 publishing.publications.create<MavenPublication >(" mavenJava" ) {
@@ -113,8 +111,30 @@ plugins.withType(JavaPlugin::class).configureEach {
113111}
114112
115113
116- plugins.withType(JavaPlatformPlugin ::class ).configureEach {
114+ plugins.withType<JavaPlatformPlugin >().configureEach {
115+ // val javadocJarStub = javadocStubTask()
117116 publishing.publications.create<MavenPublication >(" mavenJavaPlatform" ) {
118117 from(components[" javaPlatform" ])
118+ // artifact(javadocJarStub)
119119 }
120120}
121+
122+
123+ fun Project.javadocStubTask (): Jar {
124+
125+ // use creating, not registering, because the signing plugin sucks
126+ val javadocJarStub by tasks.creating(Jar ::class ) {
127+ group = JavaBasePlugin .DOCUMENTATION_GROUP
128+ description = " Stub javadoc.jar artifact (required by Maven Central)"
129+ archiveClassifier.set(" javadoc" )
130+ }
131+
132+ val signingTasks = signing.sign(javadocJarStub)
133+
134+ tasks.withType<AbstractPublishToMaven >().all {
135+ dependsOn(javadocJarStub)
136+ signingTasks.forEach { dependsOn(it) }
137+ }
138+
139+ return javadocJarStub
140+ }
0 commit comments