I'm developing a library and an application which uses this library.
I don't have any remote repository for this library, it's only stored on GitHub as a regular project.
In my application I want to use this library as a dependency, what I'm thinking about is to have a structure like that:
.
├── README.md
├── project.clj
├── repo
├── src
├── target
├── libraries
│ └── my-library
└── test
in which my-library
is git submodule
with my library. How to let my application know about this dependency?
What is 2016 solution for doing that?
There is no need to include the lib as a git submodule. You can "release" the my-library project locally.
Just go to my-library
project folder and run lein pom; lein jar; lein install
. The crucial part here is lein install
which installs the jar and pom to the local repository; typically ~/.m2.
Go to your project that uses this library and simply declare it as dependency in your project.clj
like :dependencies [[my-library "version"]]
and it should work.
EDIT:
Simlarly, if you are using Boot, you can run boot pom; boot jar; boot install
An even simpler solution is to use lein checkouts
as documented here: https://github.com/technomancy/leiningen/blob/master/doc/TUTORIAL.md#checkout-dependencies
Create a dir checkouts
at the top level of your project (parallel to the src
dir). Within checkouts
, just create a symbolic link to the directory of the project with the library code. For example, consider a project clj
and a library tupelo
drwxrwxr-x 10 alan alan 4096 Jan 5 12:09 clj/
drwxrwxr-x 11 alan alan 4096 Jan 9 20:01 tupelo/
The project clj
would look like so:
> d clj clj/* clj/checkouts/*
drwxrwxr-x 10 alan alan 4096 Jan 12 10:36 clj/
drwxrwxr-x 2 alan alan 4096 Oct 14 09:23 clj/checkouts/
lrwxrwxrwx 1 alan alan 17 Oct 30 16:44 clj/checkouts/tupelo -> /home/alan/tupelo/
drwxrwxr-x 2 alan alan 4096 Aug 31 10:05 clj/doc/
-rw-rw-r-- 1 alan alan 11219 Aug 31 10:05 clj/LICENSE
-rw-rw-r-- 1 alan alan 794 Jan 5 12:09 clj/project.clj
-rw-rw-r-- 1 alan alan 457 Aug 31 10:05 clj/README.md
drwxrwxr-x 2 alan alan 4096 Jan 3 09:01 clj/resources/
drwxrwxr-x 3 alan alan 4096 Aug 31 10:05 clj/src/
drwxrwxr-x 8 alan alan 4096 Nov 14 16:26 clj/target/
drwxrwxr-x 3 alan alan 4096 Sep 29 22:31 clj/test/
Now, when building the clj
project, it will (always) use source code from ~/tupelo
instead of clojars, maven, etc. This means you don't have to make & (re-)install a jar from the lib tupelo
everytime you make a change that you want to use in clj
.
It is not typical to use git submodules or a local file-based approach to manage libraries in Clojure. Clojure leverages much of the standard Java ecosystem approach to library management. Typically this involves building and deploying libraries to a public Maven repository like Clojars (or Maven Central). If you are only using this within your own organization, there are other options as well for organization-level Maven repositories.
You can then use that library in your own project by declaring it as a dependency in your build tool of choice. In Clojure, the most common tool is Leiningen and you would declare the use of that library as a dependency.
Other alternatives are Maven (very similar to Leiningen, but in XML format) or Boot, which takes a bit different approach.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With