Fork me on GitHub
#boot
<
2018-04-03
>
grzm02:04:55

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

seancorfield03:04:19

@grzm

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

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

grzm03:04:31

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

seancorfield03:04:21

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

grzm03:04:56

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

seancorfield03:04:22

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

boot -d boot/new new -t app -n jj
then added src/jj/Stuff.java 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])
  (:gen-class))

(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!

seancorfield03:04:14

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

seancorfield03:04:26

(it needs the with-pass-thru wrapper)

grzm04:04:39

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!

seancorfield04:04:21

@grzm Happy to help, wherever I can!

seancorfield04:04:43

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

grzm04:04:30

Yup. Me, too. Thanks for the confirmation.

seancorfield05:04:13

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.

grzm05:04:29

with alt-test?

seancorfield05:04:38

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

grzm05:04:52

I loves me some boot-tools-deps 😉

seancorfield05:04:46

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.

seancorfield05:04:43

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

grzm05:04:23

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

seancorfield05:04:03

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.

grzm05:04:30

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.

seancorfield05:04:53

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

seancorfield05:04:50

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

grzm05:04:51

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.

seancorfield05:04:16

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

seancorfield05:04:43

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

grzm05:04:57

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