Fork me on GitHub
#beginners
<
2022-06-04
>
dumrat02:06:30

Hi, I'm in corporate net and I don't have access to clojars or any outside repo. We have a local repository and after configuring ~\.lein\profiles.clj to use these repos, I am able to get stuff working. But this doesn't work for lein templates. example: lein new luminus newproj fails:

Failed to resolve version for luminus:lein-template:jar:RELEASE: could not find metadata luminus:lein-template:maven-metadata.xml in local...
What can I do here? Due to corporate restrictions, I can't manually download jars either so everything sucks.

hiredman02:06:19

Templates are maven artifacts, if your maven repo doesn't have them you cannot use them

dumrat02:06:50

My maven repo has luminus/lein-template/[multiple versions]

dumrat02:06:36

I see inside each version two files: lein-template-2.9.10.71.pom lein-template-2.9.10.71.pom.asc

dumrat02:06:02

But still error occurs when I try to use the template

dumrat02:06:13

There are cases where there's jars. Example lein-template-3.10.6.jar lein-template-3.10.6.pom

hiredman03:06:43

But there might be a plugin-repositories thing

seancorfield03:06:12

@UC1DTFY1G Have you tried specifying the version of one that you have in your corporate repo, rather than letting it use RELEASE? I can't remember how you do that with lein new tho' (I haven't used Leiningen for years).

dumrat03:06:44

@U04V70XH6 Tried this with specifying --template-version parameter with lein new luminus service --template-version 3.10.6 . However, it looks like lein is trying to download from outside repos only: Could not transfer artifact luminus:lein-template:jar:3.10.6 from/to central (): Could not transfer artifact luminus:lein-template:jar:3.10.6 from/to clojars (): Could not transfer artifact luminus:lein-template:jar:3.10.6 from/to central ( such host is known ( (Errors might have typos as I'm typing manually - can't access slack from corp either)

dumrat03:06:47

Looks like lein is disregarding [:user :repositories] entry in ~\.lein\profiles.clj

dumrat03:06:58

I'm on Windows if that's of any use

dumrat03:06:22

Oh, I added [:user :plugin-repositories] section and added local repos there and that seems to do the trick

dumrat03:06:43

What's the rationale for plugin repos to be different from repositories in profiels.clj?

seancorfield03:06:44

Probably just because plugins have separate dependencies to the regular project dependencies -- so it's makes sense for them to be able to have separate repo specifications.

👍 1
Stef Coetzee11:06:06

Such a nice example that gets right to the point: https://clojurians.slack.com/archives/C053AK3F9/p1587697593451800?thread_ts=1587696826.448300&amp;cid=C053AK3F9 Made a similar mistake in the map returned by a handler. That is, in the map the handler returns have :body {} as opposed to :body "" . You end up with this error message: java.lang.IllegalArgumentException: No implementation of method: :write-body-to-stream of protocol: #'ring.core.protocols/StreamableResponseBody found for class: clojure.lang.PersistentArrayMap Thanks @dpsutton! gratitude

Jim Strieter13:06:14

Sorry if this is dumb. I want to import the class TDistribution from org.apache.commons/commons-math3, so I added this to project.clj:

:dependencies [ ;; other deps
              [org.apache.commons/commons-math3 "3.6.1"]]
At the repl, I type:
(require '[org.apache.commons.math3.distribution.TDistribution :refer :all])
and get this:
Execution error (FileNotFoundException) at clojure-trade-bot-2.core/eval1605 (form-init6615340479110970914.clj:1).
Could not locate org/apache/commons/math3/distribution/TDistribution__init.class, org/apache/commons/math3/distribution/TDistribution.clj or org/apache/commons/math3/distribution/TDistribution.cljc on classpath.
The part that is strange to me is that the REPL completes the names when I press tab. What am I doing wrong?

Alex Miller (Clojure team)13:06:21

You import Java classes

Alex Miller (Clojure team)13:06:46

require is for Clojure namespaces

Jim Strieter13:06:26

I tried this:

(import '[org.apache.... :refer :all])
and I get this:
Syntax error macroexpanding clojure.core/import at (/tmp/form-init6615340479110970914.clj:1:1).
:refer - failed: simple-symbol? at: [:package-list :quoted-spec :spec :classes] spec: :clojure.core.specs.alpha/package-list
[org.apache.commons.math3.distribution.TDistribution :refer :all] - failed: simple-symbol? at: [:class :quoted-spec :spec] spec: :clojure.core.specs.alpha/quotable-import-list
[org.apache.commons.math3.distribution.TDistribution :refer :all] - failed: simple-symbol? at: [:package-list :spec :classes] spec: :clojure.core.specs.alpha/package-list
(quote [org.apache.commons.math3.distribution.TDistribution :refer :all]) - failed: simple-symbol? at: [:class :spec] spec: :clojure.core.specs.alpha/quotable-import-list

delaguardo13:06:54

import doesn't support modifiers as require. https://clojuredocs.org/clojure.core/import

Jim Strieter13:06:50

Tried this:

(import org.apache....)
(no []'s) and it worked. Thanks!

Jim Strieter13:06:25

Now that I have successfully imported org.apache.commons.math3.distribution.TDistribution (http://haifengl.github.io/api/java/smile/stat/distribution/TDistribution.html#cdf-double-) I am trying to access the cdf method:

(def x (new TDistribution 1))
(.cdf x 42)
and I get this error:
Execution error (IllegalArgumentException) at clojure-trade-bot-2.core/eval1652 (form-init6615340479110970914.clj:1).
No matching method cdf found taking 1 args for class org.apache.commons.math3.distribution.TDistribution
Why can't Clojure find that method? I thought to access a method you do something like this:
(.method-name instance-name &whatever-parameters)

delaguardo14:06:59

Because you import wrong class Your link goes to smile.stat.distribution.TDistribution

Jim Strieter14:06:31

The import statement is:

(import org.apache.commons.math3.distribution.TDistribution)

delaguardo14:06:02

But cdf method is in another class

Jim Strieter17:06:42

I feel like an idiot

Jim Strieter17:06:07

I went to documentation for class I did import and magically it works! Thanks @U04V4KLKC 🙂