@borkdude just a quick follow up question, if you don’t mind:
I added the Java project with :root/local “absolute path to root containing Pom”
But when I try to import an object from the dependency inside my namespace
:local/root
Sure, sry have it that way
Still get a class not found exception
Seems like the project is loaded correctly, as I had to add my private nexus mvn repo
Try clojure -Spath
and check if the directory with your classes is in there
Sure
Yes, it’s there
ok, then it should work, or the class isn't there somehow
Hm
That’s strange
Do I need to add more dirs to the paths vector into my deps.edn to make it work?
dirs in :paths
are just the first dirs on the clojure -Spath
, the rest come from your dependencies
Ok, I see
Hm, I’ll try pointing to a .jar file of the project
Still class not found
I need to point to the root of the project containing the Pom.xml, correct?
yes. but if your pom.xml doesn't include your generated classes on the classpath, then they won't be found
I see
this is why I asked you to inspect clojure -Spath
. that should contain the dir with your generated classes
Ah, ok
That it didn’t
Then I need to include them
I just saw it was including the base dir of my code
.../src/java...
what is not on the classpath, cannot be found, that's how the classpath works :)
Sure, makes sense
I thought since it had the root of my project it could check all the files under that dir
Tbh I thought that the .java files were enough
As you might see not a java specialist
clojure does not do any compilation for .java files, you need .class files
I can see that building the java application generates a target/classes folder
Makes perfect sense
How do I make mvn aware there is a target/class folder?
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"]}
I see
and then you use that other project using :local/root
and it should pick up the target/classes dir
Will try that, thx again and sry for nagging.
ok, with the additional deps.edn in the java project
and local/root with :deps/manifest :deps it worked
even company autocompletion works and is suggesting the correct imports
but when I eval the namespace
still
ClassNotFound
clojure -Spath clearly has the folder there
and the folder is not empty 🙂
I can even see the javadoc and the info on what it extends
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
latest = ?
clj --version
sorry Clojure CLI version 1.10.3.814
that error looks like a relative path in muttnik-dev-files-cogs that goes outside the project
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"}
oh wait I think see what you’re saying… 👀
ah yeah ok
the deps edn file in the cogs
folder there looks like this:
{:paths ["resources", "../shared/resources"]}
This warning was added in https://clojure.org/releases/tools#v1.10.2.790 and eventually external references not be allowed
ok so I guess I need to pull in shared as an extra dep
oh actually I see that the shared directory has been deleted anyway. I just need to clear out the cruft. Thanks.
yeah, local deps would be an ok way to accomplish the same
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?
yes
awesome that’s good to know
though looks like I don’t have this problem anymore 🙂
Presumably the move to using git proper, also means issues where JGit had a 100mb max file size limit are now also fixed?
I wasn't aware of that one but it will match whatever you get with git
since it is git :)
@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
also post the snippet where that directory occurs on your classpath as output with clojure -Spath
@borkdude you mean open a repl with clj and try to import the classname, right?
sure sec.
not even import, just try the fully qualified class name
it works now
!!!
I feel so stupid
was my error
the class with package is net.company.plugin.PluginFactory
and I tried to import it like this:
import [net.company.plugin.PluginFactory PluginFactory]
thx for all the help, works now!
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
I specifically want to feed that function a file name that is in my resources folder
-X expects to invoke a function that takes a map
the args are key/value pairs
which will go in the map passed to the function
so like clj -X practice.scratch/my-fn :file '"foo.edn"'
Ahh, I had everything right except for the single quotes surrounding the file name
will invoke (practice.scratch/my-fn {:file "foo.edn"})
yeah, more details at https://clojure.org/reference/deps_and_cli#quoting
ahh, thank you. I was looking at the guide page, not the reference page
@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!
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.
That’s not possible at the moment @pithyless but it is something folks keep asking for 🙂
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
?
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).
I believe that :exec-args
itself may have a keyword value and the CLI looks that up in the basis when you use -X
.
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.