tools-deps

Discuss tools.deps.alpha, tools.build, and the clj/clojure command-line scripts! See also #depstar #clj-new
2021-03-17T12:51:38.036Z

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

2021-03-17T12:52:30.037500Z

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

2021-03-17T12:53:11.038200Z

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

borkdude 2021-03-17T12:53:15.038500Z

:local/root

2021-03-17T12:53:41.038900Z

Sure, sry have it that way

2021-03-17T12:54:19.039300Z

Still get a class not found exception

2021-03-17T12:55:53.040400Z

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

borkdude 2021-03-17T12:56:05.040900Z

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

2021-03-17T12:56:15.041200Z

Sure

2021-03-17T12:57:06.041500Z

Yes, it’s there

borkdude 2021-03-17T12:58:18.042400Z

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

2021-03-17T12:58:30.042600Z

Hm

2021-03-17T12:58:40.043Z

That’s strange

2021-03-17T12:59:15.044Z

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

borkdude 2021-03-17T13:00:00.044600Z

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

2021-03-17T13:00:11.044800Z

Ok, I see

2021-03-17T13:06:21.046300Z

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

2021-03-17T13:11:47.046700Z

Still class not found

2021-03-17T13:12:16.047500Z

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

borkdude 2021-03-17T13:15:20.048Z

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

2021-03-17T13:15:58.048200Z

I see

borkdude 2021-03-17T13:16:57.049100Z

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

2021-03-17T13:17:06.049300Z

Ah, ok

2021-03-17T13:17:10.049600Z

That it didn’t

2021-03-17T13:17:18.050Z

Then I need to include them

2021-03-17T13:17:36.050500Z

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

2021-03-17T13:18:09.051300Z

.../src/java...

borkdude 2021-03-17T13:19:32.051600Z

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

2021-03-17T13:20:09.051900Z

Sure, makes sense

2021-03-17T13:20:36.052700Z

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

2021-03-17T13:20:50.053200Z

Tbh I thought that the .java files were enough

2021-03-17T13:21:04.053600Z

As you might see not a java specialist

borkdude 2021-03-17T13:21:38.054600Z

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

2021-03-17T13:21:40.054700Z

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

2021-03-17T13:21:52.055Z

Makes perfect sense

2021-03-17T13:22:47.056200Z

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

borkdude 2021-03-17T13:25:48.057300Z

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

2021-03-17T13:26:07.057700Z

I see

borkdude 2021-03-17T13:26:21.058300Z

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

2021-03-17T13:26:51.059200Z

Will try that, thx again and sry for nagging.

2021-03-17T13:50:16.059700Z

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

2021-03-17T13:51:23.060800Z

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

2021-03-17T13:51:45.061300Z

even company autocompletion works and is suggesting the correct imports

2021-03-17T13:51:50.061500Z

but when I eval the namespace

2021-03-17T13:51:53.061700Z

still

2021-03-17T13:51:57.061900Z

ClassNotFound

2021-03-17T13:52:16.062300Z

clojure -Spath clearly has the folder there

2021-03-17T13:52:22.062600Z

and the folder is not empty 🙂

2021-03-17T13:55:59.063Z

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

2021-03-17T14:08:57.063500Z

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

alexmiller 2021-03-17T14:09:56.063900Z

latest = ?

alexmiller 2021-03-17T14:09:59.064200Z

clj --version

2021-03-17T14:10:24.064700Z

sorry Clojure CLI version 1.10.3.814

alexmiller 2021-03-17T14:10:58.065500Z

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

2021-03-17T14:11:25.066100Z

yes, but those deps are pulled in like this:

swirrl/muttnik-dev-files-cogs {:git/url "git@github.com:Swirrl/muttnik-dev-files.git"
                                                                 :sha "116624aa86f42b765d2eda3b83a64c3981746a8e"
                                                                 :deps/manifest :deps
                                                                 :deps/root "cogs"}

2021-03-17T14:12:06.066400Z

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

2021-03-17T14:12:30.066600Z

ah yeah ok

2021-03-17T14:12:48.067100Z

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

alexmiller 2021-03-17T14:13:09.067300Z

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

2021-03-17T14:13:45.067700Z

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

2021-03-17T14:15:48.068300Z

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

alexmiller 2021-03-17T14:17:12.068600Z

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

2021-03-17T14:20:16.070700Z

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?

alexmiller 2021-03-17T14:20:49.070900Z

yes

2021-03-17T14:21:01.071100Z

awesome that’s good to know

2021-03-17T14:21:14.071600Z

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

2021-03-17T14:25:39.072700Z

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

alexmiller 2021-03-17T14:34:02.073600Z

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

1👍
alexmiller 2021-03-17T14:34:29.074Z

since it is git :)

borkdude 2021-03-17T14:40:39.074900Z

@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

borkdude 2021-03-17T14:41:22.075500Z

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

2021-03-17T14:46:12.076100Z

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

2021-03-17T14:46:20.076500Z

sure sec.

borkdude 2021-03-17T14:46:26.076700Z

not even import, just try the fully qualified class name

2021-03-17T14:48:20.077400Z

it works now

2021-03-17T14:48:22.077600Z

!!!

2021-03-17T14:48:25.077800Z

I feel so stupid

2021-03-17T14:48:28.078Z

was my error

2021-03-17T14:49:11.078900Z

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

2021-03-17T14:49:18.079100Z

and I tried to import it like this:

2021-03-17T14:49:37.079500Z

import [net.company.plugin.PluginFactory PluginFactory]

2021-03-17T14:49:50.080Z

thx for all the help, works now!

1👍
Chase 2021-03-17T15:24:15.082200Z

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

Chase 2021-03-17T15:24:49.082600Z

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

alexmiller 2021-03-17T15:25:52.082900Z

-X expects to invoke a function that takes a map

alexmiller 2021-03-17T15:25:58.083100Z

the args are key/value pairs

alexmiller 2021-03-17T15:26:11.083400Z

which will go in the map passed to the function

alexmiller 2021-03-17T15:26:39.084300Z

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

Chase 2021-03-17T15:27:03.085200Z

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

alexmiller 2021-03-17T15:27:06.085400Z

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

alexmiller 2021-03-17T15:27:31.085700Z

yeah, more details at https://clojure.org/reference/deps_and_cli#quoting

Chase 2021-03-17T15:28:42.086Z

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

2021-03-17T15:35:05.087100Z

@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🎉
pithyless 2021-03-17T20:37:49.090800Z

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.

seancorfield 2021-03-17T20:38:37.092100Z

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

pithyless 2021-03-17T20:42:27.094900Z

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?

seancorfield 2021-03-17T20:51:02.096900Z

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

seancorfield 2021-03-17T20:51:50.097600Z

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

seancorfield 2021-03-17T20:52:53.098400Z

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.