Publishing to Maven Central

Publish your public-facing Fern Java SDK to the Maven Central registry. After following the steps on this page, you’ll have a versioned package published on Maven Central.

This page assumes that you have:

Configure generators.yml

1

Configure output location

Change the output location in generators.yml from local-file-system (the default) to maven to indicate that Fern should publish your package directly to the Maven Central registry.

Then, add publish-to: central to indicate that the publish target is the new Maven Central Portal (Sonatype). To publish to the legacy Nexus Repository, use publish-to: ossrh.

generators.yml
1groups:
2 java-sdk:
3 generators:
4 - name: fernapi/fern-java-sdk
5 version: 2.43.1
6 output:
7 location: maven
8 config:
9 publish-to: central
2

Add repository location

Add the path to your GitHub repository.

generators.yml
1groups:
2 java-sdk:
3 generators:
4 - name: fernapi/fern-java-sdk
5 version: 2.43.1
6 output:
7 location: maven
8 config:
9 publish-to: central
10 github:
11 repository: your-org/company-java

Set up Maven Central publishing authentication

1

Log into Maven Central

Log into Maven Central or create a new account.

2

Verify your namespace

  1. Click on your username, then select View Namespaces. Click Register New Namespace.
  2. Enter your company website or GitHub account in reverse domain name format and go through the verification process.
3

Configure Maven Coordinate

Add the namespace you just verified in Maven Central to the coordinate field. This specifies how your Java SDK will be published and referenced in the Maven Central respository.

generators.yml
1groups:
2 java-sdk:
3 generators:
4 - name: fernapi/fern-java-sdk
5 version: 2.43.1
6 output:
7 location: maven
8 coordinate: com.company:sdk-name # groupId:artifactId
9 config:
10 publish-to: central
11 github:
12 repository: your-org/company-java
4

Generate user tokens

  1. Back in Maven Central, click on your username, then select View Account

  2. Click on Generate User Token, then click Ok to confirm generation. This will invalidate any existing token.

    Save your username and password tokens – they won’t be displayed after you leave the page.
5

Configure Maven Central authentication token

Add username: ${MAVEN_USERNAME} and password: ${MAVEN_PASSWORD} to generators.yml to tell Fern to use the MAVEN_USERNAME and MAVEN_PASSWORD environment variable for authentication when publishing to the Maven Central registry.

generators.yml
1groups:
2 java-sdk:
3 generators:
4 - name: fernapi/fern-java-sdk
5 version: 2.43.1
6 output:
7 location: maven
8 coordinate: com.company:sdk-name
9 username: ${MAVEN_USERNAME}
10 password: ${MAVEN_PASSWORD}
11 config:
12 publish-to: central
13 github:
14 repository: your-org/company-java

Generate GPG Signature

Next, set up code signing credentials by generating or identifying a GPG key ID, password, and secret key. Maven Central requires all artifacts to be digitally signed with PGP/GPG keys.

If you don’t have gpg installed, you can download the binary from https://gnupg.org/download/index.html, or install it via package manager.
1

Find your key

If you already have a GPG key, you can list your keys:

1gpg --list-secret-keys --keyid-format LONG

If you don’t have a GPG key, you can generate a new one:

1gpg --gen-key

You’ll be prompted to create a new username and passphrase.

2

Export your key

Export your key so you can store it in an environment variable later on:

1gpg --export-secret-keys --armor YOUR_KEY_ID

Be sure to replace YOUR_KEY_ID with the key ID of the key you want to export.

More information is available on Maven Central’s GPG validation page.
3

Configure GPG Signature

Add the keyId, password, and secretKey from the previous step to generators.yml:

generators.yml
1groups:
2 java-sdk:
3 generators:
4 - name: fernapi/fern-java-sdk
5 version: 2.43.1
6 output:
7 location: maven
8 coordinate: com.company:sdk-name
9 username: ${MAVEN_USERNAME}
10 password: ${MAVEN_PASSWORD}
11 signature:
12 keyId: ${MAVEN_SIGNATURE_SECRET_KEY_ID}
13 password: ${MAVEN_SIGNATURE_PASSWORD}
14 secretKey: ${MAVEN_SIGNATURE_SECRET_KEY}
15 config:
16 publish-to: central
17 github:
18 repository: your-org/company-java
4

Upload your key to public key servers

Finally, upload your key to public key servers so Maven Central can access the signature:

$# Upload to multiple key servers
>gpg --keyserver keyserver.ubuntu.com --send-keys YOUR_KEY_ID
>gpg --keyserver keys.openpgp.org --send-keys YOUR_KEY_ID
>gpg --keyserver pgp.mit.edu --send-keys YOUR_KEY_ID

Release your SDK to Maven Central

At this point, you’re ready to generate a release for your SDK.

1

Set Maven environment variables

On your local machine, set the the following environment variable to the various tokens you generated in previous steps:

$export MAVEN_USERNAME=your-maven-username
>export MAVEN_PASSWORD=your-maven-password
>export MAVEN_SIGNATURE_SECRET_KEY_ID=your-gpg-key-id
>export MAVEN_SIGNATURE_PASSWORD=your-gpg-passphrase
>export MAVEN_SIGNATURE_SECRET_KEY=your-gpg-secret-key
2

Generate your release

Regenerate your SDK and publish it on Maven Central:

$fern generate --group java-sdk --version <version>

Local machine output will verify that the release is pushed to your repository and tagged with the version you specified. Log back into Maven Central and navigate to View Deployments to see your new release.