Preserving timestamps on Clojure .clj files when building shaded jar via Maven Shade Plugin

Posted by Dereference on Stack Overflow See other posts from Stack Overflow or by Dereference
Published on 2013-10-25T15:52:09Z Indexed on 2013/10/25 15:53 UTC
Read the original article Hit count: 208

Filed under:
|
|
|
|

When using the maven-shade-plugin to package our jar artifact that contained a few Clojure libs and some Java. We were using AOT compilation for our Clojure code. When we loaded the jar, it was having very slow load times. AOT compilation is supposed to help this quite a bit, but that wasn't what we were seeing. We noticed in java jar -verbose output that there was a lot of JVM__DEFINE_CLASS calls happening when Clojure classes were being loaded.

This didn't make sense, since more of our Clojure code was AOT compiled to .class files.

Turns out the maven-shade-plugin creates all new files, with new timestamps in the final artifact Clojure uses the timestamp information on a .clj file vs. a .class file, to determine if the file needs to be recompiled. The maven-shade-plugin was causing the .clj file and it's associated .class file to have the same timestamp, so Clojure always chose to dynamically recompile the source.

The only workaround that we have been able to figure out, at this point, is to write a script that would re-open the shaded jar and bump the .clj file timestamps back to some time in the past, so that they wouldn't be equal to the timestamps of their associated .class files.

Does anyone know of a better approach?

© Stack Overflow or respective owner

Related posts about java

Related posts about maven