@@ -21,9 +21,17 @@ import java.util.Base64
2121class PublicationPlugin : Plugin <Project > {
2222
2323 override fun apply (target : Project ) {
24+ val signingKeyId: String? = System .getenv(" SIGNING_KEY_ID" )
25+ val signingPassword: String? = System .getenv(" SIGNING_PASSWORD" )
26+ val signingKey: String? = System .getenv(" SIGNING_KEY" )?.let { base64Key ->
27+ String (Base64 .getDecoder().decode(base64Key))
28+ }
29+
2430 with (target.plugins) {
2531 apply (" org.gradle.maven-publish" )
26- apply (" signing" )
32+ if (signingKey != null ) {
33+ apply (" signing" )
34+ }
2735 }
2836
2937 val libraryName: String = target.requiredStringProperty(" publish.name" )
@@ -70,21 +78,17 @@ class PublicationPlugin : Plugin<Project> {
7078 }
7179 }
7280
73- target.configure<SigningExtension > {
74- val signingKeyId: String? = System .getenv(" SIGNING_KEY_ID" )
75- val signingPassword: String? = System .getenv(" SIGNING_PASSWORD" )
76- val signingKey: String? = System .getenv(" SIGNING_KEY" )?.let { base64Key ->
77- String (Base64 .getDecoder().decode(base64Key))
78- }
79-
80- if (signingKeyId != null ) {
81- useInMemoryPgpKeys(signingKeyId, signingKey, signingPassword)
82- sign(target.extensions.getByType<PublishingExtension >().publications)
83- }
81+ if (signingKey != null ) {
82+ target.configure<SigningExtension > {
83+ if (signingKeyId != null ) {
84+ useInMemoryPgpKeys(signingKeyId, signingKey, signingPassword)
85+ sign(target.extensions.getByType<PublishingExtension >().publications)
86+ }
8487
85- val signingTasks = target.tasks.withType<Sign >()
86- target.tasks.withType<AbstractPublishToMaven >().configureEach {
87- dependsOn(signingTasks)
88+ val signingTasks = target.tasks.withType<Sign >()
89+ target.tasks.withType<AbstractPublishToMaven >().configureEach {
90+ dependsOn(signingTasks)
91+ }
8892 }
8993 }
9094 }
0 commit comments