Fork me on GitHub
#tools-deps
<
2021-03-17
>
dev-hartmann12:03:38

@borkdude just a quick follow up question, if you don’t mind:

dev-hartmann12:03:30

I added the Java project with :root/local “absolute path to root containing Pom”

dev-hartmann12:03:11

But when I try to import an object from the dependency inside my namespace

borkdude12:03:15

:local/root

dev-hartmann12:03:41

Sure, sry have it that way

dev-hartmann12:03:19

Still get a class not found exception

dev-hartmann12:03:53

Seems like the project is loaded correctly, as I had to add my private nexus mvn repo

borkdude12:03:05

Try clojure -Spath and check if the directory with your classes is in there

dev-hartmann12:03:06

Yes, it’s there

borkdude12:03:18

ok, then it should work, or the class isn't there somehow

dev-hartmann12:03:40

That’s strange

dev-hartmann12:03:15

Do I need to add more dirs to the paths vector into my deps.edn to make it work?

borkdude13:03:00

dirs in :paths are just the first dirs on the clojure -Spath, the rest come from your dependencies

dev-hartmann13:03:21

Hm, I’ll try pointing to a .jar file of the project

dev-hartmann13:03:47

Still class not found

dev-hartmann13:03:16

I need to point to the root of the project containing the Pom.xml, correct?

borkdude13:03:20

yes. but if your pom.xml doesn't include your generated classes on the classpath, then they won't be found

borkdude13:03:57

this is why I asked you to inspect clojure -Spath. that should contain the dir with your generated classes

dev-hartmann13:03:10

That it didn’t

dev-hartmann13:03:18

Then I need to include them

dev-hartmann13:03:36

I just saw it was including the base dir of my code

dev-hartmann13:03:09

.../src/java...

borkdude13:03:32

what is not on the classpath, cannot be found, that's how the classpath works :)

dev-hartmann13:03:09

Sure, makes sense

dev-hartmann13:03:36

I thought since it had the root of my project it could check all the files under that dir

dev-hartmann13:03:50

Tbh I thought that the .java files were enough

dev-hartmann13:03:04

As you might see not a java specialist

borkdude13:03:38

clojure does not do any compilation for .java files, you need .class files

dev-hartmann13:03:40

I can see that building the java application generates a target/classes folder

dev-hartmann13:03:52

Makes perfect sense

dev-hartmann13:03:47

How do I make mvn aware there is a target/class folder?

borkdude13:03:48

I'm not a mvn expert either, but if you need to add target/classes to the clojure classpath you could just add a deps.edn in this other project containing {:paths ["target/classes"]}

borkdude13:03:21

and then you use that other project using :local/root and it should pick up the target/classes dir

dev-hartmann13:03:51

Will try that, thx again and sry for nagging.

dev-hartmann13:03:16

ok, with the additional deps.edn in the java project

dev-hartmann13:03:23

and local/root with :deps/manifest :deps it worked

dev-hartmann13:03:45

even company autocompletion works and is suggesting the correct imports

dev-hartmann13:03:50

but when I eval the namespace

dev-hartmann13:03:16

clojure -Spath clearly has the folder there

dev-hartmann13:03:22

and the folder is not empty 🙂

dev-hartmann13:03:59

I can even see the javadoc and the info on what it extends

rickmoynihan14:03:57

Since upgrading tools.deps to the latest I’m seeing warnings like this: WARNING: Specified path /Users/rick/.gitlibs/libs/swirrl/muttnik-dev-files-cogs/116624aa86f42b765d2eda3b83a64c3981746a8e/shared/resources is external to project /Users/rick/.gitlibs/libs/swirrl/muttnik-dev-files-cogs/116624aa86f42b765d2eda3b83a64c3981746a8e/cogs

alexmiller14:03:59

clj --version

rickmoynihan14:03:24

sorry Clojure CLI version 1.10.3.814

alexmiller14:03:58

that error looks like a relative path in muttnik-dev-files-cogs that goes outside the project

rickmoynihan14:03:25

yes, but those deps are pulled in like this:

swirrl/muttnik-dev-files-cogs {:git/url "[email protected]:Swirrl/muttnik-dev-files.git"
                                                                 :sha "116624aa86f42b765d2eda3b83a64c3981746a8e"
                                                                 :deps/manifest :deps
                                                                 :deps/root "cogs"}

rickmoynihan14:03:06

oh wait I think see what you’re saying… 👀

rickmoynihan14:03:48

the deps edn file in the cogs folder there looks like this: {:paths ["resources", "../shared/resources"]}

alexmiller14:03:09

This warning was added in https://clojure.org/releases/tools#v1.10.2.790 and eventually external references not be allowed

rickmoynihan14:03:45

ok so I guess I need to pull in shared as an extra dep

rickmoynihan14:03:48

oh actually I see that the shared directory has been deleted anyway. I just need to clear out the cruft. Thanks.

alexmiller14:03:12

yeah, local deps would be an ok way to accomplish the same

rickmoynihan14:03:16

does that work for transitive deps? Sorry the dev-files repo (above) is consumed in another project as a direct dependency, and the dev-files repo was the one with "../shared/resources" in it. Would a local dep resolve properly in the consuming project?

rickmoynihan14:03:01

awesome that’s good to know

rickmoynihan14:03:14

though looks like I don’t have this problem anymore 🙂

rickmoynihan14:03:39

Presumably the move to using git proper, also means issues where JGit had a 100mb max file size limit are now also fixed?

alexmiller14:03:02

I wasn't aware of that one but it will match whatever you get with git

👍 1
alexmiller14:03:29

since it is git :)

borkdude14:03:39

@dev-hartmann try just clj and then type the classname you want to find directly in the REPL. Post the output here along with ls the-other-project/target/classes/<the-class>.class

borkdude14:03:22

also post the snippet where that directory occurs on your classpath as output with clojure -Spath

dev-hartmann14:03:12

@borkdude you mean open a repl with clj and try to import the classname, right?

borkdude14:03:26

not even import, just try the fully qualified class name

dev-hartmann14:03:25

I feel so stupid

dev-hartmann14:03:11

the class with package is net.company.plugin.PluginFactory

dev-hartmann14:03:18

and I tried to import it like this:

dev-hartmann14:03:37

import [net.company.plugin.PluginFactory PluginFactory]

dev-hartmann14:03:50

thx for all the help, works now!

👍 1
Chase15:03:15

so if I want to run a random function like clj -X practice.scratch/my-fn how am I supposed to feed in the arguments to that function? I'm getting a key is missing value error so I assume it has to be a map but my attempts at making it a map are failing too

Chase15:03:49

I specifically want to feed that function a file name that is in my resources folder

alexmiller15:03:52

-X expects to invoke a function that takes a map

alexmiller15:03:58

the args are key/value pairs

alexmiller15:03:11

which will go in the map passed to the function

alexmiller15:03:39

so like clj -X practice.scratch/my-fn :file '"foo.edn"'

Chase15:03:03

Ahh, I had everything right except for the single quotes surrounding the file name

alexmiller15:03:06

will invoke (practice.scratch/my-fn {:file "foo.edn"})

Chase15:03:42

ahh, thank you. I was looking at the guide page, not the reference page

dev-hartmann15:03:05

@borkdude just wanted to say thanks again, I could get it to work with the .jar file and it's working now even after creating an uberjar!

🎉 1
pithyless20:03:49

TIL that :extra-paths can be a vector of aliases. Is there a way to make an alias that just brings in a group of aliases? The idea being to make a custom alias (new name) for a group of aliases (actual extra-deps, extra-paths, etc.) for the purpose of an easier to remember -X on the CLI.

seancorfield20:03:37

That’s not possible at the moment @pithyless but it is something folks keep asking for 🙂

pithyless20:03:27

OK, thanks 🙂 Right now, I'm often solving this problem via a Makefile/Justfile. Could this perhaps be tackled with a custom function and some fancy parsing of basis?

seancorfield20:03:02

Possibly. It would depend on exactly what you’re trying to achieve and in which context. Tooling is already at liberty to treat keywords as aliases and look up the values in the (calculated project) basis — depstar does this with almost all its :exec-args, for example (on develop — I haven’t cut a release containing that yet).

seancorfield20:03:50

I believe that :exec-args itself may have a keyword value and the CLI looks that up in the basis when you use -X.

seancorfield20:03:53

I just tend to string a whole bunch of aliases together — but at work we do have a shell script (called build) that provides some shortcuts for common CLI commands and alias combinations.