lein-ring icon indicating copy to clipboard operation
lein-ring copied to clipboard

lein-ring uberjar incompatible with profile-specific :target-path

Open paulbutcher opened this issue 10 years ago • 6 comments

lein-ring’s uberjar command seems to be incompatible with Leiningen’s profile-specific :target-path.

Generate a project with lein new compojure foo, build with lein ring uberjar and run with java -jar target/foo-0.1.0-SNAPSHOT-standalone.jar and everything works fine.

However, add this to project.clj:

:target-path "target/%s"

And the generated uberjar (which will now be in target/uberjar) is missing the main class:

$ java -jar target/uberjar/foo-0.1.0-SNAPSHOT-standalone.jar 
Error: Could not find or load main class foo.handler.main

paulbutcher avatar Jul 31 '14 14:07 paulbutcher

I suspect that this line is causing the issue. It should probably be :target-path rather than :compile-path.

weavejester avatar Jul 31 '14 14:07 weavejester

That doesn't seem to be it, I'm afraid. The only difference between :compile-path and :target-path is that :compile-path has "/classes" appended. Switching to :target-path breaks things.

As far as I can work out (although I'm not at all familiar with Leiningen's internals, so I may well have this wrong), the problem seems to be that main is being compiled before the uberjar profile is merged into the project. So when main is compiled, :compile path is target/base+system+user+dev/classes instead of target/uberjar/classes.

I tried merging the uberjar profile before compiling main, like https://github.com/weavejester/lein-ring/pull/104 does, but that doesn't address the problem either (it just seems to confuse matters because Leiningen doesn't like having the profile merged twice).

So I'm at a loss - the only way forward I can see right now is to copy Leiningen's uberjar task and add jar/compile-main to it after the uberjar profile has been merged into the project. Eugh!

paulbutcher avatar Jul 31 '14 16:07 paulbutcher

faced this issue too :(

razum2um avatar Aug 27 '14 00:08 razum2um

faced this issue too :(

cbegin avatar Dec 03 '14 22:12 cbegin

There is a similar problem with the ring uberwar task.

pjstadig avatar Dec 18 '14 17:12 pjstadig

I think this issue should be closed. On lein-ring 0.9.3 it seems to be fixed to me. Is there a particular case that can reproduce a failure? I did the following to verify (which is essentially the same case as the original report by @paulbutcher)

lein new compojure ring-116
# change lein-ring version to 0.9.3
java -jar target/ring-116-0.1.0-SNAPSHOT-standalone.jar
rm -rf target
# add target-path to project.clj
lein ring uberjar
java -jar target/uberjar/ring-116-0.1.0-SNAPSHOT-standalone.jar

pjstadig avatar Mar 25 '15 14:03 pjstadig