clojure-android / lein-droid

A Leiningen plugin for building Clojure/Android projects
Eclipse Public License 1.0
645 stars 56 forks source link

Problem getting classpath or deps tree from leiningen #131

Open laurentpetit opened 8 years ago

laurentpetit commented 8 years ago

Trying to get the classpath from leiningen via lein classpath gives the following problem (it's as if the m2repository was not added to the project repositories):

myapp % lein classpath
(Warning: profile :android-common not found.)
(Warning: profile :android-user not found.)
Could not find artifact com.android.support:multidex:aar:1.0.0 in central (https://repo1.maven.org/maven2/)
Could not find artifact com.android.support:multidex:aar:1.0.0 in clojars (https://clojars.org/repo/)
Could not find artifact com.android.support:multidex:aar:1.0.0 in maven-snapshots (https://oss.sonatype.org/content/repositories/snapshots)
This could be due to a typo in :dependencies or network issues.
If you are behind a proxy, try setting the 'http_proxy' environment variable.

Also, trying to get the deps tree from leiningen via lein deps :tree gives a similar problem:

myapp % lein-stable deps :tree
(Warning: profile :android-common not found.)
(Warning: profile :android-user not found.)
(Warning: profile :android-common not found.)
(Warning: profile :android-user not found.)
Possibly confusing dependencies found:
[lein-droid "0.4.0-alpha6"] -> [org.clojure/data.zip "0.1.1"] -> [org.clojure/clojure "1.3.0-beta1"]
 overrides
[lein-droid "0.4.0-alpha6"] -> [de.ubercode.clostache/clostache "1.4.0"] -> [org.clojure/core.incubator "0.1.2"] -> [org.clojure/clojure "1.4.0"]
 and
[lein-droid "0.4.0-alpha6"] -> [de.ubercode.clostache/clostache "1.4.0"] -> [org.clojure/clojure "1.3.0"]

Consider using these exclusions:
[lein-droid "0.4.0-alpha6" :exclusions [org.clojure/clojure]]
[lein-droid "0.4.0-alpha6" :exclusions [org.clojure/clojure]]

Could not find artifact com.android.support:multidex:aar:1.0.0 in central (https://repo1.maven.org/maven2/)
Could not find artifact com.android.support:multidex:aar:1.0.0 in clojars (https://clojars.org/repo/)
Could not find artifact com.android.support:multidex:aar:1.0.0 in maven-snapshots (https://oss.sonatype.org/content/repositories/snapshots)
This could be due to a typo in :dependencies or network issues.
If you are behind a proxy, try setting the 'http_proxy' environment variable.

Finally, trying a last resort solution, e.g. calling lein repl so that hopefully I could try to get the classpath from (System/getProperty "java.class.path") won't work either (same problem).

So I'm having a hard time figuring out how I can get the project classpath from Leiningen so that CCW in Eclipse can correctly set up the java build path.

Starting the discussion about it. The goal would be to find a way to get the classpath from leiningen via the classic methods.

alexander-yakushev commented 8 years ago

Thing is, local repositories are merged at the plugin-initialization level. I might either move it to middleware, or provide an exclusive lein droid classpath command just for this purpose.

laurentpetit commented 8 years ago

It would really be better to move it to the middleware, so its use will be pervasive whatever lein command is called after that. Having lein droid classpath would plut lein-droid in an island, forcing a special case for tooling wanting to get classpath information from arbitrary leiningen project.

alexander-yakushev commented 8 years ago

Just afair middlewares in lein-droid are badly implemented, at least they were three years ago. Gotta take another look.

alexander-yakushev commented 8 years ago

@laurentpetit I fixed this bug, and just accidentally pushed 0.4.0 :D. Hopefully nothing got broken there. Waiting for your affirmation.

laurentpetit commented 8 years ago

Will test it ASAP, thanks!

2015-08-21 1:05 GMT+02:00 Alexander Yakushev notifications@github.com:

@laurentpetit https://github.com/laurentpetit I fixed this bug, and just accidentally pushed 0.4.0 :D. Hopefully nothing got broken there. Waiting for your affirmation.

— Reply to this email directly or view it on GitHub https://github.com/clojure-android/lein-droid/issues/131#issuecomment-133207518 .

Laurent Petit

laurentpetit commented 8 years ago

It's better than before: leiningen can now give a classpath to CCW. But it seems that the classpath is incomplete. In the hello world example, the SplashActivity java class complains there's no android.* stuff on the classpath.

Here's what I get when doing lein classpath: lein classpath (Warning: profile :android-common not found.) (Warning: profile :android-user not found.) /Users/laurentpetit/tmp test/myccwapp/test:/Users/laurentpetit/tmp test/myccwapp/src/clojure:/Users/laurentpetit/tmp test/myccwapp/src:/Users/laurentpetit/tmp test/myccwapp/resources:/Users/laurentpetit/tmp test/myccwapp/target/debug/classes:/Users/laurentpetit/.m2/repository/org/clojure-android/clojure/1.7.0/clojure-1.7.0.jar:/Users/laurentpetit/.m2/repository/neko/neko/4.0.0-alpha2/neko-4.0.0-alpha2.jar:/Users/laurentpetit/.m2/repository/org/clojure/tools.nrepl/0.2.10/tools.nrepl-0.2.10.jar:/Users/laurentpetit/.m2/repository/org/clojure/clojure/1.2.0/clojure-1.2.0.jar

2015-08-21 13:44 GMT+02:00 Laurent PETIT laurent.petit@gmail.com:

Will test it ASAP, thanks!

2015-08-21 1:05 GMT+02:00 Alexander Yakushev notifications@github.com:

@laurentpetit https://github.com/laurentpetit I fixed this bug, and just accidentally pushed 0.4.0 :D. Hopefully nothing got broken there. Waiting for your affirmation.

— Reply to this email directly or view it on GitHub https://github.com/clojure-android/lein-droid/issues/131#issuecomment-133207518 .

Laurent Petit

Laurent Petit

alexander-yakushev commented 8 years ago

I only moved the repositories to middleware. What exactly are you trying to do, get a full classpath, or something more?

alexander-yakushev commented 8 years ago

Additional dependencies are merged into project (and end up on classpath eventually) in different hooks at different points of time. I'm not sure all of those can be moved to middleware, so I have to know what exactly you are trying to achieve.

laurentpetit commented 8 years ago

I am trying to get a full classpath to give that to Eclipse.

So I'm doing basically lein classpath

2015-08-21 15:30 GMT+02:00 Alexander Yakushev notifications@github.com:

I only moved the repositories to middleware. What exactly are you trying to do, get a full classpath, or something more?

— Reply to this email directly or view it on GitHub https://github.com/clojure-android/lein-droid/issues/131#issuecomment-133425603 .

Laurent Petit

alexander-yakushev commented 8 years ago

Will lein droid classpath do if it exists?

laurentpetit commented 8 years ago

I fear not, because it's not a generic solution :-(

2015-08-21 15:34 GMT+02:00 Alexander Yakushev notifications@github.com:

Will lein droid classpath do if it exists?

— Reply to this email directly or view it on GitHub https://github.com/clojure-android/lein-droid/issues/131#issuecomment-133426153 .

Laurent Petit

alexander-yakushev commented 8 years ago

There's not much generic in lein-droid, it's a separate build system rather than a plugin. It doesn't use any of the usual leiningen commands, like lein compile or lein jar. So it depends how "generic" you really expect it to be.

laurentpetit commented 8 years ago

Currently, CCW embeds leiningen, gets the project map from it, and calls leiningen.core.classpath/resolve-dependencies with dependency keys and the project map.

Couldn't the droid plugin/middleware enhance the project map with the relevant information, so that after that point every lein command works as expected?

2015-08-21 15:44 GMT+02:00 Alexander Yakushev notifications@github.com:

There's not much generic in lein-droid, it's a separate build system rather than a plugin. It doesn't use none of the usual leiningen commands, like lein compile or lein jar. So it depends how "generic" you really expect it to be.

— Reply to this email directly or view it on GitHub https://github.com/clojure-android/lein-droid/issues/131#issuecomment-133428149 .

Laurent Petit

alexander-yakushev commented 8 years ago

The point here is that most lein commands don't make sense in context of Android, and many lein-droid commands don't have Leiningen counterparts. And those commands that match semantically, they involve more than just updating the project map, they have different code inside.

If CCW calls leiningen.core.classpath/resolve-dependencies, then it will be enough for it to first call (leiningen.droid.classpath/init-hooks), and extra dependencies and classpath will be there. But the question is, again, what are you going to achieve once you have the classpath? All other actions have to run through lein-droid anyway.

laurentpetit commented 8 years ago

To answer your question first: once I have the classpath, Eclipse is happy. The java parts of the project don't show up as error markers anymore. The user can browse the java classes of Android. Basically every static bit of Eclipse / CCW works again.

So do I understand well that the "fix" for having things to work with lein-droid 0.4.0 is just to first (require 'leiningen.droid.classpath), then call its init-hooks method?

2015-08-21 17:25 GMT+02:00 Alexander Yakushev notifications@github.com:

The point here is that most lein commands don't make sense in context of Android, and many lein-droid commands don't have Leiningen counterparts. And those commands that match semantically, they involve more than just updating the project map, they have different code inside.

If CCW calls leiningen.core.classpath/resolve-dependencies, then it will be enough for it to first call (leiningen.droid.classpath/init-hooks), and extra dependencies and classpath will be there. But the question is, again, what are you going to achieve once you have the classpath? All other actions have to run through lein-droid anyway.

— Reply to this email directly or view it on GitHub https://github.com/clojure-android/lein-droid/issues/131#issuecomment-133462390 .

Laurent Petit

alexander-yakushev commented 8 years ago

Yes, that would be the easy way to make it work. If it doesn't,I'll think of something else.

Also, I suggest to bump to 0.4.1, fixed a subtle bug there.

On Fri, Aug 21, 2015, 19:38 Laurent Petit notifications@github.com wrote:

To answer your question first: once I have the classpath, Eclipse is happy. The java parts of the project don't show up as error markers anymore. The user can browse the java classes of Android. Basically every static bit of Eclipse / CCW works again.

So do I understand well that the "fix" for having things to work with lein-droid 0.4.0 is just to first (require 'leiningen.droid.classpath), then call its init-hooks method?

2015-08-21 17:25 GMT+02:00 Alexander Yakushev notifications@github.com:

The point here is that most lein commands don't make sense in context of Android, and many lein-droid commands don't have Leiningen counterparts. And those commands that match semantically, they involve more than just updating the project map, they have different code inside.

If CCW calls leiningen.core.classpath/resolve-dependencies, then it will be enough for it to first call (leiningen.droid.classpath/init-hooks), and extra dependencies and classpath will be there. But the question is, again, what are you going to achieve once you have the classpath? All other actions have to run through lein-droid anyway.

— Reply to this email directly or view it on GitHub < https://github.com/clojure-android/lein-droid/issues/131#issuecomment-133462390

.

Laurent Petit

— Reply to this email directly or view it on GitHub https://github.com/clojure-android/lein-droid/issues/131#issuecomment-133486238 .

laurentpetit commented 8 years ago

Unfortunately, it doesn't work

2015-08-21 19:04 GMT+02:00 Alexander Yakushev notifications@github.com:

Yes, that would be the easy way to make it work. If it doesn't,I'll think of something else.

Also, I suggest to bump to 0.4.1, fixed a subtle bug there.

On Fri, Aug 21, 2015, 19:38 Laurent Petit notifications@github.com wrote:

To answer your question first: once I have the classpath, Eclipse is happy. The java parts of the project don't show up as error markers anymore. The user can browse the java classes of Android. Basically every static bit of Eclipse / CCW works again.

So do I understand well that the "fix" for having things to work with lein-droid 0.4.0 is just to first (require 'leiningen.droid.classpath), then call its init-hooks method?

2015-08-21 17:25 GMT+02:00 Alexander Yakushev <notifications@github.com :

The point here is that most lein commands don't make sense in context of Android, and many lein-droid commands don't have Leiningen counterparts. And those commands that match semantically, they involve more than just updating the project map, they have different code inside.

If CCW calls leiningen.core.classpath/resolve-dependencies, then it will be enough for it to first call (leiningen.droid.classpath/init-hooks), and extra dependencies and classpath will be there. But the question is, again, what are you going to achieve once you have the classpath? All other actions have to run through lein-droid anyway.

— Reply to this email directly or view it on GitHub <

https://github.com/clojure-android/lein-droid/issues/131#issuecomment-133462390

.

Laurent Petit

— Reply to this email directly or view it on GitHub < https://github.com/clojure-android/lein-droid/issues/131#issuecomment-133486238

.

— Reply to this email directly or view it on GitHub https://github.com/clojure-android/lein-droid/issues/131#issuecomment-133496058 .

Laurent Petit

alexander-yakushev commented 8 years ago

It's weird that it doesn't. But there is in fact no other way around this. Leiningen doesn't support putting extra stuff on classpath, so I have to hack the get-classpath function to do that. Those hooks are your only option.

laurentpetit commented 8 years ago

OK, thanks for having explored the possibilities! I'll try to find a work-around on the CCW side. Cheers

2015-08-24 18:20 GMT+02:00 Alexander Yakushev notifications@github.com:

It's weird that it doesn't. But there is in fact no other way around this. Leiningen doesn't support putting extra stuff on classpath, so I have to hack the get-classpath function to do that. So those hooks are your only option.

— Reply to this email directly or view it on GitHub https://github.com/clojure-android/lein-droid/issues/131#issuecomment-134281791 .

Laurent Petit

alexander-yakushev commented 8 years ago

Actually, you should try out 0.4.2. I hail Mary moved the hook initialization to middleware, and now lein classpath called from the shell has all the necessary artifacts. Maybe this will work for you as well.

alexander-yakushev commented 8 years ago

@laurentpetit: Bump. All Leiningen commands see the new classpath now, so I will be really grateful if you check whether that works in your case too. Current version is 0.4.3.

laurentpetit commented 8 years ago

OK, will do ASAP ! Thanks !

2015-09-02 9:00 GMT+02:00 Alexander Yakushev notifications@github.com:

@laurentpetit https://github.com/laurentpetit: Bump. All Leiningen commands see the new classpath now, so I will be really grateful if you check whether that works in your case too. Current version is 0.4.3.

— Reply to this email directly or view it on GitHub https://github.com/clojure-android/lein-droid/issues/131#issuecomment-136956395 .

Laurent Petit

laurentpetit commented 8 years ago

So, I tried with the following project.clj (see at the end), with lein-droid 0.4.3. The Android jars are still not on the classpath, making it impossible to compile java files depending on e.g. android.app.Activity. Also, in Eclipse/CCW, the SplashActivity java file is full of red marks, since the classpath is incomplete.

Doing lein classpath on the command line also doesn't show android jars.

The project.clj file I used:

(defproject myccwapp/myccwapp "0.1.0-SNAPSHOT" :description "FIXME: Android project description" :url "http://example.com/FIXME" :license {:name "Eclipse Public License" :url "http://www.eclipse.org/legal/epl-v10.html"}

:global-vars {warn-on-reflection true}

:source-paths ["src/clojure" "src"] :java-source-paths ["src/java"] :javac-options ["-target" "1.6" "-source" "1.6" "-Xlint:-options"] :plugins [[lein-droid "0.4.3"]]

:dependencies [[org.clojure-android/clojure "1.7.0" :use-resources true] [neko/neko "4.0.0-alpha2"]] :profiles {:default [:dev]

         :dev
         [:android-common :android-user
          {:dependencies [[org.clojure/tools.nrepl "0.2.10"]]
           :target-path "target/debug"
           :android {:aot :all-with-unused
                     :rename-manifest-package "com.myapp.debug"
                     :manifest-options {:app-name "myccwapp (debug)"}}}]
         :release
         [:android-common
          {:target-path "target/release"
           :android
           {;; :keystore-path "/home/user/.android/private.keystore"
            ;; :key-alias "mykeyalias"
            ;; :sigalg "MD5withRSA"

            :ignore-log-priority [:debug :verbose]
            :aot :all
            :build-type :release}}]}

:android {;; Specify the path to the Android SDK directory. :sdk-path "/Users/laurentpetit/android-sdk-macosx/"

        ;; Try increasing this value if dexer fails with
        ;; OutOfMemoryException. Set the value according to your
        ;; available RAM.
        :dex-opts ["-JXmx4096M" "--incremental"]

        :target-version "19"
        :aot-exclude-ns ["clojure.parallel" "clojure.core.reducers"
                         "cider.nrepl" "cider-nrepl.plugin"
                         "cider.nrepl.middleware.util.java.parser"
                         #"cljs-tooling\..+"]})

2015-09-02 9:37 GMT+02:00 Laurent PETIT laurent.petit@gmail.com:

OK, will do ASAP ! Thanks !

2015-09-02 9:00 GMT+02:00 Alexander Yakushev notifications@github.com:

@laurentpetit https://github.com/laurentpetit: Bump. All Leiningen commands see the new classpath now, so I will be really grateful if you check whether that works in your case too. Current version is 0.4.3.

— Reply to this email directly or view it on GitHub https://github.com/clojure-android/lein-droid/issues/131#issuecomment-136956395 .

Laurent Petit

Laurent Petit

alexander-yakushev commented 8 years ago

Try doing lein classpath in a sample project, or in a newly created project. It works correctly for both on my machine.

laurentpetit commented 8 years ago

Indeed Alexander,

so now it's back to a CCW issue, I'll deal with it, thanks !

2015-09-05 13:07 GMT+02:00 Alexander Yakushev notifications@github.com:

Try doing `lein classpath

— Reply to this email directly or view it on GitHub https://github.com/clojure-android/lein-droid/issues/131#issuecomment-137943528 .

Laurent Petit

alexander-yakushev commented 8 years ago

No problem. I don't know why it doesn't work correctly with your current project (which I assume is quite empty), but the case is quite marginal, so let's call it a non-matter unless it surfaces again.