how to get the latest clojure version in deps.edn without manually changing it
- User
how to get the latest clojure version in deps.edn without manually changing it
- Assistant
To keep your Clojure project up-to-date with the latest version without manually changing the
deps.ednfile, you can use a couple of strategies:-
Use a Version Range: Clojure's tooling doesn't directly support version ranges in the same way some other dependency management tools do, but you can specify a more general range or pattern if your dependencies offer it through Maven. For many scenarios, specifying only major or major.minor versions can allow your tooling to fetch newer compatible versions. However, Clojure language itself is often used with specific versions to ensure consistency.
-
Shell Scripts or CI Tools: You can automate the update process using a shell script or Continuous Integration (CI) tools to periodically check for the latest version and update your
deps.ednfile. For example, you can set up a script that:- Queries the Clojure repository for the latest version.
- Updates the
deps.ednfile with the new version.
#!/bin/bash # Fetch the latest release version of Clojure from an online source LATEST_CLOJURE_VERSION=$(curl -s https://api.clojure.org/releases/clojure/latest | jq -r '.version') # Update the deps.edn file sed -i.bak "s/clojure \"[^\"]*\"/clojure \"$LATEST_CLOJURE_VERSION\"/" deps.ednYou can add this script to run as part of your build or deployment process, ensuring you always use the latest version of Clojure.
- Use a Dependency Management Tool:
Tools like
lein-tools-depsfor Leiningen or managing your dependencies through tools likerenovateordependabotcan help automate or assist in keeping dependencies up to date in repositories, though they mostly serve other dependency formats or require some setup.
Remember, when automatically updating the Clojure version, you should have thorough tests to ensure that new versions do not introduce incompatibilities that affect your project.
-
- User
what about using "latest" instead of a version number in deps.edn?
- Assistant
In Clojure's
deps.edn, there isn't a built-in way to specify"latest"as a version for dependencies. Thedeps.ednsystem in Clojure is based on resolving dependencies through tools.deps, which typically requires explicit version numbers. The idea is to provide repeatable builds with known dependency versions rather than allowing automatic upgrades, which could introduce breaking changes or unexpected behavior.Here's why the
"latest"keyword isn't typically used or supported:-
Predictability and Stability:
- Using specific version numbers ensures that your builds are repeatable. If you rely on the latest version automatically, you might face unexpected issues due to changes in dependencies that haven't been tested with your code.
-
Tooling Limitations:
- The current Clojure tooling (
tools.deps.alpha) does not directly support specifying"latest"as a version string. It expects a valid semver version.
- The current Clojure tooling (
However, you can still automate or check for updates using external automation or tooling, as suggested earlier, to maintain a balance between staying up-to-date and ensuring stability. This approach allows you to test new versions before upgrading in a controlled manner.
-