Question

I'm using leiningen's :java-source-paths and it's compiling the java source every time. is there a way for lein to tell if it hasn't changed?

Here's an example project to illustrate the problem: https://github.com/yayitswei/leinwithjava

Was it helpful?

Solution

It looks like you have Clojure and Java source code mixed together in the same source tree, and are then pointing :java-source-paths at a sub-directory of the root of that source tree. A more typical approach for polyglot projects is to manage separate directories for source code in each language.

The reason you're seeing Java source recompiled every time you invoke lein is that the check to detect stale Java sources only works if :java-source-paths points at the root of the Java package tree. Note that the stale-java-sources function in the javac task takes the path of each source file relative to the :java-source-paths directory, and uses that to construct the path for the corresponding class file relative to the :compile-path directory. In your case, Leiningen was expecting to find target/classes/TestClass.class when the actual compiled class file was target/classes/main/java/TestClass.class.

I was able to fix your sample project by switching it over to the following directory structure:

$ find src
src
src/java
src/java/main
src/java/main/java
src/java/main/java/TestClass.java
src/clj
src/clj/leinwithjava
src/clj/leinwithjava/core.clj

And in project.clj:

:source-paths ["src/clj"]
:java-source-paths ["src/java"]
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top