← All languages

Servirtium for

Clojure

No shipped package: vendor the binding's source at a release tag, with the native library from the release. Release v2.0.0-alpha.20.

FFI mechanism
Java binding (no second FFI). Clojure reaches libservirtium_vcr through the Java binding's jar by JVM interop; the namespace servirtium adds playback / record functions taking an options map.
Toolchain
JDK 22+; Clojure 1.12.0 (clojure/pom.xml), Clojure CLI (deps.edn) or Maven
Distribution
Vendor: install the release jar, then build the Clojure layer (dev.servirtium:vcr-clojure) from the tag; the layer is not a release asset
Finding the library
Same as Java: the native is bundled in the servirtium-vcr fat jar (/native/<os>-<arch>/) and extracted at run time; SERVIRTIUM_VCR_LIB overrides for platforms the jar lacks.
On GitHub
clojure/ · README

Getting it

There is no published package for Clojure. You vendor the binding's source into your project at the release tag v2.0.0-alpha.20 and take the native library from the same release.

  1. Install the release fat jar (six natives bundled: linux, macOS, Windows x86_64 and arm64) into your local Maven repository as dev.servirtium:vcr. It is not on Maven Central yet, so there is nothing to fetch by coordinate.
    TAG=v2.0.0-alpha.20; VER=2.0.0-alpha.20
    curl -fsSLO https://github.com/servirtium/servirtium-vcr/releases/download/$TAG/servirtium-vcr-$VER.jar
    mvn -q install:install-file -Dfile=servirtium-vcr-$VER.jar -DgroupId=dev.servirtium -DartifactId=vcr -Dversion=$VER -Dpackaging=jar
    mvn -q dependency:get -Dartifact=dev.servirtium:vcr:$VER && echo OK
  2. The Clojure layer is NOT a release asset. Build and install it from the same tag into ~/.m2 as dev.servirtium:vcr-clojure (needs git, Maven and JDK 22+).
    git clone -q --depth 1 --branch v2.0.0-alpha.20 https://github.com/servirtium/servirtium-vcr.git
    mvn -q -DskipTests -f servirtium-vcr/clojure install
    mvn -q dependency:get -Dartifact=dev.servirtium:vcr-clojure:2.0.0-alpha.20 && echo OK
  3. Depend on dev.servirtium:vcr-clojure:2.0.0-alpha.20 from ~/.m2 (use mavenLocal() / Resolver.mavenLocal where your build tool needs telling).
    ;; deps.edn
    {:deps {dev.servirtium/vcr-clojure {:mvn/version "2.0.0-alpha.20"}}}
    
    <!-- or Maven -->
    <dependency>
      <groupId>dev.servirtium</groupId>
      <artifactId>vcr-clojure</artifactId>
      <version>2.0.0-alpha.20</version>
      <scope>test</scope>
    </dependency>
  4. Run the test JVM with --enable-native-access=ALL-UNNAMED (Surefire argLine, Gradle jvmArgs, sbt javaOptions, Clojure :jvm-opts); JDK 24+ otherwise prints a restricted-method warning. No SERVIRTIUM_VCR_LIB is needed: the jar extracts its bundled native at runtime.

Record

Point your client at the VCR's base URL; the VCR forwards to the real service and hands back the real response. Nothing is written until you commit.

(require '[servirtium :as vcr])

(let [v (vcr/record "tapes/climate_api.md" "https://climatedataapi.worldbank.org"
                    {:port 0
                     :remove-transport-headers true
                     :redact-credentials true})]
  (try
    ;; ... drive the SUT against (.baseUrl v) ...
    (.commit v)          ; writes the tape
    (catch Throwable e
      (.discard v)       ; a failing test drops the recording
      (throw e))
    (finally (.close v))))

Playback

The same tape, replayed with no network.

(require '[servirtium :as vcr])
(import '[dev.servirtium.vcr Outcome])

(with-open [v (vcr/playback "tapes/climate_api.md" {:port 0})]
  ;; ... drive the SUT against (.baseUrl v) ...
  (assert (= Outcome/OK (.lastKind v)))
  (vcr/assert-no-mismatches v))

Idiomatic extras

Volatile values

Templates with {{placeholders}} apply to record and playback alike; :bind supplies what no request carries.

(with-open [server (vcr/playback "tape.md"
                     {:volatile-rules [["response headers" "Date: {{serverDate}}"]]
                      :bind {"serverDate" "Fri, 13 Nov 2026 09:41:07 GMT"}})]
  (println (vcr/volatile-report server)))

Stable order and playback range

Record-side sorting needs :pretty-json; :playback-range replays interactions 4..6 only.

(vcr/record tape upstream
  {:pretty-json 2
   :sort-json-keys true
   :sort-json-array [["versions" "/created"]]
   :sort-response-headers true
   :sort-header-value ["Allow"]})
(vcr/playback tape {:playback-range [4 6]})

Gotchas

  • JDK 22 or newer; run the test JVM with --enable-native-access=ALL-UNNAMED.
  • Layers over the Java jar: install the release servirtium-vcr-2.0.0-alpha.20.jar first. The layer itself is built from the tag, not downloaded.
  • A recording is written by commit() and dropped by discard(); closing a record server with neither writes nothing and throws VcrException.
  • The full Java builder API stays available: the layer only adds idiom (java/docs/usage.md describes the semantics).
  • Clojure is dynamic: the .clj sources are on the classpath, no static compile against the jar. Start the JVM with -J--enable-native-access=ALL-UNNAMED (or :jvm-opts in deps.edn).
  • with-open closes the server: call (.commit v) inside the body, or the close throws.

Prompt for your coding agent

Paste this into Claude, Codex, Gemini or any coding agent, in your Clojure project. It wraps one of your existing integration tests with Servirtium. The general prompt has a slot for the language instead.

Hey Gemini or Claude or Codex,

I want a test in this Clojure project to run without calling a real web service every time. Use Servirtium (https://servirtium.dev), which records HTTP conversations as readable Markdown "tapes" and replays them. Do these steps in order and tell me what you did at each one.

1. Find an existing integration test in this project that calls a web service as a side effect of what it is testing. Prefer one that is slow, flaky, or needs credentials or network because of that call. Tell me which test you chose and why.

2. Add the Servirtium binding for Clojure. Follow https://servirtium.dev/languages/clojure/ exactly. Servirtium ships no package for this language. Vendor the binding's source into the project at the release tag v2.0.0-alpha.20 and put the native library from the same release where the page says: Vendor: install the release jar, then build the Clojure layer (dev.servirtium:vcr-clojure) from the tag; the layer is not a release asset.
   Toolchain and minimum version: JDK 22+; Clojure 1.12.0 (clojure/pom.xml), Clojure CLI (deps.edn) or Maven.
   How the binding finds the native library: Same as Java: the native is bundled in the servirtium-vcr fat jar (/native/<os>-<arch>/) and extracted at run time; SERVIRTIUM_VCR_LIB overrides for platforms the jar lacks.
   This is a thin layer over the Java binding: install the Java jar (dev.servirtium:vcr) too, as the page says.

3. Route that test's HTTP client to the Servirtium VCR's base URL instead of the real service, using the idiomatic Clojure way of setting a base URL or HTTP client. The VCR starts on its own port (use port 0, so it picks a free one) and gives you its base URL; give that URL to the client and never hard-code a port.

4. Run the test once in record mode against the real service. Commit the recording when the test passes and discard it when the test fails: a record VCR that is closed without a commit or a discard writes no tape and raises an error. Use redact_credentials (the spelling for Clojure is on the page) so secrets become numbered tokens, and remove volatile request headers such as User-Agent and Date from the tape so playback does not depend on them.

5. Keep the tape beside the test as readable Markdown, in version control. Open it and check there are no secrets or personal data in it before committing.

6. Make the test play back by default, with an explicit switch (for example an environment variable such as SERVIRTIUM_RECORD=1) that re-records.

7. Prove it works offline: make the real service unreachable (network off, or a wrong host) and show the test still passes in playback.

Traps to avoid:
- A record VCR needs Commit() or Discard(); closing it without either writes nothing and raises.
- The VCR runs in your test process on its own port; the system under test must use the VCR's base URL, not the real one.
- JDK 22 or newer; run the test JVM with --enable-native-access=ALL-UNNAMED.
- Layers over the Java jar: install the release servirtium-vcr-2.0.0-alpha.20.jar first. The layer itself is built from the tag, not downloaded.
- A recording is written by commit() and dropped by discard(); closing a record server with neither writes nothing and throws VcrException.
- The full Java builder API stays available: the layer only adds idiom (java/docs/usage.md describes the semantics).
- Clojure is dynamic: the .clj sources are on the classpath, no static compile against the jar. Start the JVM with -J--enable-native-access=ALL-UNNAMED (or :jvm-opts in deps.edn).
- with-open closes the server: call (.commit v) inside the body, or the close throws.

References:
- This language's page: https://servirtium.dev/languages/clojure/
- The binding's directory: https://github.com/servirtium/servirtium-vcr/tree/main/clojure
- Concepts, features and every language's quick start: https://servirtium.dev/llms-full.txt (index: https://servirtium.dev/llms.txt)

How these snippets were checked

Built the layer from the v2.0.0-alpha.20 tag on linux (cachyos, JDK 25, Maven, Clojure CLI) on top of the release jar. Ran clojure/example consumer_example (PASS, playback of single_get.md). Ran the record snippet (with :remove-transport-headers, :redact-credentials, try/commit/discard) against a local upstream, then played the new tape back (ok-body, Outcome OK), and :playback-range [0 0] on single_get.md. vcr/assert-no-mismatches, volatile and sort snippets mirror the source/README and tests; not run.

They mirror these files in the repository:

See also the feature reference, llms.txt and the clojure/ directory.