Leiningen: working with local git repo - clojure

I want to change something in incanter, so I created a fork on github and a clone of it on my laptop. Now, when I try to run tests with lein test I get these errors:
/Users/me/work/incanter$ lein test
Could not find artifact incanter:incanter-core:jar:1.5.8-SNAPSHOT in clojars (https://clojars.org/repo/)
Could not find artifact incanter:incanter-io:jar:1.5.8-SNAPSHOT in clojars (https://clojars.org/repo/)
Could not find artifact incanter:incanter-charts:jar:1.5.8-SNAPSHOT in clojars (https://clojars.org/repo/)
Could not find artifact incanter:incanter-mongodb:jar:1.5.8-SNAPSHOT in clojars (https://clojars.org/repo/)
Could not find artifact incanter:incanter-pdf:jar:1.5.8-SNAPSHOT in clojars (https://clojars.org/repo/)
Could not find artifact incanter:incanter-svg:jar:1.5.8-SNAPSHOT in clojars (https://clojars.org/repo/)
Could not find artifact incanter:incanter-latex:jar:1.5.8-SNAPSHOT in clojars (https://clojars.org/repo/)
Could not find artifact incanter:incanter-excel:jar:1.5.8-SNAPSHOT in clojars (https://clojars.org/repo/)
Could not find artifact incanter:incanter-sql:jar:1.5.8-SNAPSHOT in clojars (https://clojars.org/repo/)
Could not find artifact incanter:incanter-zoo:jar:1.5.8-SNAPSHOT in clojars (https://clojars.org/repo/)
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.
/Users/me/work/incanter$
I have not changed anything in the project.clj yet, here it is:
(defproject incanter "1.5.8-SNAPSHOT"
:description "Incanter is a Clojure-based, R-like statistical programming and data visualization environment."
:url "http://incanter.org/"
:license {:name "Eclipse Public License"
:url "http://www.eclipse.org/legal/epl-v10.html"}
:scm {:name "git" :url "https://github.com/incanter/incanter"}
:min-lein-version "2.0.0"
:dependencies [[incanter/incanter-core "1.5.8-SNAPSHOT"]
[incanter/incanter-io "1.5.8-SNAPSHOT"]
[incanter/incanter-charts "1.5.8-SNAPSHOT"]
[incanter/incanter-mongodb "1.5.8-SNAPSHOT"]
[incanter/incanter-pdf "1.5.8-SNAPSHOT"]
[incanter/incanter-svg "1.5.8-SNAPSHOT"]
[incanter/incanter-latex "1.5.8-SNAPSHOT"]
[incanter/incanter-excel "1.5.8-SNAPSHOT"]
[incanter/incanter-sql "1.5.8-SNAPSHOT"]
[incanter/incanter-zoo "1.5.8-SNAPSHOT"]
[org.clojure/clojure "1.5.1"]
]
:profiles {:dev {:resource-paths ["data"]}
:debug {:debug true}
:uberjar {:aot :all
:main incanter.main
:dependencies [[reply "0.3.0" :exclusions [org.clojure/clojure]]
[swingrepl "1.3.0"
:exclusions [org.clojure/clojure org.clojure/clojure-contrib]]
]
}
}
:repl-options {:init-ns incanter.irepl
:resource-paths ["data"]
:init (do
(set! *print-length* 500)
(use 'clojure.repl))
}
:jvm-opts ["-Xmx1g" "-Djsse.enableSNIExtension=false"
~(str "-Dincanter.home=" (System/getProperty "user.dir"))]
)
Any help will be greatly appreciated.

I took a look at the project. You must build any projects under /modules so that the snapshot-version 1.5.8-SNAPSHOT will be builded on your local .m2/
cd modules
cd incanter-core
lein install
...
Then I think it should work. Alternative you can reduce in the dependencies to 1.5.7.

You can use this approach:
Create jars of those projects(lein uberjar)
Then use command for each your jar:
mvn install:install-file \
-Dfile=maven_repository/my-project.jar \ ;;path to your jar(this is example)
-DgroupId= incanter \
-DartifactId= incanter \
-Dversion=0.1.0 \
-Dpackaging=jar \
-DgeneratePom=true
Then add deps to your project.clj and refresh leiningen:
[incanter/incanter "0.1.0"]
[groupId/artifactId "your-version"]
...

Related

Setting up leiningen profiles to multiplex between environments AND multiple mains

I currently have a setup for my Clojure project which allows me to toggle configuration from dev to test or prod by configuring profiles in Leiningen's project map. The section related to the profiles looks like this:
:main ^:skip-aot myproject.core
:target-path "target/%s"
:profiles {:uberjar {:aot :all}
:dev {:env {:clj-env :development
:database-uri "jdbc:postgresql://localhost:5432/db_dev"}}
:test {:env {:clj-env :test
:database-uri "jdbc:postgresql://localhost:5432/db_test"}}
:production {:env {:clj-env :production
:database-uri "jdbc:postgresql://localhost:5432/db"}}})
The issue is I would further like to enhance this and be able to toggle between multiple mains. I have seen in other posts that people usually achieve this by configuring the profiles like here.
What I don't know how to do is how to preserve the configuration I have so that profiles correspond to environments but also further configure it in order to be able to choose the main class by simply adding a parameter to lein run.
I have figured out that one way is obviously to keep having just one main class and add that multiplexing with actual Clojure code, but I was hoping to be able to do it via lein configuration.
After trying multiple options, the only way I have found to do this is via aliases.
First setting the :main option to nil, so the MANIFEST.MF doesn't have any Main.class set, and then simply adding a couple of aliases specifying which main class to run.
:main nil
:target-path "target/%s"
:aliases {"main1" ["run" "-m" "project.main1.core"]
"main2" ["run" "-m" "project.main2.core"]}

Clojure / Leiningen - package jar resource into clojars

I have a question similar to Deploy 3rd-party jar to clojars?
I've pushed a small project into clojars using lein deploy. That project relies on a jar dependency that I've simply put in a folder on the local drive and imported in my :resource-paths as per below:
(defproject cljblpapiwrapper "0.1.0-SNAPSHOT"
:description ""
:url ""
:license {:name "" :url ""}
:dependencies [[org.clojure/clojure "1.9.0"]]
:resource-paths ["resources/blpapi-3.8.8-2.jar"]
:repl-options {:init-ns cljblpapiwrapper.core})
Now upon importing my deployed clojars repo in another project, it fails to find classes within the jar repo. I'm getting this trace:
#error {
:cause com.bloomberglp.blpapi.CorrelationID
:via
[{:type clojure.lang.Compiler$CompilerException
:message java.lang.ClassNotFoundException: com.bloomberglp.blpapi.CorrelationID, compiling:(cljblpapiwrapper/core.clj:6:1)
:at [clojure.lang.Compiler load Compiler.java 7526]}
{:type java.lang.ClassNotFoundException
:message com.bloomberglp.blpapi.CorrelationID
:at [java.net.URLClassLoader findClass URLClassLoader.java 382]}]
:trace
[[java.net.URLClassLoader findClass URLClassLoader.java 382]
[clojure.lang.DynamicClassLoader findClass DynamicClassLoader.java 69]
[java.lang.ClassLoader loadClass ClassLoader.java 424]
[clojure.lang.DynamicClassLoader loadClass DynamicClassLoader.java 77]
[java.lang.ClassLoader loadClass ClassLoader.java 357]
...
Looks to me like the jar didn't make it to clojars - how can I package it within my repo? Alternatively, how can I push it separately to clojars?
thanks,
Did you try to download your lib from clojars? Use the jar command to unpack the *.jar file and see if the lib is there.
Look at this repo: https://github.com/cloojure/tupelo-datomic
In the ./resources dir there is a jar file: datomic-free-0.9.5661-everything.jar
You may need to play around with the syntax in project.clj to make the uberjar on clojars form correctly. You may need to publish the dependency JAR file on a separate maven-compatible repo. Options include:
Deps.co - Created by the host of The REPL podcast
AWS S3 - there is a lein plugin to help with this
I think you need to bind the jar as dependency in your project.clj, resource path tells uber jar just include the file.

Leiningen nREPL connect to remote repl with drawbridge

I'm trying to connect to a running clojure app package as a uberjar. I added [com.cemerick/drawbridge "0.0.7"] to my project.clj. But when I trying to connect with lein repl :connect http://ip:port/repl it is like it is not even connecting.
I get a stacktrace:
java.io.FileNotFoundException: Could not locate cemerick/drawbridge/client__init.class or cemerick/drawbridge/client.clj on classpath.
at clojure.lang.RT.load (RT.java:456)
clojure.lang.RT.load (RT.java:419)
clojure.core$load$fn__5677.invoke (core.clj:5893)
clojure.core$load.invokeStatic (core.clj:5892)
clojure.core$load.doInvoke (core.clj:5876)
....
clojure.lang.AFn.applyToHelper (AFn.java:171)
clojure.lang.Var.applyTo (Var.java:700)
clojure.main.main (main.java:37)
But when I run lein classpath I can find drawbridge there /root/.m2/repository/com/cemerick/drawbridge/0.0.7/drawbridge-0.0.7.jar
jar tf /root/.m2/repository/com/cemerick/drawbridge/0.0.7/drawbridge-0.0.7.jar
META-INF/MANIFEST.MF
META-INF/maven/com.cemerick/drawbridge/pom.xml
...
cemerick/drawbridge/client.clj
Any clues?
This looks like a plain old regression in Leiningen. I have submitted this as https://github.com/technomancy/leiningen/issues/2370.
Tested the same command on a older lein (clojure:lein-2.7.1) and it looks better. Something is maybe wrong on the server side but it connect at least.
Leiningen does not include Drawbridge anymore and you need to add it explicitly to plugins:
(defproject whatever "0.1.0-SNAPSHOT"
:plugins [[nrepl/drawbridge "0.2.1"]]))
See nREPL over HTTP(s) with Drawbridge in 2020

Leiningen missing test resources?

Leiningen provides a default directory for 'main' code, main resources, and test code, but nothing for test resources.
Coming from a maven background this is something I'd expect.
In that case, where should test resources live? Or a larger question, what's the philosophical reason why it wouldn't need a test resources directory
Test resources in Leiningen are managed using profiles. To set up a directory with test resources, you would add its path to the :resource-paths property of the :test profile (to make it available only to the test task) or :dev profile (to make it available to all dev tasks, e.g. test, run, repl, etc.)
Sample project.clj for a Maven-like project structure:
(defproject myproject "0.0.1-SNAPSHOT"
:source-paths ["src/main/clj"]
:test-paths ["src/test/clj"]
:resource-paths ["src/main/resources"]
:dev {:resource-paths ["src/test/resources"]})
When the :dev profile is active, its :resource-paths values are merged with the :resource-paths from the base project, giving you what you're looking for.
See the Leiningen docs for more information on profiles.

How to add multiple licenses to project.clj?

How do I add more than one license to leiningen's project.clj (my project is dually licensed)?
I know it is overdue, but just a summary for the benefit of the readers. The bug appears to be fixed, see https://github.com/technomancy/leiningen/issues/1166
The following project.clj works for me on Leiningen 2.2.0 on Java 1.7.0_09 Java HotSpot(TM) 64-Bit Server VM:
(defproject justatest "0.1.0-SNAPSHOT"
:description "FIXME: write description"
:url "http://example.com/FIXME"
:licenses [{:name "Eclipse Public License"
:url "http://www.eclipse.org/legal/epl-v10.html"}
{:name "Example License"
:url "http://example.com"}]
...