Carcigenicate
Carcigenicate

Reputation: 45826

Leiningen isn't checking Maven directory

I have a Clojure project that I'm writing using Intellij and the Cursive and Leiningen plugins.

My problem is, Leiningen isn't checking the central Maven directory when finding dependencies. water-time is my current project, and helpers is the project containing "helper" functions that I want to include.

First, my file structure:

helper's project.clj:

(defproject helpers "1"
  :description "General Helper Library"
  :dependencies [[org.clojure/clojure "1.8.0"]])

water-timer's project.clj:

(defproject water-timer "1"
    :description "A timer that reminds you to drink water"
      :dependencies [[org.clojure/clojure "1.8.0"]
                     [helpers "1"]]
      :main water-timer.tone-producer
      :aot [water-timer.tone-producer])

tone_producer.clj with irrelevant bits removed:

(ns tone-producer
  (:require [general-helpers :as g])
  (:gen-class))

(defn -main [& args]
  (println "Test!"))

Both projects were created using lein new. I had originally created them using Intellij, but in my previous question, it was recommended that I create the projects using leiningen, and then import them, so I recreated them from scratch.

If I then cd into helpers and run lein install, it successfully installs helpers into the Maven directory ([my-name]\.m2\repository\helpers\helpers\1\helpers-1.jar).

When I try to use the files though (by trying to create a uberjar using leiningen), it complains that it can't find the dependencies; even if I run lein deps prior:

"C:\Program Files (x86)\JetBrains\IntelliJ IDEA Community Edition 2016.1.2\jre\jre\bin\java" -Dvisualvm.id=91626738132760 -Dfile.encoding=UTF-8 -Dmaven.wagon.http.ssl.easy=false -Dmaven.wagon.rto=10000 -Didea.launcher.port=7541 "-Didea.launcher.bin.path=C:\Program Files (x86)\JetBrains\IntelliJ IDEA Community Edition 2016.1.2\bin" -classpath "C:\Users\slomi\.lein\self-installs\leiningen-2.6.1-standalone.jar;C:\Program Files (x86)\JetBrains\IntelliJ IDEA Community Edition 2016.1.2\lib\idea_rt.jar" com.intellij.rt.execution.application.AppMain clojure.main -m leiningen.core.main uberjar
Compiling water-timer.tone-producer
java.io.FileNotFoundException: Could not locate general_helpers__init.class or general_helpers.clj on classpath. Please check that namespaces with dashes use underscores in the Clojure file name., compiling:(tone_producer.clj:1:1)
Exception in thread "main" java.io.FileNotFoundException: Could not locate general_helpers__init.class or general_helpers.clj on classpath. Please check that namespaces with dashes use underscores in the Clojure file name., compiling:(tone_producer.clj:1:1)
    at clojure.lang.Compiler$InvokeExpr.eval(Compiler.java:3657)
    at clojure.lang.Compiler.compile1(Compiler.java:7474)
    at clojure.lang.Compiler.compile1(Compiler.java:7464)
    at clojure.lang.Compiler.compile(Compiler.java:7541)
    at clojure.lang.RT.compile(RT.java:406)
    at clojure.lang.RT.load(RT.java:451)
    at clojure.lang.RT.load(RT.java:419)
    at clojure.core$load$fn__5677.invoke(core.clj:5893)
    at clojure.core$load.invokeStatic(core.clj:5892)
    at clojure.core$load.doInvoke(core.clj:5876)
    at clojure.lang.RestFn.invoke(RestFn.java:408)
    at clojure.core$load_one.invokeStatic(core.clj:5697)
    at clojure.core$compile$fn__5682.invoke(core.clj:5903)
    at clojure.core$compile.invokeStatic(core.clj:5903)
    at clojure.core$compile.invoke(core.clj:5895)
    at user$eval20$fn__29.invoke(form-init7018212669773798479.clj:1)
    at user$eval20.invokeStatic(form-init7018212669773798479.clj:1)
    at user$eval20.invoke(form-init7018212669773798479.clj:1)
    at clojure.lang.Compiler.eval(Compiler.java:6927)
    at clojure.lang.Compiler.eval(Compiler.java:6917)
    at clojure.lang.Compiler.eval(Compiler.java:6917)
    at clojure.lang.Compiler.load(Compiler.java:7379)
    at clojure.lang.Compiler.loadFile(Compiler.java:7317)
    at clojure.main$load_script.invokeStatic(main.clj:275)
    at clojure.main$init_opt.invokeStatic(main.clj:277)
    at clojure.main$init_opt.invoke(main.clj:277)
    at clojure.main$initialize.invokeStatic(main.clj:308)
    at clojure.main$null_opt.invokeStatic(main.clj:342)
    at clojure.main$null_opt.invoke(main.clj:339)
    at clojure.main$main.invokeStatic(main.clj:421)
    at clojure.main$main.doInvoke(main.clj:384)
    at clojure.lang.RestFn.invoke(RestFn.java:421)
    at clojure.lang.Var.invoke(Var.java:383)
    at clojure.lang.AFn.applyToHelper(AFn.java:156)
    at clojure.lang.Var.applyTo(Var.java:700)
    at clojure.main.main(main.java:37)
Caused by: java.io.FileNotFoundException: Could not locate general_helpers__init.class or general_helpers.clj on classpath. Please check that namespaces with dashes use underscores in the Clojure file name.
    at clojure.lang.RT.load(RT.java:456)
    at clojure.lang.RT.load(RT.java:419)
    at clojure.core$load$fn__5677.invoke(core.clj:5893)
    at clojure.core$load.invokeStatic(core.clj:5892)
    at clojure.core$load.doInvoke(core.clj:5876)
    at clojure.lang.RestFn.invoke(RestFn.java:408)
    at clojure.core$load_one.invokeStatic(core.clj:5697)
    at clojure.core$load_one.invoke(core.clj:5692)
    at clojure.core$load_lib$fn__5626.invoke(core.clj:5737)
    at clojure.core$load_lib.invokeStatic(core.clj:5736)
    at clojure.core$load_lib.doInvoke(core.clj:5717)
    at clojure.lang.RestFn.applyTo(RestFn.java:142)
    at clojure.core$apply.invokeStatic(core.clj:648)
    at clojure.core$load_libs.invokeStatic(core.clj:5774)
    at clojure.core$load_libs.doInvoke(core.clj:5758)
    at clojure.lang.RestFn.applyTo(RestFn.java:137)
    at clojure.core$apply.invokeStatic(core.clj:648)
    at clojure.core$require.invokeStatic(core.clj:5796)
    at clojure.core$require.doInvoke(core.clj:5796)
    at clojure.lang.RestFn.invoke(RestFn.java:408)
    at tone_producer$loading__5569__auto____36.invoke(tone_producer.clj:1)
    at clojure.lang.AFn.applyToHelper(AFn.java:152)
    at clojure.lang.AFn.applyTo(AFn.java:144)
    at clojure.lang.Compiler$InvokeExpr.eval(Compiler.java:3652)
    ... 35 more
Compilation failed: Subprocess failed

Process finished with exit code 1

The thing that concerns me is the classpath it prints at the top of the error doesn't include the .m2 directory. It is my understanding that leiningen looks in that directory when trying to resolve dependencies, so I'm confused as to why it isn't looking there.

What am I missing here? All I want to do is make a executable jar that depends on a local source!

Upvotes: 0

Views: 352

Answers (1)

Chris Murphy
Chris Murphy

Reputation: 6509

Your require in tone_producer.clj should be: [helpers.general-helpers :as g].

In my experience it will be easier to develop your application if you don't try to create libraries right from the outset. Have one Cursive project and have a separate namespace for your intended library. Then you will be able to develop the two parts of your application together.

Upvotes: 1

Related Questions