Using maven for managing Clojure projects

2 views
Skip to first unread message

Josip Gracin

unread,
May 18, 2008, 1:32:50 PM5/18/08
to Clojure
Hello!

Maven lets one define a project using a declarative language in xml
format. Among other things, project definition contains the
dependencies specification. In build time, the dependencies are
automatically downloaded and included in the classpath for various
build
tasks. They can also be included in the resulting jar file, copied to
some place, etc. IMHO, using Maven infrastructure might be beneficial
for Clojure.

With that thought, I started to create Maven project description (POM)
for clojure-contrib project but I stumbled on a problem. The thing is
that, as it is now, all the .clj files end up in the top-level
directory
of the jar file (i.e. of the classpath), without any prefix directory,
and therefore potentially collide with other projects.

So, the idea is to move the files to some subdirectory, for example,
clojure/contrib and then be able to evaluate something like

(require 'clojure.contrib.lib)

and that it loads file clojure/contrib/lib.clj based on the classpath.
Note that this is not imply messing up Clojure namespaces. lib.clj
could still use "lib" namespace as it does now.

Any thoughts on the idea?

Stephen C. Gilardi

unread,
May 18, 2008, 3:26:00 PM5/18/08
to clo...@googlegroups.com
On May 18, 2008, at 1:32 PM, Josip Gracin wrote:

> So, the idea is to move the files to some subdirectory, for example,
> clojure/contrib and then be able to evaluate something like
>
> (require 'clojure.contrib.lib)
>
> and that it loads file clojure/contrib/lib.clj based on the classpath.
> Note that this is not imply messing up Clojure namespaces. lib.clj
> could still use "lib" namespace as it does now.

My first choice would have been to add the path to the proposed
directory within the jar file directly to the classpath. I envisioned
using the "!" character to represent entering the jar file as Java
does when it prints URLs for resources within jars:

-cp path/to/jar/file/contrib.jar!clojure/contrib

Looking into that, it appears it's not a supported syntax for a
classpath entry. Does anyone know another way to accomplish something
similar using existing Java methods?

Symbol names containing "/" or "." are handled specially by clojure:

http://clojure.sourceforge.net/reference/reader.html

There's also no easy way to separate out the apparent "components"
between the periods.

The action of the "require" statement you proposed above is supported
now using the ":in" option for the libspec:

(require (lib :in "clojure/contrib"))

It would be feasible to add a concept of a "lib path": one or more
paths which would be automatically appended to each classpath root if
the resource were not found without extending the classpath. If that
would be a significant convenience, I'm open to considering it. We'd
want to weigh the convenience against the added complexity.

Does ":in" provide what you're looking for?

--Steve

Josip Gracin

unread,
May 19, 2008, 3:52:38 PM5/19/08
to Clojure
On May 18, 9:26 pm, Stephen C. Gilardi <scgila...@gmail.com> wrote:
> Does ":in" provide what you're looking for?

I think so, yeah. I didn't know it was there. Cool.

The dots were used just as an example. Obviously, not very informed
one. :-)

Thanks!

Stephen C. Gilardi

unread,
May 19, 2008, 7:06:36 PM5/19/08
to clo...@googlegroups.com
You're quite welcome.  I've been adding some things to lib.clj and updating the docs in the comments at the top of the file over time.  I'm glad ":in" is likely to work for you.

Cheers,

--Steve

Reply all
Reply to author
Forward
0 new messages