Fork me on GitHub

Can anyone point me towards examples of including/compiling .java files in a boot build?



(! 998)-> boot javac -h
Compile java sources.

  -h, --help             Print this help info.
  -o, --options OPTIONS  Conj OPTIONS onto list of options passed to the java compiler.
I assume it just compiles any .java files it finds in the :source-paths or :resource-paths (but I haven't checked the source code).


@seancorfield cheers. seems like compilation is (maybe) working. still can't get the compiled files to get picked up properly in my clojure code 😕


Hmm, do you have an example up on GitHub I can take a look at?


Not yet. One of the things I'm currently frustrated with in Clojure is my inability to really extract stuff out quickly. Feels like I'm Doing It Wrong™.


'k... FWIW, I just created a new app

boot -d boot/new new -t app -n jj
then added src/jj/ as
package jj;

public class Stuff {
	public String greet( String s ) {
		return "Hello " + s + "!";
and edited src/jj/core.clj to import and call it:
(ns jj.core
  (:import [jj Stuff])

(defn -main
  "I don't do a whole lot ... yet."
  [& args]
  (let [s (Stuff.)]
    (println (.greet s "Sean")))
  (println "Hello, World!"))
and then boot javac build to produce a JAR and
(! 878)-> java -jar target/jj-0.1.0-SNAPSHOT-standalone.jar 
Hello Sean!
Hello, World!


I realized there's a bug in the generated run task in the template -- so you can't do build javac run unless you update the run task

(deftask run
  "Run the project."
  [a args ARG [str] "the arguments for the application."]
  (with-pass-thru fs
    (require '[jj.core :as app])
    (apply (resolve 'app/-main) args)))


(it needs the with-pass-thru wrapper)


That works as expected, so there's something else going on in my larger project. Thanks for the remote support. Having someone out there on the other end makes a difference!


@grzm Happy to help, wherever I can!


Both boot test and boot alt-test pass for me in that project.


Yup. Me, too. Thanks for the confirmation.


I notice that if you edit the Java source, the tests say "No tests found", but if you edit the Clojure tests, it finds them.


with alt-test?


I didn't realize you were also using boot-tools-deps... yes, with alt-test


I loves me some boot-tools-deps 😉


I haven't -- yet -- tackled the somewhat daunting task of converting our build at work over to the new deps.edn format. We have all our dependencies external, but in a simplified format at the moment.


It's definitely something I want to do at some point since it would allow us to simplify our build and our tooling stack.


It's amazing to me how much stuff falls out using tools-deps.


We have a whole bunch of subprojects in a mono-repo and, right now, we have a complex Boot task that automatically figures out what each one depends on (and enforces certain rules about which cannot depend on what). But I'd like to simplify that and make it all explicit (esp. since we've now decided to take down the walls between some of the projects). So I think the local deps would be perfect for this.


oh, if you type Enter, you can force alt-test to run all of the tests. That seems to work for me when changing the java file. EDIT TO ADD: Nope. While it looks like it recompiles the class, it doesn't reload it.


If you do boot watch test it all works as expected -- editing either source or tests pick up the changes.


I've seen a few other people report strange behavior trying to use alt-test with boot-tools-deps @grzm


I dunno if it's interaction between the two. alt-test does reloading magic, so it wouldn't surprise me if it misses Java classes and only pays attention to Clojure namespace.


You might find if you move the (watch) before the (deps ..) for the alt-test task, it might work too...


So, yeah, it might well be some peculiarity of alt-test...


Good thing is I've got the Java class working in my larger project.