Lein :provided profile and uberjar not working

398 views
Skip to first unread message

Scott Klarenbach

unread,
Jun 3, 2015, 3:35:30 PM6/3/15
to clo...@googlegroups.com

I'm unable to post a new topic to the leinigen group so I thought I'd try my luck here.

I'd like to exclude certain dependencies from my uberjar, by using the :provided profile, but the jars are always included.

I've added the following to my project.clj, but the edu.stanford.nlp jars end up in the uberjar no matter what.  I've also tried with a simple project just to exclude a few jars and that doesn't seem to work either.  Am I missing something simple?  Or is there a better way to exclude large dependencies from uberjar if the deployment environment will already have them on the classpath?  Thanks.

:profiles {:uberjar {:aot :all}
             :provided {:dependencies
                        [[edu.stanford.nlp/stanford-corenlp "3.4.1"]
                         [edu.stanford.nlp/stanford-corenlp "3.4.1"
                          :classifier "models"]]}
             :dev {:resource-paths ["test-data"]}}

Marshall Bockrath-Vandegrift

unread,
Jun 3, 2015, 3:53:14 PM6/3/15
to clo...@googlegroups.com
Scott Klarenbach <doyouun...@gmail.com> writes:

> I'd like to exclude certain dependencies from my uberjar, by using the
> :provided profile, but the jars are always included.

I believe the problem you’re seeing is due to the fact that Leiningen
doesn’t quite think about dependency `scope` the same way Maven does.
Adding a direct-only dependency to the `:provided` profile does mark it
as `provided` `scope` in any resulting `pom.xml` and does not include
the dependencies added to an uberjar. But if one of your normal
dependencies *also* depends on the one you’ve added to `:provided`, then
the “provided-ness” isn’t propogated and it will get pulled into the
uberjar, just like any other indirect dependency.

The work-around is first to add the provided dependency to the
`:provided` profile as you’ve already done, then also add an
`:exclusion` for that same artifact, either at the top-level or on the
offending other direct dependencies.

HTH,

--
Marshall Bockrath-Vandegrift <lla...@damballa.com>
Principal Software Engineer, Damballa R&D

Scott Klarenbach

unread,
Jun 3, 2015, 3:54:32 PM6/3/15
to clo...@googlegroups.com
The issue was that I hadn't removed the dependencies from the toplevel vector.  Thanks to Jeremy Heiler for pointing that out.

Francis Avila

unread,
Jun 3, 2015, 4:51:33 PM6/3/15
to clo...@googlegroups.com
Possibly you are also including the dependencies in the non-profile part of the project.clj? You shouldn't: the :provided profile is normally included, but excluded when running the uberjar task.

More concrete example:

(defproject myproj "0.1.0"
 
:dependencies [[org.clojure/clojure "1.6.0"]] ;; notice standford-corenlp is *not* mentioned!!
 
:uberjar {:aot :all}  
 
:profiles {:provided {:dependencies
                       
[[edu.stanford.nlp/stanford-corenlp "3.4.1"]
                         
[edu.stanford.nlp/stanford-corenlp "3.4.1"
                         
:classifier "models"]]}})
Reply all
Reply to author
Forward
0 new messages