Skip to content

Commit 77ae226

Browse files
authored
Add Maven Central Publishing Guide (#49)
1 parent e59ec70 commit 77ae226

File tree

1 file changed

+226
-2
lines changed

1 file changed

+226
-2
lines changed

fern/products/sdks/overview/java/publishing-to-maven-central.mdx

Lines changed: 226 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,230 @@ title: Publishing to Maven Central
33
description: How to publish the Fern Java SDK to Maven Central.
44
---
55

6-
Learn how to publish your Fern Java SDK to the Maven Central registry.
6+
Publish your public-facing Fern Java SDK to the [Maven Central
7+
registry](https://pypi.org/). After following the steps on this page,
8+
you'll have a versioned package published on Maven Central.
79

8-
<Warning>This page is a WIP, please refer to our previous [documentation](https://buildwithfern.com/learn/sdks/guides/publish-a-public-facing-sdk).</Warning>
10+
<Info>This guide assumes that you already have an initialized `fern` folder on your local machine. If you don’t, run `fern init`. See [Java Quickstart](quickstart.mdx) for more details.</Info>
11+
12+
## Set up your GitHub integration
13+
14+
1. Create a new GitHub repository called `company-java` (or something similar) for your SDK, if you haven't done so already.
15+
1. Install the [Fern GitHub App](https://github.com/apps/fern-api): Select **Configure**, then scroll down to **Repository Access**. Select **Only select repositories** and in the dropdown select the repository for your SDK. Click **Save**.
16+
17+
18+
## Configure `generators.yml`
19+
20+
<Steps>
21+
22+
<Step title="Run `fern add <generator>`">
23+
24+
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.
25+
26+
Add a new generator to `generators.yml`:
27+
28+
29+
```bash
30+
fern add fern-java-sdk --group java-sdk
31+
```
32+
33+
Once the command completes, you'll see a new group created in your `generators.yml`:
34+
35+
```yaml {2-8}
36+
groups:
37+
java-sdk:
38+
generators:
39+
- name: fernapi/fern-java-sdk
40+
version: <Markdown src="/snippets/version-number.mdx"/>
41+
output:
42+
location: local-file-system
43+
path: ../sdks/java/src/main/java/
44+
```
45+
46+
</Step>
47+
48+
<Step title="Configure `output` location">
49+
50+
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:
51+
52+
```yaml {6-7}
53+
groups:
54+
java-sdk:
55+
generators:
56+
- name: fernapi/fern-java-sdk
57+
version: <Markdown src="/snippets/version-number.mdx"/>
58+
output:
59+
location: maven
60+
61+
```
62+
</Step>
63+
64+
<Step title="Configure Maven Coordinate">
65+
66+
Add the `coordinate: groupId:artifactId` field to specify how your Java
67+
SDK will be published and referenced in the Central Maven respository.
68+
69+
```yaml {8}
70+
groups:
71+
java-sdk:
72+
generators:
73+
- name: fernapi/fern-java-sdk
74+
version: <Markdown src="/snippets/version-number.mdx"/>
75+
output:
76+
location: maven
77+
coordinate: com.company:sdk-name #<company name in reverse domain name format>:<SDK name>
78+
```
79+
80+
</Step>
81+
82+
83+
<Step title="Add repository location">
84+
85+
Add the path to your GitHub repository to `generators.yml`:
86+
87+
```yaml {9-10}
88+
groups:
89+
java-sdk:
90+
generators:
91+
- name: fernapi/fern-java-sdk
92+
version: <Markdown src="/snippets/version-number.mdx"/>
93+
output:
94+
location: maven
95+
coordinate: com.company:sdk-name
96+
github:
97+
repository: your-org/company-java
98+
```
99+
100+
</Step>
101+
</Steps>
102+
103+
## Set up Maven Central publishing authentication via the Central Portal
104+
105+
<Steps>
106+
107+
<Step title="Log into Maven Central">
108+
109+
Log into [Maven Central](https://pypi.org/) or create a new account.
110+
111+
</Step>
112+
113+
<Step title="Generate user tokens">
114+
115+
1. Click on your username, then select **View Account**
116+
1. Click on **Generate User Token**, then click **Ok** to confirm
117+
generation. This will invalidate any existing token.
118+
119+
<Warning>Save your username and password tokens – they won’t be displayed after you leave the page.</Warning>
120+
121+
</Step>
122+
123+
124+
<Step title="Configure Maven Central authentication token">
125+
126+
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.
127+
128+
```yaml {9-10}
129+
groups:
130+
java-sdk:
131+
generators:
132+
- name: fernapi/fern-java-sdk
133+
version: <Markdown src="/snippets/version-number.mdx"/>
134+
output:
135+
location: maven
136+
coordinate: com.company:sdk-name
137+
username: ${MAVEN_USERNAME}
138+
password: ${MAVEN_PASSWORD}
139+
github:
140+
repository: your-org/company-java
141+
```
142+
</Step>
143+
144+
<Step title="Generate GPG Signature">
145+
146+
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.
147+
148+
<Info>If you don't have gpg installed, you can download the binary from [https://gnupg.org/download/index.html](https://gnupg.org/download/index.html), or install it via package manager.</Info>
149+
150+
1. Find your key
151+
* If you already have a GPG key, you can list your keys:
152+
153+
```sh
154+
gpg --list-secret-keys --keyid-format LONG
155+
```
156+
157+
* If you don't have a GPG key, you can generate a new one:
158+
159+
```sh
160+
gpg --gen-key
161+
```
162+
163+
You'll be prompted to create a new username and passphrase.
164+
165+
1. To export your secret key, run:
166+
167+
```sh
168+
gpg --export-secret-keys --armor KEY_ID
169+
```
170+
171+
Be sure to replace `KEY_ID` with the key ID of the key you want to export.
172+
173+
<Info>More information is available on [Maven Central's GPG validation page](https://central.sonatype.org/publish/requirements/gpg/).</Info>
174+
</Step>
175+
<Step title="Configure GPG Signature">
176+
177+
Add the `keyId`, `password`, and `secretKey` from the previous step to `generators.yml`:
178+
179+
```yaml {11-14}
180+
groups:
181+
java-sdk:
182+
generators:
183+
- name: fernapi/fern-java-sdk
184+
version: <Markdown src="/snippets/version-number.mdx"/>
185+
output:
186+
location: maven
187+
coordinate: com.company:sdk-name
188+
username: ${MAVEN_USERNAME}
189+
password: ${MAVEN_PASSWORD}
190+
signature:
191+
keyId: ${MAVEN_CENTRAL_SECRET_KEY_KEY_ID}
192+
password: ${MAVEN_CENTRAL_SECRET_KEY_PASSWORD}
193+
secretKey: ${MAVEN_CENTRAL_SECRET_KEY}
194+
github:
195+
repository: your-org/company-java
196+
```
197+
</Step>
198+
</Steps>
199+
200+
## Release your SDK to Maven Central
201+
202+
At this point, you're ready to generate a release for your SDK.
203+
204+
<Steps>
205+
206+
<Step title="Set Maven environment variables">
207+
208+
On your local machine, set the the following environment variable to the various tokens you generated in previous steps:
209+
210+
```bash
211+
export MAVEN_USERNAME=your-maven-username
212+
export MAVEN_PASSWORD=your-maven-password
213+
export MAVEN_CENTRAL_SECRET_KEY_KEY_ID=your-gpg-key-id
214+
export MAVEN_CENTRAL_SECRET_KEY_PASSWORD=your-gpg-passphrase
215+
export MAVEN_CENTRAL_SECRET_KEY=your-gpg-secret-key
216+
```
217+
218+
</Step>
219+
220+
<Step title="Generate your release">
221+
222+
Regenerate your SDK and publish it on Maven Central:
223+
224+
```bash
225+
fern generate --group java-sdk --version <version>
226+
```
227+
Local machine output will verify that the release is pushed to your
228+
repository and tagged with the version you specified. Log back into Maven Central and
229+
navigate to **View Deployments** to see your new release.
230+
</Step>
231+
232+
</Steps>

0 commit comments

Comments
 (0)