Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/java.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,14 @@ jobs:
- name: Compile, check formatting, and lint maintenance tools
run: make lint/java

- name: Test Go maintenance tools
- name: Test maintenance and release tools
run: make test/java/tools

- name: Verify canonical migration mirror
run: make verify/java-migrations

- name: Check publishable archives
run: make check/java/package
- name: Check and stage complete GitHub release archives
run: make check/java/github-release

java_versions:
name: Test (Java ${{ matrix.java-version }}, SQLite)
Expand Down
7 changes: 6 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,9 @@ test/java/sqlite: generate/fixtures verify/java-migrations
$(java_mvn) -f java/pom.xml verify -Driver.test.database=sqlite -DexcludedGroups=postgres

.PHONY: test/java/tools
test/java/tools: ## Test Java maintenance tools and Maven warning enforcement
test/java/tools: ## Test Java maintenance tools, release tooling, and Maven warning enforcement
bash java/bin/check-maven-warnings_test.sh
python3 -m unittest discover -s java/bin -p '*_test.py'
go test ./java/bin/check-packages/*.go
go test ./java/bin/sync-migrations/*.go

Expand Down Expand Up @@ -278,6 +279,10 @@ check/java/package: ## Build and verify publishable Maven archives without publi
check/java/package: build/java
go run ./java/bin/check-packages/main.go

.PHONY: check/java/github-release
check/java/github-release: ## Build, test, and stage all Java GitHub release assets without publishing
python3 java/bin/github-release.py prepare

.PHONY: check/java/release
check/java/release: ## Build a signed Maven Central bundle without uploading (requires an OpenPGP key)
check/java/release: generate/fixtures verify/java-migrations
Expand Down
4 changes: 3 additions & 1 deletion java/Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.PHONY: test test/conformance test/postgres test/sqlite test/tools lint lint/tools format package package/release
.PHONY: test test/conformance test/postgres test/sqlite test/tools lint lint/tools format package package/github-release package/release
test:
$(MAKE) -C .. test/java
test/conformance:
Expand All @@ -17,5 +17,7 @@ format:
mvn spotless:apply
package:
$(MAKE) -C .. check/java/package
package/github-release:
$(MAKE) -C .. check/java/github-release
package/release:
$(MAKE) -C .. check/java/release
72 changes: 57 additions & 15 deletions java/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,15 @@ retry, or work them using the same database.
Java 21 or newer is required. Add `com.riverqueue:river:0.1.0-alpha.1` and a JDBC driver to your application's dependencies. Jackson 3 is included transitively.

```xml
<repositories>
<repository>
<id>river</id>
<url>https://riverqueue.com/maven</url>
<releases><checksumPolicy>fail</checksumPolicy></releases>
<snapshots><enabled>false</enabled></snapshots>
</repository>
</repositories>

<dependency>
<groupId>com.riverqueue</groupId>
<artifactId>river</artifactId>
Expand All @@ -21,6 +30,8 @@ Java 21 or newer is required. Add `com.riverqueue:river:0.1.0-alpha.1` and a JDB
</dependency>
```

The River repository is public and requires no credentials. Maven Central supplies third-party dependencies.

For SQLite, replace the Postgres JDBC dependency with `org.xerial:sqlite-jdbc:3.53.4.0`. To install a local copy of River from source, see the [development guide](docs/development.md#building-from-source).

## Quick start
Expand Down Expand Up @@ -78,24 +89,30 @@ for each operation. River never closes an application-owned data source. An

## Migration CLI

The `river-cli` executable JAR includes Postgres and SQLite JDBC drivers and
runs with Java 21 or newer. It needs no application classpath.
For a local build, see the [development guide](docs/development.md#building-from-source). Set `RIVER_CLI` to the executable JAR, then run:
The CLI runs with Java 21 or newer. [JBang](https://www.jbang.dev/documentation/jbang/latest/installation.html)
resolves the thin CLI JAR and its dependencies and installs a reusable command:

```sh
RIVER_CLI=/path/to/river-cli-0.1.0-alpha.1-all.jar
jbang app install --name river-java --java 21 \
--java-options=--enable-native-access=ALL-UNNAMED \
--repos https://riverqueue.com/maven \
--main com.riverqueue.cli.MigrationCli \
com.riverqueue:river-cli:0.1.0-alpha.1
export PATH="$HOME/.jbang/bin:$PATH"
export DATABASE_URL=postgres://localhost/myapp
# For SQLite: export DATABASE_URL=jdbc:sqlite:/absolute/path/myapp.db

java -jar "$RIVER_CLI" --help
java -jar "$RIVER_CLI" migrate-list
java -jar "$RIVER_CLI" migrate-up --dry-run
java -jar "$RIVER_CLI" migrate-up
river-java --help
river-java migrate-list
river-java migrate-up --dry-run
river-java migrate-up
```

The Maven executable artifact is `com.riverqueue:river-cli` with version
`0.1.0-alpha.1` and classifier `all`. Copy that single JAR into your deployment image to run
migrations before starting workers. `--database-url URL` overrides `DATABASE_URL`.
Dependencies, including both JDBC drivers, are downloaded once and cached. No
`all` classifier is needed. For containers or installations with Maven and a JDK,
use the [Maven-only instructions](#running-with-maven-and-java) below, or
[build from source](docs/development.md#building-from-source).
`--database-url URL` overrides `DATABASE_URL`.
`--schema background_jobs` selects a Postgres schema; an actual migration up
creates it if needed. Listing and dry runs do not create schemas or migration tables.

Expand All @@ -113,10 +130,10 @@ version `0` explicitly removes the entire migration line. A zero `--max-steps`
uses the command's default: all pending up migrations or one down migration.

```sh
java -jar "$RIVER_CLI" migrate-down --max-steps 2 --dry-run --show-sql
java -jar "$RIVER_CLI" migrate-up --target-version 8
java -jar "$RIVER_CLI" migrate-get --version 3 --up > river_3.up.sql
java -jar "$RIVER_CLI" migrate-get --driver sqlite --all --up > river_sqlite.up.sql
river-java migrate-down --max-steps 2 --dry-run --show-sql
river-java migrate-up --target-version 8
river-java migrate-get --version 3 --up > river_3.up.sql
river-java migrate-get --driver sqlite --all --up > river_sqlite.up.sql
```

SQL export defaults to Postgres without a database URL. Use `--driver sqlite`
Expand All @@ -136,6 +153,31 @@ var preview = new Migrator(database).migrate(Migrator.Direction.DOWN,
Migrator.Options.defaults().maxSteps(2).dryRun(true));
```

### Running with Maven and Java

In an empty directory, create this consumer POM and download the runtime JARs:

```sh
cat > pom.xml <<'EOF'
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>local</groupId><artifactId>river-cli-install</artifactId><version>1</version>
<repositories><repository><id>river</id><url>https://riverqueue.com/maven</url></repository></repositories>
<dependencies><dependency><groupId>com.riverqueue</groupId><artifactId>river-cli</artifactId><version>0.1.0-alpha.1</version></dependency></dependencies>
</project>
EOF
mvn --batch-mode --no-transfer-progress \
org.apache.maven.plugins:maven-dependency-plugin:3.11.0:copy-dependencies \
-DincludeScope=runtime
java --enable-native-access=ALL-UNNAMED -cp 'target/dependency/*' \
com.riverqueue.cli.MigrationCli --help
```

Replace `--help` with any migration command above. Copy the entire
`target/dependency` directory into a deployment image and adjust the classpath to
its location. Running it needs only Java; Maven and network access are needed
when downloading the dependencies.

## Transactional enqueueing

[Enqueue in the application's transaction](https://riverqueue.com/docs/transactional-enqueueing)
Expand Down
1 change: 0 additions & 1 deletion java/bin/check-packages/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ func run(root string) error {
{"river/target/river-" + project.Version + "-sources.jar", false},
{"cli/target/river-cli.jar", false},
{"cli/target/river-cli-sources.jar", false},
{"cli/target/river-cli-" + project.Version + "-all.jar", true},
} {
var resources string
if artifact.runtime {
Expand Down
Loading
Loading