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 guide assumes that you already have an initialized fern folder on your local machine. See Set up the fern folder for more details.

Set up your GitHub integration

  1. Create a new GitHub repository called company-java (or something similar) for your SDK, if you haven’t done so already.
  2. Install the Fern GitHub App: Select Configure, then scroll down to Repository Access. Select Only select repositories and in the dropdown select the repository for your SDK. Click Save.

Configure generators.yml

1

Run fern add <generator>

Navigate to your generators.yml on your local machine. Your generators.yml lives inside of your fern folder and contains all the configuration for your Fern generators.

Add a new generator to generators.yml:

$fern add fern-java-sdk --group java-sdk

Once the command completes, you’ll see a new group created in your generators.yml:

1 groups:
2 java-sdk:
3 generators:
4 - name: fernapi/fern-java-sdk
5 version: 2.39.0
6 output:
7 location: local-file-system
8 path: ../sdks/java/src/main/java/
2

Configure output location

Next, 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:

1groups:
2 java-sdk:
3 generators:
4 - name: fernapi/fern-java-sdk
5 version: 2.39.0
6 output:
7 location: maven
3

Configure Maven Coordinate

Add the coordinate: groupId:artifactId field to specify how your Java SDK will be published and referenced in the Central Maven respository.

1groups:
2 java-sdk:
3 generators:
4 - name: fernapi/fern-java-sdk
5 version: 2.39.0
6 output:
7 location: maven
8 coordinate: com.company:sdk-name #<company name in reverse domain name format>:<SDK name>
4

Add repository location

Add the path to your GitHub repository to generators.yml:

1groups:
2 java-sdk:
3 generators:
4 - name: fernapi/fern-java-sdk
5 version: 2.39.0
6 output:
7 location: maven
8 coordinate: com.company:sdk-name
9 github:
10 repository: your-org/company-java

Set up Maven Central publishing authentication via the Central Portal

1

Log into Maven Central

Log into Maven Central or create a new account.

2

Generate user tokens

  1. 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.
3

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.

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

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. To export your secret key, run:

    1gpg --export-secret-keys --armor KEY_ID

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

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

Configure GPG Signature

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

1groups:
2 java-sdk:
3 generators:
4 - name: fernapi/fern-java-sdk
5 version: 2.39.0
6 output:
7 location: maven
8 coordinate: com.company:sdk-name
9 username: ${MAVEN_USERNAME}
10 password: ${MAVEN_PASSWORD}
11 signature:
12 keyId: ${MAVEN_CENTRAL_SECRET_KEY_KEY_ID}
13 password: ${MAVEN_CENTRAL_SECRET_KEY_PASSWORD}
14 secretKey: ${MAVEN_CENTRAL_SECRET_KEY}
15 github:
16 repository: your-org/company-java

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_CENTRAL_SECRET_KEY_KEY_ID=your-gpg-key-id
>export MAVEN_CENTRAL_SECRET_KEY_PASSWORD=your-gpg-passphrase
>export MAVEN_CENTRAL_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.