tools-deps

Discuss tools.deps.alpha, tools.build, and the clj/clojure command-line scripts! See also #depstar #clj-new
pithyless 2020-12-17T15:43:11.455400Z

If I fork a project and publish a jar under a different clojars groupid, can I somehow alias it back to the original groupid/name? Otherwise, my understanding is even if I use :override-deps the original project will be pulled in from any transitive deps, correct? Does that mean I need to track down all potential transitive deps that use this groupid/project-name and add an :exclusion?

pithyless 2020-12-17T15:44:11.456500Z

Normally, I'd just use the original groupid and point to a :git/url, but this particular project has some compiled java bits.

borkdude 2020-12-17T15:45:03.457300Z

@pithyless :classpath-overrides + nil might work too

borkdude 2020-12-17T15:45:39.457800Z

although that might still pull in the transitive deps

borkdude 2020-12-17T15:47:10.459300Z

but if your fork pulls in the same transitive deps you will probably get the newest of those transitive deps

pithyless 2020-12-17T15:48:08.460Z

OK, great; thanks @borkdude

pithyless 2020-12-17T16:26:59.460700Z

Confirming that :classpath-overrides + nil works like a charm; cheers!

dominicm 2020-12-17T18:09:57.461200Z

There's a jira for this fwiw

Eugen 2020-12-17T20:35:23.463100Z

hi, can I run a java class as a Clojure alias? I'm trying to generate bindings for an antlr grammar using the java tool: The gradle code I want to replicate is:

apply plugin: 'java'
repositories {
    jcenter()
}
dependencies {
    runtime 'org.antlr:antlr4:4.5.2'
}
task generateParser(type:JavaExec) {
   main = 'org.antlr.v4.Tool'
   classpath = sourceSets.main.runtimeClasspath
   args = ['-Dlanguage=JavaScript', 'todo.g4', '-o', 'static/generated-parser']
}

Eugen 2020-12-17T20:35:49.463600Z

how can I specify the main class: org.antlr.v4.Tool ?

alexmiller 2020-12-17T20:42:52.464500Z

you can specify clj -M -m org.antlr.v4.Tool if you just want to invoke that main class with the deps classpath

alexmiller 2020-12-17T20:45:33.465800Z

you can pack this into an alias too using :main-opts and :replace-deps or :extra-deps to specify the deps

alexmiller 2020-12-17T20:46:19.466300Z

and not sure if that -D is a jvm property or a class arg. If the former, use :jvm-opts for that one

alexmiller 2020-12-17T20:46:29.466500Z

(note that you can't remove Clojure itself from the classpath - it assumes you are running Clojure programs)

Eugen 2020-12-17T20:53:45.467400Z

thanks @alexmiller. How I can specify org.antlr.v4.Tool in deps.edn ? Now I have:

:antlr-js-target {:main-fn ["org.antlr.v4.Tool"]
                   :main-opts ["grammars/timeclock.g4" "-o" "static/generated/js-parser"]
                   :jvm-opts ["-Dlanguage=JavaScript"]}

alexmiller 2020-12-17T20:55:05.468Z

:antlr-js-target {:main-opts ["-m" "org.antlr.v4.Tool" "grammars/timeclock.g4" "-o" "static/generated/js-parser"]
                   :jvm-opts ["-Dlanguage=JavaScript"]}

Eugen 2020-12-17T20:55:18.468200Z

thank you 🙂

Eugen 2020-12-17T21:12:20.469100Z

unfortunatelly it does not work 😞

hledger-grammars$ clj -M:antlr-js-target
Execution error (FileNotFoundException) at clojure.main/main (main.java:40).
Could not locate org/antlr/v4/Tool__init.class, org/antlr/v4/Tool.clj or org/antlr/v4/Tool.cljc on classpath.

Full report at:
/tmp/clojure-8595960239732774942.edn
I have checked the dependencies and they should be on the classpath
{:clojure.main/message
 "Execution error (FileNotFoundException) at clojure.main/main (main.java:40).\nCould not locate org/antlr/v4/Tool__init.class, org/antlr/v4/Tool.clj or org/antlr/v4/Tool.cljc on classpath.\n",
 :clojure.main/triage
 {:clojure.error/class java.io.FileNotFoundException,
  :clojure.error/line 40,
  :clojure.error/cause
  "Could not locate org/antlr/v4/Tool__init.class, org/antlr/v4/Tool.clj or org/antlr/v4/Tool.cljc on classpath.",
  :clojure.error/symbol clojure.main/main,
  :clojure.error/source "main.java",
  :clojure.error/phase :execution},
 :clojure.main/trace
 {:via
  [{:type java.io.FileNotFoundException,
    :message
    "Could not locate org/antlr/v4/Tool__init.class, org/antlr/v4/Tool.clj or org/antlr/v4/Tool.cljc on classpath.",
    :at [clojure.lang.RT load "RT.java" 462]}],
  :trace
  [[clojure.lang.RT load "RT.java" 462]
   [clojure.lang.RT load "RT.java" 424]
   [clojure.core$load$fn__6839 invoke "core.clj" 6126]
   [clojure.core$load invokeStatic "core.clj" 6125]
   [clojure.core$load doInvoke "core.clj" 6109]
   [clojure.lang.RestFn invoke "RestFn.java" 408]
   [clojure.core$load_one invokeStatic "core.clj" 5908]
   [clojure.core$load_one invoke "core.clj" 5903]
   [clojure.core$load_lib$fn__6780 invoke "core.clj" 5948]
   [clojure.core$load_lib invokeStatic "core.clj" 5947]
   [clojure.core$load_lib doInvoke "core.clj" 5928]
   [clojure.lang.RestFn applyTo "RestFn.java" 142]
   [clojure.core$apply invokeStatic "core.clj" 667]
   [clojure.core$load_libs invokeStatic "core.clj" 5985]
   [clojure.core$load_libs doInvoke "core.clj" 5969]
   [clojure.lang.RestFn applyTo "RestFn.java" 137]
   [clojure.core$apply invokeStatic "core.clj" 667]
   [clojure.core$require invokeStatic "core.clj" 6007]
   [clojure.main$main_opt invokeStatic "main.clj" 514]
   [clojure.main$main_opt invoke "main.clj" 510]
   [clojure.main$main invokeStatic "main.clj" 664]
   [clojure.main$main doInvoke "main.clj" 616]
   [clojure.lang.RestFn applyTo "RestFn.java" 137]
   [clojure.lang.Var applyTo "Var.java" 705]
   [clojure.main main "main.java" 40]],
  :cause
  "Could not locate org/antlr/v4/Tool__init.class, org/antlr/v4/Tool.clj or org/antlr/v4/Tool.cljc on classpath."}}

alexmiller 2020-12-17T21:15:33.469700Z

can you double-check with clj -Spath -M:antlr-js-target ?

alexmiller 2020-12-17T21:16:31.470100Z

oh, it's looking to load a clojure class here

alexmiller 2020-12-17T21:16:38.470400Z

maybe you can't actually do this :)

Eugen 2020-12-17T21:17:09.470900Z

clj -Spath -M:antlr-js-target
src:resources:/home/ieugen/.m2/repository/clj-antlr/clj-antlr/0.2.7/clj-antlr-0.2.7.jar:/home/ieugen/.m2/repository/org/clojure/clojure/1.10.1/clojure-1.10.1.jar:/home/ieugen/.m2/repository/org/antlr/antlr4/4.8-1/antlr4-4.8-1.jar:/home/ieugen/.m2/repository/org/antlr/antlr4-runtime/4.8-1/antlr4-runtime-4.8-1.jar:/home/ieugen/.m2/repository/org/clojure/tools.logging/1.1.0/tools.logging-1.1.0.jar:/home/ieugen/.m2/repository/org/clojure/core.specs.alpha/0.2.44/core.specs.alpha-0.2.44.jar:/home/ieugen/.m2/repository/org/clojure/spec.alpha/0.2.176/spec.alpha-0.2.176.jar:/home/ieugen/.m2/repository/com/ibm/icu/icu4j/61.1/icu4j-61.1.jar:/home/ieugen/.m2/repository/org/abego/treelayout/org.abego.treelayout.core/1.0.3/org.abego.treelayout.core-1.0.3.jar:/home/ieugen/.m2/repository/org/antlr/ST4/4.3/ST4-4.3.jar:/home/ieugen/.m2/repository/org/antlr/antlr-runtime/3.5.2/antlr-runtime-3.5.2.jar:/home/ieugen/.m2/repository/org/glassfish/javax.json/1.0.4/javax.json-1.0.4.jar

alexmiller 2020-12-17T21:21:18.473800Z

could just invoke with a Clojure expression, like?

:antlr-js-target {:main-opts ["-e" "(org.antlr.v4.Tool/main,\"grammars/timeclock.g4\",\"-o\",\"static/generated/js-parser\")"]
                   :jvm-opts ["-Dlanguage=JavaScript"]}

alexmiller 2020-12-17T21:22:24.474200Z

as you can tell, you're kind of out of the main usage of this tool (running clojure programs)

Eugen 2020-12-17T21:26:47.476Z

yes, seems like it is. I am tryng to use this tool to do some project building. Seems to be related to what it is used for in clojure

Eugen 2020-12-17T21:27:09.476500Z

almost there, now it needs to pass a single array instead of 3 args

Eugen 2020-12-17T21:27:12.476800Z

Syntax error (IllegalArgumentException) compiling . at (REPL:1:1).
No matching method main found taking 3 args for class org.antlr.v4.Tool

Eugen 2020-12-17T21:28:37.477100Z

I'll try to use object-array

Eugen 2020-12-17T21:32:01.477400Z

failed with ["-e" "(org.antlr.v4.Tool/main,(object-array,[,\"grammars/timeclock.g4\",\"-o\",\"static/generated/js-parser\",],),)"]

class [Ljava.lang.Object; cannot be cast to class [Ljava.lang.String; ([Ljava.lang.Object; and [Ljava.lang.String; are in module java.base of loader 'bootstrap') 

alexmiller 2020-12-17T21:32:48.477700Z

oh right. it's probably actually a String[]

alexmiller 2020-12-17T21:34:22.478300Z

["-e" "(org.antlr.v4.Tool/main,(into-array,[\"grammars/timeclock.g4\",\"-o\",\"static/generated/js-parser\",],),)"]

alexmiller 2020-12-17T21:34:34.478600Z

^^ will derive the array type from the first arg

Eugen 2020-12-17T22:09:36.479900Z

yes, this works but it does not take into account the jvm option: :jvm-opts ["-Dlanguage=JavaScript"] . It generates java classes instead of js. I could set the property in the expression

Eugen 2020-12-17T22:23:00.480700Z

I managed to get it working by checking the java code. It seems they accept -Dlanguage as an argument also so this worked: :antlr-js-target {:main-opts ["-e" "(org.antlr.v4.Tool/main,(into-array,[\"-Dlanguage=JavaScript\",\"grammars/timeclock.g4\",\"-o\",\"static/generated/js-parser\"]))"]}

Eugen 2020-12-17T22:24:50.482700Z

thank you @alexmiller for your help. Could calling Java from deps.edn be made easier? Would JavaExec or an Exec be a feature?

alexmiller 2020-12-17T22:41:17.483900Z

it could be made easier, but I don't really see it as the purpose of this tool so I'm not really interested in adding stuff for it

👍 1