The following Wiki page describes a straightforward way of setting up Leiningen to use a mirror of Clojars.org: https://github.com/clojars/clojars-web/wiki/Mirrors
Based on this, I have put the following as my ~/.lein/profiles.clj:
{:user {:mirrors
{#"clojars" {:name "clojars mirror"
:url "https://clojars-mirror.tcrawley.org/repo/"}}}}
However, even with this profiles.clj, I can still see in e.g. Wireshark that lein is trying to connect to clojars.org instead of clojars-mirror.tcrawley.org. What setting am I missing?
My Leiningen version is
Leiningen 2.5.3 on Java 1.7.0_91 OpenJDK 64-Bit Server VM
I couldn't get a mirror working by modifying profile.clj either.
However I was able to get it working for a specific project.clj by adding this within defproject
:mirrors {#"clojars" {:name "Clojar Mirror"
:url "https://clojars-mirror.tcrawley.org/repo/"
:repo-manager true}}
Notes:
This came from the official Leiningen sample project.clj:
https://github.com/technomancy/leiningen/blob/master/sample.project.clj
I tried following the below for global setting in profile.clj (the syntax is somewhat different from yours) but had no luck:
https://github.com/technomancy/leiningen/issues/271#issuecomment-21108691
https://stackoverflow.com/a/17697119/617320
Related
before I start, you probably need to know three things:
I don't have Java background
I'm a Clojure newbie - started to learn it
question is related to my "training" package kennyfy
TL;DR version I'm not able to import/use my training package in a project
Longer version
I set myself a goal - write simple API which converts text to kennyspeak. Before that I've created a package (using default lein template).
I tried to import this package to my API.
Part of project.clj looks like this:
:repositories [["jitpack" "https://jitpack.io"]]
:dependencies [[com.github.radmen/clojure-kennyfy "0.1.2"]]
lein deps fetches the package without any problems.
When I try to use it, Clojure fails with following message:
kennyfy-api.core=> (radmen.kennyfy/kenny-speak "foo")
ClassNotFoundException radmen.kennyfy java.net.URLClassLoader.findClass (URLClassLoader.java:382)
I understand the error, yet I've no idea why this class is not imported.
I am quite sure, that this may be related to the metadata stored in the package, which results in failed imports.
What am I doing wrong?
Thank you
$ java -version
openjdk version "1.8.0_192"
OpenJDK Runtime Environment (build 1.8.0_192-b26)
OpenJDK 64-Bit Server VM (build 25.192-b26, mixed mode)
$ lein version
Leiningen 2.8.3 on Java 1.8.0_192 OpenJDK 64-Bit Server VM
Clojure 1.9.0
A clojure namespaces is loaded the first time it is required.
foo.core=> (radmen.kennyfy/kenny-speak "foo")
Execution error (ClassNotFoundException) at java.net.URLClassLoader/findClass (URLClassLoader.java:382).
radmen.kennyfy
foo.core=> (require '[radmen.kennyfy :as kennyfy])
nil
foo.core=> (kennyfy/kenny-speak "foo")
"mpfppfppf"
foo.core=> (radmen.kennyfy/kenny-speak "foo")
"mpfppfppf"
foo.core=>
This is asking for help regarding the same question as How to change Clojure or Lein's Clojure default version?
but is not an answer to that question. Should I have nevertheless have written it as an answer under that thread?
Specifying a Clojure version to be used when the "(lein repl)" command is issued outside of a project directory seems to be a natural thing to want. Of course there may be good design reasons for not allowing it, but do you think an error message like the following,
to be displayed when Leiningen detects that the ~/.lein/profiles.clj (or other relevant profile files) specify a different Clojure version from the one hard coded into Leiningen,
would be a good idea?
"specifying the Clojure version to be used with certain software, such as tools.nrepl and clojure-complete, is only allowed when this command is issued within a project directory"
A lot of people apparently have spent a lot of time on Stack Overflow trying to find out how to do this.
References:
"Updating ~/.lein/profiles.clj to {:repl {:dependencies [^:displace [org.clojure/clojure "1.9.0"]]}} does not seem to work. – Petrus Theron Jan 10 2018 at 9:05" How do you change Clojure version in Leiningen and LightTable?
"I asked technomancy on IRC just now. He said: "REPL's outside projects are hard coded to lein's version of clojure". – David J. Feb 24 '14 at 19:52" How to change Clojure or Lein's Clojure default version?
"this ^:displace trick will not work with tools.nrepl or clojure-complete." https://github.com/technomancy/leiningen/blob/master/doc/PROFILES.md
How to upgrade nrepl version of leiningen?
I think you may try to declare different profiles in your project.clj where each of them has its own Clojure version. For example:
:profiles
{;; :default [:base :system :user :provided :dev]
:server-jvm {:jvm-opts ^:replace ["-server"]}
:1.5 {:dependencies [[org.clojure/clojure "1.5.1"]]}
:1.6 {:dependencies [[org.clojure/clojure "1.6.0"]]}
:1.7 {:dependencies [[org.clojure/clojure "1.7.0"]]}
:1.8 {:dependencies [[org.clojure/clojure "1.8.0"]]}
:1.9 {:dependencies [[org.clojure/clojure "1.9.0"]]}}
Now that, when running any Lein command, specify a profile as follows:
lein with-profile 1.7 repl
The REPL session of Clojure 1.7 should start.
I grabbed that fragment from carmine sources. The official Lein profiles manual also has the same example.
How can I specify JVM flags so that they apply only to one alias in a project.clj file?
Specifically I want to try the built in server capability in Clojure 1.8.0.
I can do this with an uberjar and the command:
java -Dclojure.server.interactive="{:port 8411 :accept srv.action/process}" -jar target\uberjar\srv-0.1.0-SNAPSHOT-standalone.jar
But I was hoping I could set that -D... from within a lein alias.
I tried this
:aliases {
"serve" [:jvm-opts ["-Dclojure.server.interactive={:port 8411 :accept srv.action/process}"] "run"]
}
But I get
java.lang.ClassCastException: clojure.lang.Keyword cannot be cast to java.lang.String
Is it possible to do this?
I am using "Leiningen 2.6.1 on Java 1.8.0_92 Java HotSpot(TM) 64-Bit Server VM"
Leiningen profiles are definitely the way to do this. You can define a profile with any of the usual options, in your case :jvm-opts. In your profile.clj include something similar to the following:
:profiles {:clj-server {:jvm-opts ["-Dclojure.server.interactive={:port 8411 :accept srv.action/process}"]}}
Then you can tell leiningen you wish to use this profile via with-profile.
lein with-profile clj-server run
However, this will only use the options specified in the new profile. If you wish to activate the new profile in addition to the default profiles (dev, test, etc) you need to prepend the profile with a +.
lein with-profile +clj-server run
If you're lazy, like me, you can define an alias to run different tasks utilizing this newly defined profile:
:aliases {"clj-server-run" ["with-profile" "+clj-server" "run"]}
Then it's as easy as calling lein clj-server-run.
Hopefully this helps. I truly recommend reading through the leiningen documentation provided as well as its extremely useful.
I found an answer using profiles:
:profiles {:uberjar {:aot :all}
:server {:jvm-opts ["-Dclojure.server.interactive={:port 8411 :accept srv.action/process}"]}}
:aliases {
"serve" [ "with-profile" "server" "run"]})
I added a 'server' profile, which is allowed to specify its own :jvm-opts and then an alias to run that profile. It can be run with lein serve.
Any comments welcome.
As exercise to gain experience with ClojureScript I am writing a LightTable Plugin and I find no way to successfully use any standard library, I read the official documentation and even updated it to reflect latest changes regarding paths etc.. I followed this video and read the whole thread on the google group trying the proposed solutions, even working with the latest github source without luck.
I tried including core.async or cljs.http (I know the embedded nodejs alternative, just as example) following the proposed workflow by Irakli on the Google discussion. Simplest possible scenario:
$ lein version
Leiningen 2.5.0 on Java 1.7.0_55 Java HotSpot(TM) 64-Bit Server VM (Mac OS X 10.9.5) and LT latest (0.7.2)
$ lein new lt-plugin sample
plugin project.clj->
(defproject sample "0.0.1"
:dependencies [[org.clojure/clojure "1.5.1"]
[cljs-http "0.1.20"]
])
core file
(ns lt.plugins.sample
(:require [lt.object :as object]
[lt.objs.tabs :as tabs]
[lt.objs.command :as cmd]
[cljs-http.client :as http]
)
(:require-macros [lt.macros :refer [defui behavior]]))
(defn get-users
""
[]
(let [response (http/get "https://api.github.com/users" {:with-credentials? false})]
(prn (:status response))
(prn (map :login (:body response))))) ; evaluated correctly
(get-users) ; loads of errors like
WARNING: Referred var clojure.string/split does not exist at line 1 file:/Users/jaime/.m2/repository/noencore/noencore/0.1.16/noencore-0.1.16.jar!/no/en/core.cljs
I run lein deps, save, reload behaviours, restart, refresh plugin lists... all possible combinations tried, with the plugin folder within ~/Library/Application Support/LightTable/plugins or outside.
Should I download the jars and put them manually into a lib folder? I guess lein deps is not working as I expect
Yes currently seems that Cljs native or Cljx for that matter, doesn't resonate well with the LightTable UI.
Trying https://github.com/swannodette/om/wiki/Basic-Tutorial you'll find that it doesn't take much. You can create a LT keybinding to open browser tab, navigate to project folder index.html and make another for reloading (as autoreload is a work in progress I think). Then another tab with the Cljs file while you have the cljsbuild auto running, refresh browser and changes should be witnessed.
I've been trying to follow a number of tutorials on building a web app in Clojure, but I keep running into the same problem. To take the simplest case, I tried following this tutorial: http://drtom.ch/posts/2012-12-10/An_Introduction_to_Webprogramming_in_Clojure_-_Ring_and_Middleware/
When I get to the step that starts the server (run-jetty handler {:port 8383}), I get the following error:
NoSuchMethodError org.slf4j.helpers.MessageFormatter.arrayFormat(Ljava/lang/String;[Ljava/lang/Object;)Lorg/slf4j/helpers/FormattingTuple; org.eclipse.jetty.util.log.JettyAwareLogger.log (JettyAwareLogger.java:613)
I asked lien to show me the classpath, and sure enough, org.slf4j.helpers.MessageFormatter isn't in there anywhere.
I've run into this on pretty much every ring-based web tutorial I've tried, so either I've got something configured weird (I updated and reinstalled lein, blew away my ~/.m2 and rebuilt, etc), or something has changed in the myriad dependencies that get put together to make the classpath.
Any ideas what's going on here?
EDIT
I've got further information -- I created a VM in virtualbox, installed OpenJDK and lein, and created a project there. It worked fine. Since I had created it in a directory shared with the host, I then tried doing "lein ring server" in the same directory from the host, and it failed with the above error.
So I did "lein classpath" both in the vm and in the host and compared the results -- they're identical. I also checked that they're running the same build of the same JVM (OpenJDK 64-bit build 24.51-b03).
So, if they're running the same JVM with identical classpaths, what's left?
Can you try updating the dependencies like the following?
(defproject ..........
:dependencies [[org.clojure/clojure "1.5.1"]
[ring/ring-core "1.1.8"]
[ring/ring-jetty-adapter "1.1.8"]
[compojure "1.1.3"]]
:main quickstart.core
:min-lein-version "2.0.0"
:plugins [[lein-ring "0.8.10"]]
:ring {:handler quickstart.core/handler})
If you use the lein ring plugin as configured above, you can start the application like:
lein ring server