:use fails in lein project - clojure

When I try to use
(ns eight-puzzle.core
(:use [clojure.contrib.seq :only (positions)]))
I get this error
java.io.FileNotFoundException: Could not locate clojure/contrib/seq__init.class or clojure/contrib/seq.clj on classpath:
RT.java:443 clojure.lang.RT.load
RT.java:411 clojure.lang.RT.load
core.clj:5530 clojure.core/load[fn]
core.clj:5529 clojure.core/load
RestFn.java:408 clojure.lang.RestFn.invoke
core.clj:5336 clojure.core/load-one
core.clj:5375 clojure.core/load-lib[fn]
core.clj:5374 clojure.core/load-lib
RestFn.java:142 clojure.lang.RestFn.applyTo
core.clj:619 clojure.core/apply
core.clj:5413 clojure.core/load-libs
RestFn.java:137 clojure.lang.RestFn.applyTo
core.clj:621 clojure.core/apply
core.clj:5507 clojure.core/use
RestFn.java:408 clojure.lang.RestFn.invoke
NO_SOURCE_FILE:1 eight-puzzle.core/eval8699[fn]
NO_SOURCE_FILE:1 eight-puzzle.core/eval8699
And this problem happens when ever I try to import anything in. Did I do something wrong when setting up clojure?

External dependencies, for projects managed by Leiningen, should be specified in the project.clj file, under the :dependencies key.
(defproject project1 "0.0.1"
:description "Something"
:dependencies [[org.clojure/clojure "1.5.1"]
[org.clojure/clojure-contrib "1.2.0"]
[clj-time "0.6.0"]])
Note: The entries in :dependencies can originate from either maven (maven central repository) or Clojars.
It also looks like you are using clojure.contrib. This library has been deprecated and you should upgrade, if you can. If you are only using clojure.contrib.seq/positions, take a look at this StackOverflow answer. You can also reimplement it with just clojure.core functions:
(defn positions [pred coll]
(for [[idx elt]
(map-indexed vector coll)
:when (pred elt)]
idx))

Related

http-kit dependency issue when updating sente-boot

Likely something wrong with my updated build.boot file: https://github.com/laforge49/sente-boot/blob/master/build.boot
(Been on the backend too long!)
I've tried changing the version of clojure and clojurescript. Previously I was not finding class RT, so I've made some progress at least.
Here's my dependencies:
:dependencies '[
[org.clojure/clojure "1.9.0" :scope "provided"]
[org.clojure/core.async "0.4.490"]
[org.clojure/clojurescript "1.9.562"]
[adzerk/boot-reload "0.5.1" :scope "test"]
[adzerk/boot-cljs "2.0.0" :scope "test"]
[com.taoensso/sente "1.14.0-RC2"] ; <--- Sente
[com.taoensso/timbre "4.10.0"]
[http-kit "2.3.0"]
[ring "1.7.1"]
[ring/ring-defaults "0.3.2"] ; Includes `ring-anti-forgery`, etc.
[compojure "1.6.1"] ; Or routing lib of your choice
[hiccup "1.0.5"] ; Optional, just for HTML
[com.cognitect/transit-clj "0.8.313"]
[com.cognitect/transit-cljs "0.8.256"]
[onetom/boot-lein-generate "0.1.3"]]
I get this error:
clojure.lang.ExceptionInfo: clojure/lang/IFn
data: {:file "org\\httpkit\\server.clj", :line 66}
java.lang.NoClassDefFoundError: clojure/lang/IFn
java.lang.ClassNotFoundException: clojure.lang.IFn
...
clojure.core/load/fn core.clj: 6007
clojure.core/load/invokeStatic core.clj: 6006
clojure.core/load core.clj: 5990
...

cloverage FileNotFoundException

I would like to use cloverage so I can check how much of my code base is tested by speclj. However after installing cloverage as a lein plugin and running: lein cloverage I see the following exception:
Exception in thread "main" java.io.FileNotFoundException:
Could not locate app/unit/core_spec__init.class or app/unit/core_spec.clj on classpath.
Please check that namespaces with dashes use underscores in the Clojure file name.,
compiling:(/private/var/folders/w_/yt926bqs21g44f257yz05ctsjbv948/T/form-init4597524674545750330.clj:1:125)
Caused by: java.io.FileNotFoundException: Could not locate app/component/core_spec__init.class or app/component/core_spec.clj on classpath. Please check that namespaces with dashes use underscores in the Clojure file name.
I've not used cloverage before so what to check if I'm using it correctly, has anyone come across this issue before?
This is what my project.clj looks like:
(defproject app version
:dependencies [
[org.clojure/clojure "1.8.0"]
[org.clojure/tools.logging "0.4.0"]
[org.clojure/tools.cli "0.3.5"]
[org.clojure/data.json "0.2.6"]
[org.postgresql/postgresql "9.4-1201-jdbc41"]
[org.slf4j/slf4j-log4j12 "1.7.25"]
[log4j/log4j "1.2.17" :exclusions [javax.mail/mail
javax.jms/jms
com.sun.jmdk/jmxtools
com.sun.jmx/jmxri]]
[metosin/compojure-api "1.1.11"]
[metosin/ring-swagger "0.24.3"]
[compojure "1.6.0"]
[cheshire "5.8.0"]
[ring "1.6.3"]
[ring/ring-json "0.4.0"]
[ring-logger "0.7.7"]
[environ "1.1.0"]
[korma "0.4.3"]
[blackwater "0.0.9"]
[prismatic/schema "1.1.7"]
[siili/humanize "0.1.1"]
[amazonica "0.3.117"]
]
:main app.cli.core
:plugins [
[lein-ring "0.12.1"]
[lein-cloverage "1.0.10"]
[speclj "3.3.2"]
]
:test-paths ["spec"]
:profiles {
:uberjar {:aot :all}
:user {
:plugins
[[cider/cider-nrepl "0.16.0"]
      [lein-kibit "0.1.6"]
      [nightlight/lein-nightlight "1.0.0"]
      [lein-cloverage "1.0.6"]
      [jonase/eastwood "0.2.3"]
      [lein-cloverage "1.0.9"]
[speclj "3.3.2"]]
}
:dev {
:dependencies [
[ring-mock "0.1.3"]
[clj-http "3.7.0"]
[org.clojure/data.json "0.2.6"]
[speclj "3.3.2"]
[clj-time "0.14.2"]
[listora/again "0.1.0"]
[environ "1.1.0"]
]
}
}
)
spec/app/component/core_spec.clj
(ns app.component.core_spec
(:require [speclj.core :refer :all]
[clojure.data.json :as json]
[clj-http.client :as client]
[clj-time.core :as t]
[again.core :as again]
[clj-time.format :as f]
[environ.core :refer [env]]))
(describe "app"
; tests and things...
)
Your problem is probably unrelated to Cloverage specifically. It looks like you're trying to require app.unit.core-spec, and that file either doesn't exist or hasn't been properly named (don't forget source files should have underscores, not dashes!)

Clojure dependencies for tests only

In my project.cli I have a dependency on clj-http that is used for tests only, with clj-http.client.
When I look at the uberjar file created for that project, I see that the class fils associated with this dependency are included. That makes the jar file bigger than it need be.
So, is there a way to define a dependency in clojure such that it is only used during tests, and is not included in the uberjar?
I know that I could do this in a pom.xml, but the pom.xml is generated when using clojure, so I only have recourse to something that works in the project.clj file.
To add more colour, my project.clj looks like this
(defproject aproject "0.1.0-SNAPSHOT"
:description "A project"
:dependencies [[org.clojure/clojure "1.8.0"]
[org.clojure/data.json "0.2.6"]
[compojure "1.5.0"]
[hiccup "1.0.5"]
[http-kit "2.1.18"]
[org.clojure/tools.logging "0.3.1"]
[ch.qos.logback/logback-classic "1.1.7"]
[ring/ring-devel "1.4.0"]]
:plugins [[lein-ring "0.9.7"]]
:ring {:handler aproject.core/app-routes}
:main ^:skip-aot aproject.core
:target-path "target/%s"
:resources-paths ["resources/"]
:profiles {:uberjar {:aot :all}
:dev {:dependencies [[peridot "0.4.3"]
[midje "1.8.3"]]
:plugins [[lein-midje "3.2.1"]]
:aliases {"test" ["midje"]}}
:test {:dependencies [[clj-http "3.5.0"]
[midje "1.8.3"]]
:plugins [[lein-midje "3.2.1"]]}
})
I am running the tests like this:
lein with-profile test midje :filters dt
What I am seeing is:
Exception in thread "main" java.io.FileNotFoundException: Could not locate midje/util/ecosystem__init.class or midje/util/ecosystem.clj on classpath., compiling:(/private/var/folders/7l/0fwd_7ls1m19q3_z1_tgg1w80000gn/T/form-init7253661442775183594.clj:1:125)
at clojure.lang.Compiler.load(Compiler.java:7391)
The filter probably does not affect this, but just in case the test looks like this:
(ns aproject.deployment.core
(:require [midje.sweet :refer :all]
[clj-http.client :as client]
[peridot.core :as p]
[clojure.data.json :as json]
[front-end.core :as fe]))
(facts "'aproject' deployed" :dt
(let [response (client/get "http://localhost:8080/ping")]
(response :status) => 200
))
I can see that the test profile is being triggered, and I seem to have the dependency for midje, and the plugin, but ...?
Thanks
Nathan
Add it to the :test profile, then run your tests with lein with-profile test midje :filters dt. Generate your uberjar as usual, lein uberjar and it shouldn't include the extra files.

Wrong types still compile with clojure core.typed?

The project file:
(defproject testclojure "0.1.0-SNAPSHOT"
:description "FIXME: write description"
:url "http://example.com/FIXME"
:license {:name "Eclipse Public License"
:url "http://www.eclipse.org/legal/epl-v10.html"}
:dependencies [[org.clojure/clojure "1.6.0"]
[org.clojure/core.typed "0.2.84"]
[alembic "0.3.2"]]
:main ^:skip-aot testclojure.core
:target-path "target/%s"
:profiles {:uberjar {:aot :all}})
The code:
(ns testclojure.core
(:gen-class)
(:require [clojure.core.typed :refer [ann AnyInteger check-ns]])
(:import [clojure.lang ISeq]))
(ann ^:no-check clojure.core/mod [AnyInteger AnyInteger -> AnyInteger])
(ann div-by [AnyInteger AnyInteger -> Boolean])
(defn div-by [x y]
(== (mod y x) 0))
(ann div-by-3-or-5 [AnyInteger -> Boolean])
(defn div-by-3-or-5 [x]
(or (div-by 3 x) (div-by 5 x)))
(ann euler1 [AnyInteger -> AnyInteger])
(defn euler1 [n]
(reduce + (filter div-by-3-or-5 (range n))))
(ann -main [-> nil] )
(defn -main []
(prn (euler1 "a")))
lein compile gives no error at all.
As the docstring for check-ns says:
Do not use check-ns within a checked namespace.
It is intended to be used at the REPL or within a unit test.
Suggested idiom for clojure.test: (is (check-ns 'your.ns))
If you put this in test/testclojure/core_test.clj:
(ns testclojure.core-test
(:require [clojure.test :refer :all]
[clojure.core.typed :refer [check-ns]]
testclojure.core))
(deftest core-typed
(is (check-ns 'testclojure.core)))
lein test will rightly complain about the type problem:
lein test testclojure.core-test
Initializing core.typed ...
Building core.typed base environments ...
Finished building base environments
"Elapsed time: 4251.270066 msecs"
core.typed initialized.
Start collecting testclojure.core
WARNING: Duplicate var annotation: clojure.core/mod
Finished collecting testclojure.core
Collected 1 namespaces in 833.458074 msecs
Not checking clojure.core.typed (does not depend on clojure.core.typed)
Start checking testclojure.core
Checked testclojure.core in 992.400431 msecs
Checked 2 namespaces in 1843.974821 msecs
Type Error (testclojure/core.clj:22:8) Function euler1 could not be applied to arguments:
Domains:
AnyInteger
Arguments:
(clojure.core.typed/Val "a")
Ranges:
AnyInteger
in: (euler1 "a")
in: (euler1 a)
lein test :only testclojure.core-test/core-typed
ERROR in (core-typed) (core.clj:4403)
expected: (check-ns (quote testclojure.core))
actual: clojure.lang.ExceptionInfo: Type Checker: Found 1 error
at clojure.core$ex_info.invoke (core.clj:4403)
clojure.core.typed.errors$print_errors_BANG_.invoke (errors.clj:234)
clojure.core.typed.check_ns_common$check_ns$fn__24049.invoke (check_ns_common.clj:114)
clojure.lang.AFn.applyToHelper (AFn.java:152)
clojure.lang.AFn.applyTo (AFn.java:144)
clojure.core$apply.invoke (core.clj:624)
clojure.core$with_bindings_STAR_.doInvoke (core.clj:1862)
clojure.lang.RestFn.invoke (RestFn.java:425)
clojure.core.typed.check_ns_common$check_ns.doInvoke (check_ns_common.clj:112)
clojure.lang.RestFn.invoke (RestFn.java:425)
clojure.lang.AFn.applyToHelper (AFn.java:156)
clojure.lang.RestFn.applyTo (RestFn.java:132)
clojure.core$apply.invoke (core.clj:628)
clojure.core.typed.check_ns_clj$check_ns.doInvoke (check_ns_clj.clj:23)
clojure.lang.RestFn.invoke (RestFn.java:410)
clojure.lang.AFn.applyToHelper (AFn.java:154)
clojure.lang.RestFn.applyTo (RestFn.java:132)
clojure.core$apply.invoke (core.clj:626)
clojure.core.typed$check_ns.doInvoke (typed.clj:2241)
clojure.lang.RestFn.invoke (RestFn.java:410)
clojure.lang.AFn.applyToHelper (AFn.java:154)
clojure.lang.RestFn.applyTo (RestFn.java:132)
clojure.core$apply.invoke (core.clj:624)
testclojure.core_test/fn (core_test.clj:7)
clojure.test$test_var$fn__7187.invoke (test.clj:704)
clojure.test$test_var.invoke (test.clj:704)
clojure.test$test_vars$fn__7209$fn__7214.invoke (test.clj:722)
clojure.test$default_fixture.invoke (test.clj:674)
clojure.test$test_vars$fn__7209.invoke (test.clj:722)
clojure.test$default_fixture.invoke (test.clj:674)
clojure.test$test_vars.invoke (test.clj:718)
clojure.test$test_all_vars.invoke (test.clj:728)
clojure.test$test_ns.invoke (test.clj:747)
clojure.core$map$fn__4245.invoke (core.clj:2559)
clojure.lang.LazySeq.sval (LazySeq.java:40)
clojure.lang.LazySeq.seq (LazySeq.java:49)
clojure.lang.Cons.next (Cons.java:39)
clojure.lang.RT.boundedLength (RT.java:1654)
clojure.lang.RestFn.applyTo (RestFn.java:130)
clojure.core$apply.invoke (core.clj:626)
clojure.test$run_tests.doInvoke (test.clj:762)
clojure.lang.RestFn.applyTo (RestFn.java:137)
clojure.core$apply.invoke (core.clj:624)
user$eval85$fn__140$fn__171.invoke (form-init5812871912759411988.clj:1)
user$eval85$fn__140$fn__141.invoke (form-init5812871912759411988.clj:1)
user$eval85$fn__140.invoke (form-init5812871912759411988.clj:1)
user$eval85.invoke (form-init5812871912759411988.clj:1)
clojure.lang.Compiler.eval (Compiler.java:6703)
clojure.lang.Compiler.eval (Compiler.java:6693)
clojure.lang.Compiler.load (Compiler.java:7130)
clojure.lang.Compiler.loadFile (Compiler.java:7086)
clojure.main$load_script.invoke (main.clj:274)
clojure.main$init_opt.invoke (main.clj:279)
clojure.main$initialize.invoke (main.clj:307)
clojure.main$null_opt.invoke (main.clj:342)
clojure.main$main.doInvoke (main.clj:420)
clojure.lang.RestFn.invoke (RestFn.java:421)
clojure.lang.Var.invoke (Var.java:383)
clojure.lang.AFn.applyToHelper (AFn.java:156)
clojure.lang.Var.applyTo (Var.java:700)
clojure.main.main (main.java:37)
Ran 1 tests containing 1 assertions.
0 failures, 1 errors.
Tests failed.

hiccup form-helper with compojure

Exception: Exception in thread "main" java.io.FileNotFoundException: Could not locate hiccup/form_helpers__init.class or hiccup/form_helpers.clj on classpath:
I'm trying to get a toy compojure app up and running. The original app was from CloudBees and their ClickStart app for Clojure/Compojure. I'm trying to add a simple form (that won't persist anything yet) using hiccup form_helpers but I'm getting a ClassNotFound exception. Here's what I've done:
project.clj:
(defproject mywebapp "0.1.0-SNAPSHOT"
:description "FIXME: write description"
:url "http://example.com/FIXME"
:dependencies [[org.clojure/clojure "1.4.0"]
[compojure "1.1.1"]
[hiccup "1.0.1"]]
:plugins [[lein-ring "0.7.3"]]
:ring {:handler mywebapp.routes/app}
:profiles
{:dev {:dependencies [[ring-mock "0.1.3"]]}})
views.clj:
(ns mywebapp.views
(:use [hiccup core page]
[hiccup form-helpers :only [form-to label text-area submit-button]]))
...
(defn shout-form []
[:div {:id "shout-form" }
(form-to [:post "/form"]
(label "shout" "What do you want to SHOUT?")
[:br]
(text-area "shout")
[:br]
(submit-button "SHOUT!"))])
...
Ah, looks like I just had an old example of forms in hiccup. form_helpers was from a previous version.
if I change my views.clj file from this:
(:use [hiccup form-helpers])
to look like this:
(:use [hiccup form])
(and presumably this would work though i haven't tested it):
(:use [hiccup form :only [form-to label text-area submit-button]])
I don't get the error anymore.
To clarify: the package used to be called "form_helpers" and is now simply called "form".