14 April 2023
Alex Miller
Clojure 1.12.0-alpha2 is now available and we encourage you to try it and give us your feedback!
There are many cases where it would be useful to add a library interactively or to patch a live system without restarting the JVM - speculative evaluation, adding a known dependency to your project, or adding a library to accomplish a specific task.
Clojure 1.12.0-alpha2 provides new functions to add libraries interactively, without restarting the JVM or losing the state of your work:
add-lib takes a lib that is not available on the classpath, and makes it available by downloading (if necessary) and adding to the classloader. Libs already on the classpath are not updated. If the coordinate is not provided, the newest Maven or git (if the library has an inferred git repo name) version or tag are used.
add-libs is like add-lib
, but resolves a set of new libraries and versions together.
sync-deps calls add-libs
with any libs present in deps.edn, but not yet present on the classpath.
These new functions are intended only for interactive use at the repl - using a deps.edn etc is still the proper way to build and maintain your code. To this end, these functions all check that *repl* is bound to true (that flag is set automatically by clojure.main/repl
). In a clojure.main REPL, these new functions are automatically referred in the user
namespace. In other repls, you may need to (require '[clojure.repl.deps :refer :all])
before use.
Library resolution and download are provided by tools.deps. However, you do not want to add tools.deps and its many dependencies to your project classpath during development, and thus we have also added a new api for invoking functions out of process via the Clojure CLI.
There are many useful tools you can use at development time, but which are not part of your project’s actual dependencies. The Clojure CLI provides explicit support for tools with their own classpath, but there was not previously a way to invoke these interactively.
Now Clojure includes clojure.tools.deps.interop/invoke-tool to invoke a tool function out of process. The classpath for the tool is defined in your deps.edn so you do not need to add the tool’s dependencies to your project classpath.
add-lib
functionality is built using invoke-tool
but you can also use it to build or invoke your own tools for interactive use. Find more about the function execution protocol on the deps reference.
For a long time, we’ve had the clojure.java.shell
namespace, but over time Java has provided new APIs for process info, process control, I/O redirection.
This release adds a new namespace clojure.java.process that takes advantage of these APIs and is easier to use. See:
See the dev changelog for a full list of changes in 1.12.0-alpha2.