java

fricze 2024-09-20T19:13:26.044529Z

hi, I need to write few Java classes to be usable from Clojure. this repo is great for start https://github.com/seancorfield/java-clojure-example but I don't know how to handle dependencies in Java code. is there a way to import packages defined in deps.edn in Java code or do I have to handle Java dependencies separately?

fricze 2024-09-21T08:15:05.690399Z

"doesn't work" mean that I have this deps in deps.edn:

{org.clojure/clojure                  {:mvn/version "1.12.0"}
  io.github.humbleui/types$clojure     {:mvn/version "0.2.0"}
  io.github.humbleui/jwm               {:mvn/version "0.4.18" :exclusions [io.github.humbleui/types]}
  io.github.humbleui/skija-windows-x64 {:mvn/version "0.116.2" :exclusions [io.github.humbleui/types]}
  io.github.humbleui/skija-linux-x64   {:mvn/version "0.116.2" :exclusions [io.github.humbleui/types]}
  io.github.humbleui/skija-macos-x64   {:mvn/version "0.116.2" :exclusions [io.github.humbleui/types]}
  io.github.humbleui/skija-macos-arm64 {:mvn/version "0.116.2" :exclusions [io.github.humbleui/types]}
  io.github.tonsky/extend-clj          {:mvn/version "0.1.0"}
when I do (:import [io.github.humbleui.skija Font Typeface]) in Clojure – it works when I try to do import io.github.humbleui.skija.Font; in Java the info I get is: package io.github.humbleui.skija does not exist

2024-09-21T15:56:11.455479Z

https://clojure.org/guides/tools_build has an example of a mixed clojure and java build, I would start from there. Looks like a big difference between it and the example you are starting from is it passes the basis to the javac task

fricze 2024-09-21T18:42:48.639229Z

thanks! I see what was my issue, I was missing :basis key when calling javac

fricze 2024-09-21T18:43:47.656379Z

when I created (def basis (delay (b/create-basis {:project "deps.edn"}))) and passed it to javac it started working 🙂

👏 1
2024-09-20T19:38:12.244429Z

The libraries in deps.edn will be put on the classpath when you launch a process using clj, and will just be available

2024-09-20T19:40:45.252289Z

The thing to be aware of with java is just you have much more distinction between compilation and running phases, and you'll need to make sure its dependencies are available for both (although may not be exactly the same set of deps)

fricze 2024-09-20T19:57:25.782769Z

yeah, they will be available when I run clj. but are they available when I compile java? without clj?

fricze 2024-09-20T20:00:25.781269Z

let's say there's maven repo https://mvnrepository.com/artifact/io.github.humbleui.skija and I want to install this package via deps.edn but later import it in Java file and compile this Java file by itself. so I want to write this in Java and access this package in Java import io.github.humbleui.skija;

fricze 2024-09-20T20:01:21.089959Z

currently it doesn't work for me and I wonder whether it's doable, or do I have to create some maven project with its own dependencies?

2024-09-20T20:06:29.007379Z

what does "doesn't work for me" mean?

2024-09-20T20:06:52.506609Z

java imports classes

2024-09-20T20:07:09.378439Z

io.github.humbleui.skija looks like a package name (prefix of a class name) not a class

2024-09-20T20:07:52.622399Z

and maven group and artifact ids are a disjoint namespace from the stuff contained in the jars you get from maven