Skip to content

Instantly share code, notes, and snippets.

@joinr
Created March 21, 2017 05:55
Show Gist options
  • Save joinr/f88e915eafd15103c308e9092fa0c488 to your computer and use it in GitHub Desktop.
Save joinr/f88e915eafd15103c308e9092fa0c488 to your computer and use it in GitHub Desktop.
An example of a file-repo that mirrors central and clojars so that we don't touch the network, along with comments about weird error messages...
;;Say I don't want to ever touch the internet. Say I've written all my
;;awesome clojure stuff, and I have built up a bunch of libraries in
;;my local .m2 repo. Important caveat: say none of these libraries
;;got there via 'lein install', if they did....we got problems and
;;likely will get wierd errors. Let's say, for now, every lib
;;is downloaded from either clojars or maven central.
;;If we were to copy our .m2 folder to another place....say
;;a network file folder, or just a local file folder like
;;c:/Users/tom/repos/, we can force lein to look there
;;and only there - when resolving external (that is
;;dependencies that aren't cached to our local .m2 folder).
;;THe following profile sketches out how to do so..
{:user {:plugins [[joinr/lein-marginalia "0.9.1-SNAPSHOT"]]
;;CRITICAL: point the default central and clojars at our local
;;file mirror, via the :mirrors profile.
;;:mirrors values take the same keys as :repositories.
;;the :url is a file:///... uri, which must point to the
;;repository folder, not the root .m2 folder.
;;(note the added /repository/ on the file url)
:mirrors {"central" {:name "central"
:url "file:///c:/Users/tom/repos/repository/"
:checksum :warn}
#"clojars" {:name "internal repo"
:url "file:///c:/Users/tom/repos/repository/"
:repo-manager true
:checksum :warn}
}
;;optionally, we can setup to deploy to our mirror.
;;this way, if we do 'lein deploy fs' our lib is installed there, and
;;other donks can use it. The most notable difference between this and
;;'lein install' is that 'lein install' doesn't provide the correct,
;;magical metadata necessary for others to resolve it. So, if we have
;;anything in our .m2 cache that got there via 'lein install', if we
;;copy it to our mirror, we'll end up with wierd errors...like
;;"number of bytes transferred cannot be negative", which is maven's
;;crappy way of telling us we have garbage dependencies in our local
;;cache and/or in our remote. this is typically an artifact of
;;going with 'lein install' instead of deploying, or copying our .m2
;;without thinking...
:deploy-repositories [["fs" {:url "file:///c:/Users/tom/repos/"
:sign-releases false}]]
;;This is another way to define "local" repositories. The only reason we used the
;;:mirrors definition above is to, under production circumstances, prevent lein
;;from running out to the internet (which we can't access), rather using the
;;file-based mirrors. This mechanism just provides "extra" places to look, along
;;with any caveats about them.
;; :repositories [["blah" {:url "file:///c:/Users/tom/repos/repository/"
;; ;; If a repository contains releases only setting
;; ;; :snapshots to false will speed up dependencies.
;; :snapshots true
;; ;; Disable signing releases deployed to this repo.
;; ;; (Not recommended.)
;; :sign-releases false
;; ;; You can also set the policies for how to handle
;; ;; :checksum failures to :fail, :warn, or :ignore.
;; :checksum :warn
;; ;; How often should this repository be checked for
;; ;; snapshot updates? (:daily, :always, or :never)
;; :update :always
;; ;; You can also apply them to releases only:
;; }]]
}
:repl
{:plugins
[[cider/cider-nrepl "0.9.1"]
]}
}
;;Noted errors:
;;"No algorthims available" => looks like it finds the libs, but fails to resolve. Likely that you
;;didn't add on the "repository" folder to the file uri.
;;"Cannot transfer negative bytes" => garbage either in the remote or the local repo.
;;You may have crap that was 'lein installed' or otherwise deployed. This causes maven to
;;freak out and think the repository is wrong or something. Again, if you pulled everything
;;from clojars or central, you shouldn't run into this problem. Solution: wipe your mirror, ensure
;;it only has jars from clojars/central (i.e. with a fresh .m2 local cache - or none - got to your project
;;and do a lein deps - resolve dependencies - WITHOUT the aforementioned mirrors enabled). After that,
;;copy your - now "clean" .m2 - into the mirror location. Turn on mirros in the profiles.clj .
;;Test out by wiping your .m2, then trying lein deps again from the same project. It should fetch
;;the exact dependencies you just dl'd. If you posted your jars on the network, other people can
;;use the file mirror as their clojars/central mirror too.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment