Skip to content

Instantly share code, notes, and snippets.

@GaspardP
Last active March 7, 2020 11:02
Show Gist options
  • Save GaspardP/32d9c6b2f4da28121c79c76acc74e2db to your computer and use it in GitHub Desktop.
Save GaspardP/32d9c6b2f4da28121c79c76acc74e2db to your computer and use it in GitHub Desktop.
alpha.spec (org.clojure/spec-alpha2) as lein dependency (local install using a maven deploy-file)

Create a local maven repository

To isolate local artifacts from downloaded one we create a local equivalent of ~/.m2/repositories.

mkdir -p ~/.m2/local

Install spec-alpha2 in the local repository

Clone, build and install alpha.spec (previously spec-alpha2) to the local repository.

# Version extracted from https://github.com/clojure/spec-alpha2/blob/683e507a9647b65a248a5e00d314f9cfaaa2ce56/pom.xml#L5
VERSION="0.2.177-SNAPSHOT"
git clone https://github.com/clojure/spec-alpha2.git
cd spec-alpha2
mvn package
mvn deploy:deploy-file -Durl=file:\${user.home}/.m2/local \
    -Dfile=target/alpha.spec-$VERSION.jar \
    -DgroupId=org.clojure -DartifactId=alpha.spec -Dversion=$VERSION

Use alpha.spec in the project

In your project, add alpha.spec as a dependency and refer to its local version.

;;; project.clj
:dependencies [[org.clojure/alpha.spec "0.2.177-SNAPSHOT"]]
:repositories {"local" ~(str "file:" (System/getProperty "user.home") "/.m2/local")}

The artifiact should now be available.

$ lein deps
Retrieving org/clojure/alpha.spec/0.2.177-SNAPSHOT/alpha.spec-0.2.177-20200303.104500-1.pom from local
Retrieving org/clojure/alpha.spec/0.2.177-SNAPSHOT/alpha.spec-0.2.177-20200303.104500-1.jar from local

You can now require the lib in your project.

(ns my.namespace
  (:require [clojure.alpha.spec :as s]))

NB: If you want to use the generator (e.g. (gen/sample (s/gen ::some-spec))) you will need to add test.gen as a dependency.

:dependencies [[org.clojure/alpha.spec "0.2.177-SNAPSHOT"]
               [org.clojure/test.check "0.10.0"]]

Possible error

$ lein deps
Could not find artifact org.clojure:alpha.spec:jar:0.2.177-SNAPSHOT in clojars (https://repo.clojars.org/)
Could not find artifact org.clojure:alpha.spec:jar:0.2.177-SNAPSHOT in local (file:/home/$USER/.m2/local)
This could be due to a typo in :dependencies, file system permissions, or network issues.
If you are behind a proxy, try setting the 'http_proxy' environment variable.

Check that the files are present in your local repository. In this example it should be located in ~/.m2/local and contain the files as listed below.

$ ls ~/.m2/local/org/clojure/alpha.spec
0.2.177-SNAPSHOT  maven-metadata.xml  maven-metadata.xml.md5  maven-metadata.xml.sha1
(defproject my-project "0.1.0-SNAPSHOT"
:description "FIXME: write description"
:url "http://example.com/FIXME"
:license {:name "Eclipse Public License"
:url "http://www.eclipse.org/legal/epl-v10.html"}
:dependencies [[org.clojure/clojure "1.10.1"]
[org.clojure/test.check "0.10.0"]
;; Version extracted from https://github.com/clojure/spec-alpha2/blob/683e507a9647b65a248a5e00d314f9cfaaa2ce56/pom.xml#L5
[org.clojure/alpha.spec "0.2.177-SNAPSHOT"]]
;; Make local version of the dependencies available
:repositories {"local" ~(str "file:" (System/getProperty "user.home") "/.m2/local")}
:main ^:skip-aot state.core
:target-path "target/%s"
:profiles {:uberjar {:aot :all}})
@GaspardP
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment