Skip to content

Instantly share code, notes, and snippets.

@Kambaa
Last active April 1, 2024 01:28
Show Gist options
  • Save Kambaa/2e7653aaea4a15233e34e499d6d673b4 to your computer and use it in GitHub Desktop.
Save Kambaa/2e7653aaea4a15233e34e499d6d673b4 to your computer and use it in GitHub Desktop.
GPG + Github Action example For Maven Publishing

GPG Generation

Read https://central.sonatype.org/publish/requirements/gpg/

Example working github actions setup for my incomplete work.

https://github.com/Kambaa/gmc-maven-plugin/blob/master/.github/workflows/maven.yml

Another axample

https://github.com/rapidappio/rapidapp-java/blob/main/.github/workflows/release.yaml

GPG Import

gpg --import private.key
# enter your password when asked

List/Export keys:

gpg --homedir C:\Users\USERNAME\.gnupg --list-keys
gpg --homedir C:\Users\USERNAME\.gnupg --export-secret-keys ENTER_KEY > private.key
gpg --homedir C:\Users\USERNAME\.gnupg --armor --export-secret-key [email protected] -w0 

Send/Receive Keys:

gpg --keyserver keyserver.ubuntu.com --send-keys <KEY>
gpg --keyserver keyserver.ubuntu.com --recv-keys <KEY>

Maven settings.xml

add this:


maven settings.xml
<!-- in servers --> 
<server>
<id>ossrh</id>
<username>SONATYPE_USERNAME</username>
<password>SONATYPE_PASSWORD</password>
</server>

or this:

  <server>
    <id>gpg.passphrase</id>
    <passphrase><GPG_PASSPHRASE></passphrase>
  </server>

in profiles section, add

    <profile>
      <id>ossrh</id>
      <activation>
      <activeByDefault>true</activeByDefault>
    </activation>
    <properties>
      <!-- for linux -->
      <gpg.executable>gpg2</gpg.executable> 
      <!-- for windows -->
      <gpg.executable>"%ProgramFiles(x86)%\GnuPG\bin\gpg.exe" --homedir "C:\Users\USERNAME\.gnupg"</gpg.executable>
      <!-- <gpg.passphrase><YOUR_PASSPHRASE></gpg.passphrase> -->
    </properties>
  </profile>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment