Use CodeArtifact with deps.edn
You use deps.edn with clj to manage dependencies for Clojure projects. This section shows how to configure deps.edn to use a CodeArtifact repository.
Fetch dependencies
To configure Clojure to fetch dependencies from a CodeArtifact repository, you must
edit the Maven configuration file, settings.xml.
-
In
settings.xml, add a<servers>section with a reference to theCODEARTIFACT_AUTH_TOKENenvironment variable so that Clojure passes the token in HTTP requests.Note
Clojure expects the settings.xml file to be located at
~/.m2/settings.xml. If elsewhere, create the file in this location.<settings> ... <servers> <server> <id>codeartifact</id> <username>aws</username> <password>${env.CODEARTIFACT_AUTH_TOKEN}</password> </server> </servers> ... </settings> If you do not have one already, generate a POM xml for your project using
clj -Spom.In your
deps.ednconfiguration file, add a repository matching the server id from Mavensettings.xml.:mvn/repos { "clojars" nil "central" nil "codeartifact" {:url "https://my_domain-111122223333.d.codeartifact.us-west-2.amazonaws.com/maven/my_repo/"} }Note
-
tools.depsguarantees that thecentralandclojarsrepositories will be checked first for Maven libraries. Afterward, the other repositories listed indeps.ednwill be checked. -
To prevent downloading from Clojars and Maven Central directly,
centralandclojarsneed to be set tonil.
Make sure you have the CodeArtifact Auth token in an environment variable (see Pass an auth token using an environment variable). When building the package after these changes, dependencies in
deps.ednwill be fetched from CodeArtifact.Note
To use a dualstack endpoint, use the
codeartifact.endpoint.region.on.aws-
Publish artifacts
-
Update your Maven settings and
deps.ednto include CodeArtifact as a maven-recognized server (see Fetch dependencies). You can use a tool such as deps-deployto upload artifacts to CodeArtifact. In your
build.clj, add adeploytask to upload required artifacts to the previously setupcodeartifactrepository.(ns build (:require [deps-deploy.deps-deploy :as dd])) (defn deploy [_] (dd/deploy {:installer :remote :artifact "PATH_TO_JAR_FILE.jar" :pom-file "pom.xml" ;; pom containing artifact coordinates :repository "codeartifact"}))Publish the artifact by running the command:
clj -T:build deploy
For more information on modifying default repositories, see Modifying the default repositories