This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-10-18
Channels
- # announcements (12)
- # babashka (6)
- # beginners (62)
- # calva (3)
- # cider (41)
- # clerk (5)
- # clojure (192)
- # clojure-bay-area (1)
- # clojure-europe (14)
- # clojure-norway (97)
- # clojure-uk (6)
- # clojuredesign-podcast (4)
- # clojurescript (30)
- # code-reviews (7)
- # cursive (32)
- # datahike (4)
- # datomic (35)
- # docker (8)
- # emacs (8)
- # events (1)
- # fulcro (13)
- # helix (19)
- # hoplon (4)
- # hyperfiddle (37)
- # jobs-discuss (10)
- # membrane (11)
- # missionary (19)
- # off-topic (28)
- # polylith (8)
- # portal (10)
- # practicalli (8)
- # re-frame (31)
- # reitit (6)
- # shadow-cljs (39)
- # timbre (3)
- # vim (1)
- # xtdb (6)
Hi all! Any clues on how to pre-compile Java sources in a Polylith workspace? I now have a single component with a single Java class, so I don’t want to extract it into a library and would like to keep things simple. I’ve already tried to configure a build
profile and ns as per https://github.com/seancorfield/java-clojure-example/tree/master and https://andersmurphy.com/2021/12/12/clojure-compiling-java-source-with-tools-build.html, but it doesn’t seem to work. Does anyone have an example of a similar project?
Can you explain "it doesn’t seem to work" and also provide a bit more detail on what you have actually tried?
Is having a standalone clojure -T:build compile-java
command sufficient for your needs, for example? (i.e., that you run manually as needed to work with your :dev
REPL)
Sean, hi! I had no doubt that you would be the one to respond. 😃
Sorry, I was in a hurry yesterday and didn’t go into details, hoping that someone will just send me a link to the existing repo.
In essence, the commands I tried completed without any errors (i.e. the classpath
was assembled correctly), but as a result, the target
directory did not appear anywhere in the project.
And, yeah, so far I find having a standalone command / bb task sufficient for the project needs — I’ll overengineer this later on. 😂
So, I played around with this a little more today and came up with a working setup. Here it is!
├── components
│ └── happy-face
│ └── src
│ └──
│ └── java-src
│ └──
│ └── deps.edn
├── build.clj
└── deps.edn
The root deps.edn
has a :build
alias as simple as in examples I’ve linked above.
The component’s deps.edn
lists "target/classes"
in :paths
.
My build.clj
script is in the root of the workspace and looks like this:@U04V70XH6, the only problem that remains is tests failing in IntelliJ IDEA with its own classpath
, even though the compiled class file is available.
NB: I still use a rather old IntelliJ version, 2020.2.4, that comes with Cursive of the time, which doesn’t understand Polylith projects quite well yet.
I scanned the IntelliJ’s classpath
and it turned out to be a bit outdated (the brick’s src-java
made it to there, but not the target/classes
). I then double-checked that I have all aliases enabled in “Clojure Deps” tab and refreshed the project. Now my tests are back to life! 😃
@U04V70XH6, what best practices can you recommend for similar mixed Clojure/Java codebase projects in production development? Do you use Java in the World Singles codebase?
We do not use Java code at all at work, just lots of Java libraries. We've never felt a need to "drop down" to Java -- Clojure does all we need.