tools-build

scarytom 2021-12-28T18:06:11.356900Z

I wonder if someone can spot my stupid mistake? I've got a mixed Java/Clojure library that I'm trying to convert to tools.build. I'm struggling to get the Clojure to AOT compile -- it doesn't seem to have the class files from the prior Java compilation step on the classpath. I've distilled the issue into this tiny sample project: https://github.com/scarytom/tbs Any feedback gratefully received.

scarytom 2021-12-28T18:07:15.357100Z

running clj -T:build compile yields:

Unexpected error (ClassNotFoundException) macroexpanding gen-class at (com/scarytom/tbs/java_interop.clj:5:1).
java.lang.BeatBox

scarytom 2021-12-28T18:08:03.357300Z

reading that back, it looks like it has the wrong package for BeatBox... that gives me a thread to pull on

dpsutton 2021-12-28T18:08:17.357500Z

com.scarytom.tbs.BeatBox is what i would expect to look for, not java.lang.BeatBox

dpsutton 2021-12-28T18:08:51.357700Z

(:import [com.scarytom.tbs BeatBox]) should be (:import com.scarytom.tbs.BeatBox)

scarytom 2021-12-28T18:14:56.357900Z

thanks

dpsutton 2021-12-28T18:16:18.358100Z

did that work?

scarytom 2021-12-28T19:06:13.358300Z

Sorry. I got called away. I'll try it out momentarily

scarytom 2021-12-28T19:16:41.358500Z

no, your change doesn't work -- the space is correct for a java import. The problem is that gen-class needs a fully qualified type for the return type of the makeBeatBox fn. I didn't know this.

scarytom 2021-12-28T19:18:03.358700Z

I've checked in a working version, so you can see what I did.

scarytom 2021-12-28T19:18:07.358900Z

thanks again for looking at this

2021-12-28T19:24:52.359100Z

You need to add the output "target/java-classes" where the compiled classfiles are written to the classpath of the clojure compile step

2021-12-28T19:26:44.359300Z

I would consider using them same directory for the output of both steps, which will solve it because the output of the clojure compile goes on the classpath anyway

scarytom 2021-12-28T22:05:48.359700Z

thanks @hiredman -- I had already done that (`target/java-classes` is specified as a path in deps.edn). I wasn't aware that the output of the clojure compile is on the classpath for the clojure compile... that seems somewhat circular.

2021-12-29T00:14:49.359900Z

I suspect compile-clj doesn't use paths from deps.edn

scarytom 2021-12-29T21:30:57.381800Z

curious @hiredman, as my sample project is compiling fine despite the clojure depending on a Java interface.

2021-12-30T00:10:15.383Z

The basis is also passed to java-command, so it must merge stuff from there with the cp entry