Skip to content

Commit 00ad54a

Browse files
committed
docs(java): Update readme with badge, add Java readme, and add a publish script for later
1 parent a5fdd61 commit 00ad54a

File tree

3 files changed

+167
-0
lines changed

3 files changed

+167
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
[![Go checks](https://github.com/google/dotprompt/actions/workflows/go.yml/badge.svg)](https://github.com/google/dotprompt/actions/workflows/go.yml)
22
[![Python checks](https://github.com/google/dotprompt/actions/workflows/python.yml/badge.svg)](https://github.com/google/dotprompt/actions/workflows/python.yml)
33
[![JS checks](https://github.com/google/dotprompt/actions/workflows/test.yml/badge.svg)](https://github.com/google/dotprompt/actions/workflows/test.yml)
4+
[![Java checks](https://github.com/google/dotprompt/actions/workflows/java.yml/badge.svg)](https://github.com/google/dotprompt/actions/workflows/java.yml)
45
[![Ask Codewiki](https://codewiki.google/github.com/google/dotprompt)](https://codewiki.google/github.com/google/dotprompt)
56
[![Ask DeepWiki](https://deepwiki.com/badge.svg)](https://deepwiki.com/google/dotprompt)
67

java/README.md

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
# Java Dotprompt
2+
3+
This directory contains the Java implementation of the Dotprompt library.
4+
5+
## Usage
6+
7+
Add the following dependency to your project:
8+
9+
**Maven:**
10+
```xml
11+
<dependency>
12+
<groupId>com.google.dotprompt</groupId>
13+
<artifactId>dotprompt</artifactId>
14+
<version>0.1.0</version>
15+
</dependency>
16+
```
17+
18+
**Gradle:**
19+
```groovy
20+
implementation 'com.google.dotprompt:dotprompt:0.1.0'
21+
```
22+
23+
**Bazel:**
24+
```starlark
25+
maven_install(
26+
artifacts = [
27+
"com.google.dotprompt:dotprompt:0.1.0",
28+
],
29+
# ...
30+
)
31+
```
32+
33+
## Building
34+
35+
```bash
36+
bazel build //java/com/google/dotprompt:dotprompt
37+
```
38+
39+
## Testing
40+
41+
```bash
42+
bazel test //java/com/google/dotprompt/...
43+
```
44+
45+
---
46+
47+
# Deploying to Maven Central
48+
49+
This section describes the process for releasing the `dotprompt` Java library to Maven Central.
50+
51+
## Prerequisites
52+
53+
1. **GPG Keys**: You need a GPG key pair to sign artifacts.
54+
* Export the private key: `gpg --armor --export-secret-keys <KEY_ID>`
55+
* Note the passphrase.
56+
57+
2. **Sonatype OSSRH Account**: You need an account on [s01.oss.sonatype.org](https://s01.oss.sonatype.org/) with access to the `com.google.dotprompt` group ID.
58+
59+
## GitHub Secrets Configuration
60+
61+
Configure these secrets in the repository settings (Settings → Secrets and variables → Actions):
62+
63+
| Secret Name | Description |
64+
|-------------|-------------|
65+
| `OSSRH_USERNAME` | Your Sonatype username |
66+
| `OSSRH_TOKEN` | Your Sonatype password or user token |
67+
| `MAVEN_GPG_PRIVATE_KEY` | ASCII-armored GPG private key |
68+
| `MAVEN_GPG_PASSPHRASE` | Passphrase for your GPG key |
69+
70+
## Release Process
71+
72+
### 1. Update the Version
73+
74+
Before creating a release, update the version in `java/com/google/dotprompt/BUILD.bazel`:
75+
76+
```starlark
77+
java_export(
78+
name = "dotprompt_pkg",
79+
maven_coordinates = "com.google.dotprompt:dotprompt:X.Y.Z", # Update this
80+
# ...
81+
)
82+
```
83+
84+
### 2. Create a GitHub Release
85+
86+
1. Go to the **Releases** section on GitHub.
87+
2. Click **Draft a new release**.
88+
3. Create a new tag matching the version (e.g., `java-v0.1.0`).
89+
4. Add release notes.
90+
5. **Publish** the release.
91+
92+
### 3. Automated Publishing
93+
94+
The `Publish Java Package` workflow (`.github/workflows/publish_java.yml`) triggers automatically when a release is created:
95+
96+
1. Sets up JDK 21 and Bazel.
97+
2. Imports the GPG key.
98+
3. Runs `scripts/publish-java.sh` to publish to Maven Central.
99+
100+
### 4. Verification
101+
102+
* Check the GitHub Actions workflow logs for success.
103+
* Log in to [Sonatype OSSRH](https://s01.oss.sonatype.org/) to verify the staging repository.
104+
* After sync (typically 10-30 minutes), verify on [Maven Central](https://search.maven.org/search?q=g:com.google.dotprompt).
105+
106+
## Local Testing (Dry Run)
107+
108+
To verify artifacts build correctly without publishing:
109+
110+
```bash
111+
bazel build //java/com/google/dotprompt:dotprompt_pkg
112+
```
113+
114+
To inspect the generated POM:
115+
116+
```bash
117+
bazel build //java/com/google/dotprompt:dotprompt_pkg-pom
118+
cat bazel-bin/java/com/google/dotprompt/dotprompt_pkg-pom.xml
119+
```

scripts/publish-java.sh

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#!/bin/bash
2+
# Copyright 2025 Google LLC
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
#
16+
# SPDX-License-Identifier: Apache-2.0
17+
18+
set -e
19+
20+
# Usage: ./scripts/publish-java.sh <gpg_sign_key_path> <gpg_passphrase> <maven_user> <maven_password>
21+
22+
if [ "$#" -ne 4 ]; then
23+
echo "Usage: $0 <gpg_sign_key_path> <gpg_passphrase> <maven_user> <maven_password>"
24+
exit 1
25+
fi
26+
27+
GPG_KEY_PATH=$1
28+
GPG_PASSPHRASE=$2
29+
MAVEN_USER=$3
30+
MAVEN_PASSWORD=$4
31+
32+
# Define the deployment repository URL (Sonatype OSSRH)
33+
DEPLOY_ENV="release" # or "snapshot" if desired, but typically we want release for tags.
34+
# Bazel java_export allows specifying deployment via flags or properties.
35+
# We will use the standard command structure generated by java_export.
36+
37+
echo "Publishing Java artifacts..."
38+
39+
bazel run //java/com/google/dotprompt:dotprompt_pkg.publish -- \
40+
--define "maven_repo=https://oss.sonatype.org/service/local/staging/deploy/maven2/" \
41+
--define "maven_user=$MAVEN_USER" \
42+
--define "maven_password=$MAVEN_PASSWORD" \
43+
--define "gpg_sign=true" \
44+
--define "gpg_key=$GPG_KEY_PATH" \
45+
--define "gpg_passphrase=$GPG_PASSPHRASE"
46+
47+
echo "Publishing complete."

0 commit comments

Comments
 (0)