@@ -36,27 +36,41 @@ val signingSecretKeyRingFile: Provider<String> =
36
36
providers.gradleProperty(" signing.secretKeyRingFile" )
37
37
38
38
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
-
45
39
46
40
tasks.withType<AbstractPublishToMaven >().configureEach {
47
41
// Gradle warns about some signing tasks using publishing task outputs without explicit
48
42
// dependencies. I'm not going to go through them all and fix them, so here's a quick fix.
49
43
dependsOn(tasks.withType<Sign >())
50
44
45
+ doLast {
46
+ logger.lifecycle(" [${this .name} ] ${project.group} :${project.name} :${project.version} " )
47
+ }
48
+ }
49
+
50
+
51
+ signing {
51
52
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
+ }
53
58
}
59
+ }
54
60
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} " )
57
70
}
58
71
}
59
72
73
+ val javadocJarStub = javadocStubTask()
60
74
61
75
publishing {
62
76
if (sonatypeRepositoryCredentials.isPresent()) {
@@ -65,11 +79,10 @@ publishing {
65
79
name = " sonatype"
66
80
credentials(sonatypeRepositoryCredentials.get())
67
81
}
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
+ // }
73
86
}
74
87
publications.withType<MavenPublication >().configureEach {
75
88
createKxsTsGenPom()
@@ -79,29 +92,14 @@ publishing {
79
92
}
80
93
81
94
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 {
98
96
publishing.publications.withType<MavenPublication >().configureEach {
99
- artifact(javadocJarStub)
97
+ // artifact(javadocJarStub)
100
98
}
101
99
}
102
100
103
101
104
- plugins.withType( JavaPlugin :: class ).configureEach {
102
+ plugins.withType< JavaPlugin >( ).configureEach {
105
103
afterEvaluate {
106
104
if (! isKotlinMultiplatformJavaEnabled()) {
107
105
publishing.publications.create<MavenPublication >(" mavenJava" ) {
@@ -113,8 +111,30 @@ plugins.withType(JavaPlugin::class).configureEach {
113
111
}
114
112
115
113
116
- plugins.withType(JavaPlatformPlugin ::class ).configureEach {
114
+ plugins.withType<JavaPlatformPlugin >().configureEach {
115
+ // val javadocJarStub = javadocStubTask()
117
116
publishing.publications.create<MavenPublication >(" mavenJavaPlatform" ) {
118
117
from(components[" javaPlatform" ])
118
+ // artifact(javadocJarStub)
119
119
}
120
120
}
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