Skip to content

Commit 4e2b71c

Browse files
committed
Add instructions for releasing to Maven Central
1 parent 3fa841d commit 4e2b71c

File tree

1 file changed

+137
-0
lines changed

1 file changed

+137
-0
lines changed

Diff for: RELEASING.md

+137
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
# Release Procedure
2+
3+
These instructions are a how-to guide for Hamcrest maintainers. They describe
4+
how to release a new version of Hamcrest to Maven Central.
5+
6+
## Signing Key Setup
7+
8+
The Gradle `signing` plugin is used to cryptographically sign the published
9+
artifacts. You will need to add details of your private keys to allow
10+
the plugin to work. Follow the instructions at
11+
https://docs.gradle.org/current/userguide/signing_plugin.html.
12+
13+
You can store the signing properties in a file called `gradle.properties`
14+
as a sibling of the top level `build.gradle` file. This file will be ignored
15+
by `git`, and so will not be accidentally checked in. Alternatively, you
16+
can put the `gradle.properties` file in the `GRADLE_USER_HOME` directory
17+
(usually `~/.gradle`)
18+
19+
## Sonatype Account Setup
20+
21+
Before you can perform a release, you will need:
22+
* An account on the Maven Central staging server at https://oss.sonatype.org/
23+
* Permissions in the `org.hamcrest` group
24+
25+
### Register an Account
26+
27+
You will need to register an account with https://central.sonatype.com/.
28+
Follow the instructions at https://central.sonatype.org/register/legacy/#create-an-account
29+
for actually creating an account. Do not follow the instructions to
30+
"Create a Namespace". `org.hamcrest` is already managed through the legacy
31+
project infrastructure. That may change in the future, but for now
32+
(July 2024) these instructions work as described below.
33+
34+
### Request to be Added to `org.hamcrest`
35+
36+
Sonatype needs to be notified that you have access to publish to
37+
`org.hamcrest`. This must be done by one of the current publishers
38+
(e.g. `@tumbarumba` or `@sf105`). Ask one of those people to follow
39+
the instructions at https://central.sonatype.org/register/legacy/#contact-central-support-at-sonatype.
40+
This may take up to 2 days before your permissions are applied.
41+
42+
### Configure Access Tokens
43+
44+
https://oss.sonatype.org/ will no longer accept a username and password
45+
when publishing. Rather, you will need to create an access token. Follow
46+
the instructions at https://central.sonatype.org/publish/generate-token/,
47+
and store the values in `ossrhUsername` and `ossrhPassword` in the same
48+
`gradle.properties` file used to hold the signing keys.
49+
50+
In the end, you should have a `gradle.properties` file with (at least) the
51+
following keys:
52+
53+
```properties
54+
signing.keyId=...
55+
signing.password=...
56+
signing.secretKeyRingFile=...
57+
ossrhUsername=...
58+
ossrhPassword=...
59+
```
60+
61+
## Publishing Process
62+
63+
### Update Version
64+
65+
The version is defined as a property at the top of the `build.gradle` file
66+
in the root of the repository. Normally, this has a `-SNAPSHOT` suffix. When
67+
doing a release, the `-SNAPSHOT` suffix is removed.
68+
69+
Edit the file to set the `version` property to the actual version required.
70+
Save the file and test out the publishing process locally by running the
71+
command:
72+
73+
```shell
74+
./gradlew clean jar publishToMavenLocal
75+
```
76+
77+
To check the local publish worked correctly, look in the directory
78+
`~/.m2/repository/org/hamcrest/hamcrest` and verify the versioned files
79+
are all present and correct.
80+
81+
When you are satisfied that the build is working correctly, you can commit
82+
the change, tag the repository, and push to GitHub.
83+
84+
e.g. this is the commands for version 3.0:
85+
86+
```shell
87+
git add build.gradle
88+
git commit -m "Version 3.0"
89+
git tag v3.0
90+
git push origin --tags
91+
```
92+
93+
### Publishing to Sonatype Staging
94+
95+
When ready, run the command:
96+
97+
```shell
98+
./gradlew publishAllPublicationsToMavenRepository
99+
```
100+
101+
Wait.
102+
103+
Wait a bit more. Sometimes it times out. Sometimes you will get 502 errors.
104+
Keep on trying. It will eventually work.
105+
106+
107+
### Release to Maven Central
108+
109+
Look at the staging repositories: https://oss.sonatype.org/#stagingRepositories
110+
and find the published artifacts. Make sure that everything is present
111+
and accounted for.
112+
113+
When you are happy, you will need to "Close" the repository - you won't be
114+
able to publish any more artifacts to this repository, but you will then
115+
be able to release the repository.
116+
117+
Once it is closed, you will be able to "Release" the repository, which will
118+
transfer all artifacts to Maven Central. It can take up to half an hour
119+
for the jars to appear. Look in https://mvnrepository.com/artifact/org.hamcrest/hamcrest
120+
and check for the new version.
121+
122+
### Prepare for Next Snapshot
123+
124+
Edit the `build.gradle` file, and change the version back to the next
125+
snapshot version. For example, if you just published version `3.0`, the
126+
next version will be `3.1-SNAPSHOT`.
127+
128+
Commit this change and push to GitHub.
129+
130+
### Share and Enjoy
131+
132+
Put a message out on the mailing lists to give people the good news.
133+
134+
# Future Improvements
135+
136+
Look at https://github.com/gradle-nexus/publish-plugin/ to automate all
137+
this.

0 commit comments

Comments
 (0)