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:
- An initialized
fern
folder. See Set up thefern
folder. - A GitHub repository for your Java SDK. See Project structure.
- A Java generator group in
generators.yml
. See Java Quickstart.
Configure Maven Central publication
You’ll need to update your generators.yml
file to configure the output location, target repository, and publishing mode. Your generators.yml
should live in your source repository (or on your local machine), not the repository that contains your Java SDK code.
Configure output
location
In the group
for your Java SDK, 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
.
Add repository location
Add the path to the GitHub repository containing your Java SDK:
Choose your publishing mode
Optionally set the mode to control how Fern handles SDK publishing:
mode: release
(default): Fern generates code, commits to main, and tags a release automaticallymode: pull-request
: Fern generates code and creates a PR for you to review before releasemode: push
: Fern generates code and pushes to a branch you specify for you to review before release
You can also configure other settings, like the reviewers or license. Refer to the full github
(generators.yml
) reference for more information.
Set up Maven Central publishing authentication
Verify your namespace
- Click on your username, then select View Namespaces. Click Register New Namespace.
- Enter your company website or GitHub account in reverse domain name format and go through the verification process.
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.
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.
Find your key
If you already have a GPG key, you can list your keys:
If you don’t have a GPG key, you can generate a new one:
You’ll be prompted to create a new username and passphrase.
Export your key
Export your key so you can store it in an environment variable later on:
Be sure to replace YOUR_KEY_ID
with the key ID of the key you want to export.
Publish your SDK
Decide how you want to publish your SDK to Maven Central. You can use GitHub workflows for automated releases or publish directly via the CLI.
Release via a GitHub workflow
Set up a release workflow via GitHub Actions so you can trigger new SDK releases directly from your source repository.
Set up authentication
Open your source repository in GitHub. Click on the Settings tab. Then, under the Security section, open Secrets and variables > Actions.
You can also use the url https://github.com/<your-repo>/settings/secrets/actions
.
Add secret for your Fern Token
- Select New repository secret.
- Name your secret
FERN_TOKEN
. - Add your Fern token. If you don’t already have one, generate one by
running
fern token
. By default, thefern_token
is generated for the organization listed infern.config.json
. - Click Add secret.
Add secrets for Maven Central
Add the following repository secrets by selecting New repository secret for each:
MAVEN_USERNAME
- Your Maven Central usernameMAVEN_PASSWORD
- Your Maven Central passwordMAVEN_SIGNATURE_SECRET_KEY_ID
- Your GPG key IDMAVEN_SIGNATURE_PASSWORD
- Your GPG passphraseMAVEN_SIGNATURE_SECRET_KEY
- Your GPG secret key
Set up a new workflow
Set up a CI workflow that you can manually trigger from the GitHub UI. In your repository, navigate to Actions. Select New workflow, then Set up workflow yourself. Add a workflow that’s similar to this:
You can alternatively configure your workflow to execute on: [push]
.
Regenerate and release your SDK
Navigate to the Actions tab, select the workflow you just created, specify a version number, and click Run workflow. This regenerates your SDK.
The rest of the release process depends on your chosen mode:
-
Release mode (default): If you didn’t specify a
mode
or setmode: release
, no further action is required. Fern automatically tags the new release with your specified version number and initiates the publishing workflow in your SDK repository. -
Pull request or push mode: If you set
mode: pull-request
ormode: push
, Fern creates a pull request or pushes to a branch respectively. Review and merge the PR (pull-request
) or branch (push
), then tag a new release to initiate the publishing workflow in your SDK repository.
Once the workflow completes, you can view your new release by logging into Maven Central and navigating to View Deployments.
Release via CLI and environment variables
Regenerate and release your SDK
Regenerate your SDK, specifying the version:
The rest of the release process depends on your chosen mode:
-
Release mode (default): If you didn’t specify a
mode
or setmode: release
, no further action is required. Fern automatically tags the new release with your specified version number and initiates the publishing workflow in your SDK repository. -
Pull request or push mode: If you set
mode: pull-request
ormode: push
, Fern creates a pull request or pushes to a branch respectively. Review and merge the PR (pull-request
) or branch (push
), then tag a new release to initiate the publishing workflow in your SDK repository.
Once the command completes, you can view your new release by logging into Maven Central and navigating to View Deployments.