Loading Clojure Libraries Directly From Github
Did you ever fix a bug in an open source library, and then had to wait until the maintainer released an updated version?
It’s happened to me many times, the latest one being Toucan. I had run into a limitation, and found out that there was already an open ticket. It wasn’t a big change so I decided to dive in and address it. Just a little yak shave so I could get on with my life.
Now this pull request needs to be reviewed, and merged, and eventually be released to Clojars, but ain’t nobody got time for that stuff. No sir-ee.
So what do I do? Do I push my own version to Clojars? Call it lambdaisland/toucan
? If the project seems abandoned, and it could help others as well, then maybe I would, the way I did with ring.middleware.logger, but Toucan is actively maintained, so releasing a fork might cause confusion (and maybe even be taken the wrong way).
For cases like these it’s good to know that you can use Github as a Maven repository. That’s right, you don’t need to deploy or build any jars. Any Clojure library with a proper project.clj
will do, thanks to the power of Jitpack.
All you need to do is create a git tag and push it Github.
$ git tag v1.0.2-with-hydrate-fix
$ git push plexus --tags
Now add the Jitpack maven repository, and you can load your library straight aways.
(defproject lambdaisland "0.160.0"
:dependencies [,,,
[com.github.plexus/toucan "v1.0.2-hydrate-fix"]]
:repositories [["jitpack" "https://jitpack.io"]])
Notice the format of the dependency vector: [com.github.your-github-name/your-project-name "git-tag"]
.
Let’s try that out:
$ lein deps
Could not transfer artifact com.github.plexus:toucan:pom:v1.0.2-hydrate-fix from/to jitpack (https://jitpack.io): Read timed out
This could be due to a typo in :dependencies or network issues.
If you are behind a proxy, try setting the 'http_proxy' environment variable.
This is usually the case, the first time you try to download the jar, Jitpack still needs to fetch the code and build it, so this tends to time out. But try again a minute later and, tada \o/
$ lein deps
Retrieving com/github/plexus/toucan/v1.0.2-hydrate-fix/toucan-v1.0.2-hydrate-fix.pom from jitpack
Retrieving com/github/plexus/toucan/v1.0.2-hydrate-fix/toucan-v1.0.2-hydrate-fix.jar from jitpack
Jitpack also has paid plans, for when you want to deploy stuff straight from private repositories, but they’re free for open source, so kudos to them!
Comments ()