Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to target a specific version of java when making an uberjar using Leiningen

I create a standalone jar using Lein uberjar. This works perfectly fine on my laptop which is running java 1.8. However the computers at my college run java 1.7.0_60.

Within my project.clj I have added :javac-options ["-target 1.7"] in order to compile to java 1.7, however this returns the same error as when that jar is compiled for java 1.8. The error being: Unsupported major.minor version 52.

Maybe the addition of :javac-options ["-target 1.7"] to my project.clj is having no influence on the version which is compiled, I am unsure, please help!

like image 424
Willyb Avatar asked Jul 16 '15 11:07

Willyb


1 Answers

Clojure currently compiles to Java classes that are backwards compatible to Java 1.6, so it is not the Leiningen javac options that are the issue. I ran into the same problem on one of my projects. The issue is that one of the libraries you are using is compiled for too new a Java version. When you build an überjar, Leiningen just copies the classes from your dependency jars into it, so you get whatever class file versions they have.

To solve this problem in my case I had to fork the dependency project on Github and make it build Java 1.6 compatible classes, and then make my Leningen project depend on the fork rather than the main project.

like image 176
James Elliott Avatar answered Sep 18 '22 06:09

James Elliott