Fork me on GitHub
#tools-deps
<
2020-12-17
>
pithyless15:12:11

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?

pithyless15:12:11

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

borkdude15:12:03

@pithyless :classpath-overrides + nil might work too

borkdude15:12:39

although that might still pull in the transitive deps

borkdude15:12:10

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

pithyless15:12:08

OK, great; thanks @borkdude

pithyless16:12:59

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

dominicm18:12:57

There's a jira for this fwiw

Eugen20:12:23

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']
}

Eugen20:12:49

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

Alex Miller (Clojure team)20:12:52

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

Alex Miller (Clojure team)20:12:33

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

Alex Miller (Clojure team)20:12:19

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

Alex Miller (Clojure team)20:12:29

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

Eugen20:12:45

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"]}

Alex Miller (Clojure team)20:12:05

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

Eugen20:12:18

thank you 🙂

Eugen21:12:20

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."}}

Alex Miller (Clojure team)21:12:33

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

Alex Miller (Clojure team)21:12:31

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

Alex Miller (Clojure team)21:12:38

maybe you can't actually do this :)

Eugen21:12:09

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

Alex Miller (Clojure team)21:12:18

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"]}

Alex Miller (Clojure team)21:12:24

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

Eugen21:12:47

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

Eugen21:12:09

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

Eugen21:12:12

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

Eugen21:12:37

I'll try to use object-array

Eugen21:12:01

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') 

Alex Miller (Clojure team)21:12:48

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

Alex Miller (Clojure team)21:12:22

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

Alex Miller (Clojure team)21:12:34

^^ will derive the array type from the first arg

Eugen22:12:36

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

Eugen22:12:00

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\"]))"]}

Eugen22:12:50

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

Alex Miller (Clojure team)22:12:17

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

👍 3