title: Signing fails when trying to publish to Maven Central using Sonatype nexus (gradle-nexus.publish-plugin)
body: <p>I'm trying to publish my library to Maven Central. I already set it up over at Sonatype Nexus, and now I'm trying to hook up Gradle to it (this library depends on Minecraft Forge, so using Maven isn't an option).</p>
  <p>I saw that there was a plugin created called <a href="https://github.com/gradle-nexus/publish-plugin" rel="nofollow noreferrer">Gradle Nexus Publish Plugin</a> and thought I could use it to make publishing easier.</p>
  <p>Using the <code>publishAllPublicationsToSonatypeRepository</code> Gradle task, I could publish a repo to Nexus;
  But once I call <code>closeSonatypeStagingRepository</code>, it fails with the following error:</p>
  <pre><code>Execution failed for task ':signMavenPublication'.
  &gt; Could not read PGP secret key
  
  Cause: premature end of stream in PartialInputStream
  </code></pre>
  <p>Now, I added a <code>println</code> to see what key Gradle reads from <code>signingKey</code>, and turns out that no matter what I put there, it always retrieves the same key, even if I put in an invalid key (this is an altered key):</p>
  <pre><code>lQWGBGByDfwBDADB5pWxgBT04U0bDIv/Pv0zDEYqKXt2Dubj3RcvCDAveel3eYFt
  </code></pre>
  <p>(The password is being updated though)</p>
  <p>Why is this happening?</p>
  <p>This is my <code>build.gradle.kts</code>:</p>
  <pre><code>import net.minecraftforge.gradle.common.util.ModConfig
  import net.minecraftforge.gradle.common.util.RunConfig
  import net.minecraftforge.gradle.userdev.UserDevExtension
  import java.time.Instant
  import java.time.format.DateTimeFormatter
  
  // BuildScript
  buildscript {
      repositories {
          maven(url = &quot;https://maven.minecraftforge.net/&quot;)
          jcenter()
          mavenCentral()
      }
  
      dependencies {
          classpath(group = &quot;net.minecraftforge.gradle&quot;, name = &quot;ForgeGradle&quot;, version = &quot;4.1.+&quot;)
      }
  }
  
  plugins {
      idea
      id(&quot;io.github.gradle-nexus.publish-plugin&quot;) version &quot;1.0.0&quot;
      `java-library`
      `maven-publish`
      signing
      kotlin(&quot;jvm&quot;) version &quot;1.5.0&quot;
  }
  apply(plugin = &quot;net.minecraftforge.gradle&quot;)
  
  // Config -&gt; Minecraft
  val forgeVersion: String by extra
  val minecraftVersion: String by extra
  val kffVersion: String by extra
  val modVersion: String by extra
  
  // JVM Info
  println(
      &quot;&quot;&quot;
          Java: ${System.getProperty(&quot;java.version&quot;)} 
          JVM: ${System.getProperty(&quot;java.vm.version&quot;)} (${System.getProperty(&quot;java.vendor&quot;)}) 
          Arch: ${System.getProperty(&quot;os.arch&quot;)}
      &quot;&quot;&quot;.trimIndent()
  )
  
  // Minecraft
  configure&lt;UserDevExtension&gt; {
      mappings(&quot;official&quot;, minecraftVersion)
  
      @Suppress(&quot;SpellCheckingInspection&quot;)
      accessTransformer(file(&quot;src/main/resources/META-INF/accesstransformer.cfg&quot;))
  
      runs(closureOf&lt;NamedDomainObjectContainer&lt;RunConfig&gt;&gt; {
          create(&quot;client&quot;) {
              workingDirectory(file(&quot;run&quot;))
  
              taskName = &quot;client&quot;
  
              // Recommended logging data for a userdev environment
              property(&quot;forge.logging.markers&quot;, &quot;SCAN,REGISTRIES,REGISTRYDUMP&quot;)
  
              // Recommended logging level for the console
              property(&quot;forge.logging.console.level&quot;, &quot;debug&quot;)
  
              mods(closureOf&lt;NamedDomainObjectContainer&lt;ModConfig&gt;&gt; {
                  create(&quot;loottables&quot;) {
                      source(sourceSets[&quot;main&quot;])
                  }
              })
          }
  
          create(&quot;server&quot;) {
              workingDirectory(file(&quot;run&quot;))
  
              taskName = &quot;server&quot;
  
              // Recommended logging data for a userdev environment
              property(&quot;forge.logging.markers&quot;, &quot;SCAN,REGISTRIES,REGISTRYDUMP&quot;)
  
              // Recommended logging level for the console
              property(&quot;forge.logging.console.level&quot;, &quot;debug&quot;)
  
              mods(closureOf&lt;NamedDomainObjectContainer&lt;ModConfig&gt;&gt; {
                  create(&quot;loottables&quot;) {
                      source(sourceSets[&quot;main&quot;])
                  }
              })
          }
  
          create(&quot;data&quot;) {
              workingDirectory(file(&quot;run&quot;))
  
              taskName = &quot;datagen&quot;
  
              // Recommended logging data for a userdev environment
              property(&quot;forge.logging.markers&quot;, &quot;SCAN,REGISTRIES,REGISTRYDUMP&quot;)
  
              // Recommended logging level for the console
              property(&quot;forge.logging.console.level&quot;, &quot;debug&quot;)
  
              // Specify the mod id for data generation, where to output the resulting resource, and where to look for existing resources.
              args(
                  &quot;--mod&quot;,
                  &quot;loottables&quot;,
                  &quot;--all&quot;,
                  &quot;--output&quot;,
                  file(&quot;src/generated/resources/&quot;),
                  &quot;--existing&quot;,
                  file(&quot;src/main/resources/&quot;)
              )
  
              mods(closureOf&lt;NamedDomainObjectContainer&lt;ModConfig&gt;&gt; {
                  create(&quot;loottables&quot;) {
                      source(sourceSets[&quot;main&quot;])
                  }
              })
          }
      })
  }
  
  // Minecraft Dependency
  // Note: Due to the way kotlin gradle works we need to define the minecraft dependency after we configure Minecraft
  dependencies {
      &quot;minecraft&quot;(group = &quot;net.minecraftforge&quot;, name = &quot;forge&quot;, version = &quot;$minecraftVersion-$forgeVersion&quot;)
      implementation(group = &quot;thedarkcolour&quot;, name = &quot;kotlinforforge&quot;, version = &quot;latest.release&quot;)
      testImplementation(
          group = &quot;org.jetbrains.kotlin&quot;,
          name = &quot;kotlin-test-junit5&quot;,
          version = kotlin.coreLibrariesVersion
      )
  }
  
  repositories {
      maven {
          name = &quot;kotlinforforge&quot;
          url = uri(&quot;https://thedarkcolour.github.io/KotlinForForge/&quot;)
      }
  }
  
  // Setup
  project.group = &quot;com.theonlytails&quot;
  project.version = modVersion
  base.archivesBaseName = &quot;loottables&quot;
  
  // Sets the toolchain to compile against OpenJDK 8
  java {
      toolchain {
          languageVersion.set(JavaLanguageVersion.of(8))
          vendor.set(JvmVendorSpec.ADOPTOPENJDK)
      }
  }
  
  // Finalize the jar by re-obfuscating
  tasks.named&lt;Jar&gt;(&quot;jar&quot;) {
      // Manifest
      manifest {
          attributes(
              &quot;Specification-Title&quot; to &quot;LootTables&quot;,
              &quot;Specification-Vendor&quot; to &quot;TheOnlyTails&quot;,
              &quot;Specification-Version&quot; to &quot;1&quot;,
              &quot;Implementation-Title&quot; to &quot;LootTables&quot;,
              &quot;Implementation-Version&quot; to project.version,
              &quot;Implementation-Vendor&quot; to &quot;TheOnlyTails&quot;,
              &quot;Implementation-Timestamp&quot; to DateTimeFormatter.ISO_INSTANT.format(Instant.now()),
              &quot;FMLModType&quot; to &quot;LIBRARY&quot;
          )
      }
  
      @Suppress(&quot;SpellCheckingInspection&quot;)
      finalizedBy(&quot;reobfJar&quot;)
  }
  
  // Publishing to maven central
  publishing {
      publications {
          create&lt;MavenPublication&gt;(&quot;maven&quot;) {
              groupId = &quot;com.theonlytails&quot;
              artifactId = &quot;loottables&quot;
              version = modVersion
  
              from(components[&quot;java&quot;])
  
              pom {
                  name.set(&quot;LootTables&quot;)
                  description.set(&quot;A Kotlin DSL for creating loot tables in Minecraft Forge mods&quot;)
                  url.set(&quot;https://github.com/theonlytails/loottables&quot;)
  
                  properties.set(mapOf(&quot;project.build.sourceEncoding&quot; to &quot;UTF-8&quot;))
  
                  licenses {
                      license {
                          name.set(&quot;MIT License&quot;)
                          url.set(&quot;https://www.opensource.org/licenses/mit-license.php&quot;)
                          distribution.set(&quot;repo&quot;)
                      }
                  }
  
                  developers {
                      developer {
                          id.set(&quot;theonlytails&quot;)
                          name.set(&quot;TheOnlyTails&quot;)
                          url.set(&quot;https://theonlytails.com/&quot;)
                      }
                  }
  
                  issueManagement {
                      url.set(&quot;https://github.com/theonlytails/loottables/issues&quot;)
                      system.set(&quot;GitHub Issues&quot;)
                  }
  
                  scm {
                      connection.set(&quot;scm:git:git:github.com/theonlytails/loottables.git&quot;)
                      developerConnection.set(&quot;scm:git:git@github.com:theonlytails/loottables.git&quot;)
                      url.set(&quot;https://github.com/theonlytails/loottables&quot;)
                  }
              }
          }
      }
  }
  
  java {
      withJavadocJar()
      withSourcesJar()
  }
  
  signing {
      val signingPassword: String? by extra
      val signingKey: String? by extra
  
      println(signingKey) // this is for debbuging purposes only, I'm obviously going to remove this once done
      println(signingPassword)
  
      useInMemoryPgpKeys(
          signingKey ?: throw GradleException(&quot;Couldn't find a signing password&quot;),
          signingPassword ?: throw GradleException(&quot;Couldn't find a signing key&quot;)
      )
  
      sign(publishing.publications[&quot;maven&quot;])
  }
  
  nexusPublishing {
      repositories {
          sonatype {
              nexusUrl.set(uri(&quot;https://s01.oss.sonatype.org/service/local/&quot;))
              snapshotRepositoryUrl.set(uri(&quot;https://s01.oss.sonatype.org/content/repositories/snapshots/&quot;))
  
              username.set(System.getenv(&quot;MAVEN_USERNAME&quot;))
              password.set(System.getenv(&quot;MAVEN_PASSWORD&quot;))
          }
      }
  }
  
  // Testing
  tasks.withType&lt;Test&gt; {
      useJUnitPlatform()
  }
  </code></pre>