File: README.md

package info (click to toggle)
pomegranate-clojure 1.1.0+really-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 400 kB
  • sloc: xml: 160; makefile: 2; sh: 2
file content (144 lines) | stat: -rw-r--r-- 5,799 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
# Pomegranate  [![Travis CI status](https://secure.travis-ci.org/cemerick/pomegranate.png)](https://travis-ci.org/cemerick/pomegranate/builds)

[Pomegranate](https://github.com/cemerick/pomegranate) is a library that
provides:

1. A sane Clojure API for
   [Maven-resolver](https://maven.apache.org/resolver/) (originally called Aether).
2. A re-implementation of
   [`add-classpath`](https://clojure.github.com/clojure/clojure.core-api.html#clojure.core/add-classpath)
   (deprecated in Clojure core) that:

* is a little more comprehensive than core's `add-classpath` — it should work as
  expected in more circumstances, and
* optionally uses Maven-resolver to add a Maven artifact (and all of its transitive
  dependencies) to your Clojure runtime's classpath dynamically.

Insofar as most useful Clojure libraries have dependencies, any reasonable
implementation of the `add-classpath` concept must seamlessly support resolving
those dependencies IMO.

## "Installation"

Pomegranate is available in Maven central.  Add it to your Leiningen
`project.clj`:

```clojure
[com.cemerick/pomegranate "1.1.0"]
```

or to your Maven project's `pom.xml`:

```xml
<dependency>
  <groupId>com.cemerick</groupId>
  <artifactId>pomegranate</artifactId>
  <version>1.1.0</version>
</dependency>
```

## `add-classpath` usage

Just to set a stage: you're at the REPL, and you've got some useful data that
you'd like to munge and analyze in various ways.  Maybe it's something you've
generated locally, maybe it's data on a production machine and you're logged in
via [nREPL](https://github.com/clojure/tools.nrepl).  In any case, you'd like to
work with the data, but realize that you don't have the libraries you need do
what you want.  Your choices at this point are:

1. Dump the data to disk via `pr` (assuming it's just Clojure data structures!),
   and start up a new Clojure process with the appropriate libraries on the
   classpath. This can really suck if the data is in a remote environment.
2. There is no second choice.  You _could_ use `add-claspath`, but the library
   you want has 12 bajillion dependencies, and there's no way you're going to
   hunt them down manually.

Let's say we want to use [Incanter](https://github.com/liebke/incanter) (which
has roughly 40 dependencies — far too many for us to reasonably locate and add
via `add-classpath` manually):

```clojure
=> (require '(incanter core stats charts))
#<CompilerException java.io.FileNotFoundException:
  Could not locate incanter/core__init.class or incanter/core.clj on classpath:  (NO_SOURCE_FILE:0)>
```

Looks bleak. Assuming you've got Pomegranate on your classpath already, you can
do this though:

```clojure
=> (use '[cemerick.pomegranate :only (add-dependencies)])
nil
=> (add-dependencies :coordinates '[[incanter "1.2.3"]]
                     :repositories (merge cemerick.pomegranate.aether/maven-central
                                          {"clojars" "https://clojars.org/repo"}))
;...add-dependencies returns full dependency graph...
=> (require '(incanter core stats charts))
nil
```

Now you can analyze and chart away, Incanter having been added to your runtime.
Note that `add-dependencies` may crunch along for a while — it may need to
download dependencies, so you're waiting on the network.  All resolved
dependencies are stored in the default local repository (`~/.m2/repository`),
and if they are found there, then they are not downloaded.

The arguments to `add-dependencies` look like Leiningen-style notation, and they
are.

Please note that **there are a number of scenarios in which `add-dependencies`
will not work, or will not work as you'd expect**.  Many of these are due to the
nature of JVM classloaders (e.g. adding jars containing conflicting versions of
a particular dependency will rarely end well), which Pomegranate does not
currently attempt to hide.  Thus, `add-classpath` and `add-dependencies` should
be considered escape hatches to be used when necessary, rather than a regular
part of your development workflow.

#### `URLClassLoader` modifiability

Starting with pomegranate `1.0.0`, `java.net.URLClassLoader`s are not modifiable
by default. This is to accommodate new reflection policy starting with JDK 9
(which currently issues an ugly warning on reflective access to non-public
methods, but future releases will simply fail). If you are in a situation where
you are using pomegranate but do not have a `clojure.lang.DynamicClassLoader`
visible in your classloader hierarchy, you will need to explicitly enable the
`java.net.URLClassLoader` support in
[dynapath](https://github.com/tobias/dynapath) (upon which pomegranate relies
for such things).

## Status of Aether support

Pomegranate is being used by [Leiningen v2.x](https://leiningen.org) as
its sole dependency resolution library.  This has prompted rapid
maturation of the scope and quality of Aether support.  That said,
specific API points remain subject to change as we find the right
abstractions and conventions.

#### Supported features

* dependency resolution
  * common dependency graph/hierarchy manipulation ops
* local installation
* remote deployment
* repository authentication for all of the above
* HTTP proxy configuration
* offline mode
* transfer listeners (with a sane Clojure fn veneer)

#### Not there yet

* repository listeners
* options to retrieve a single artifact (e.g. for obtaining source/javadoc)
* tests; there's halfway decent coverage, but nowhere near the kind of
  comprehensive combinatorial testing that maven dependency resolution demands

## Changelog

See the `CHANGES.md` file at the top level of the repo.

## License

Copyright © 2011-2017 [Chas Emerick](https://cemerick.com) and all other
contributors.

Licensed under the EPL. (See the file epl-v10.html.)