In order to do some multi-platform GUI development, I have just switched from GTK + Clojure (because it looks like the Java bindings for GTK never got ported to Windows) to SWT + Clojure. So far, so good in that I have gotten an uberjar built for Linux.
The catch, though, is that I want to build an uberjar for Windows and I am trying to figure out a clean way to manage the project.clj file.
At first, I thought I would set the classpath to point to the SWT libraries and then build the uberjar. This would require that I set a classpath to the SWT libraries before running the jar, but I would likely need a launcher script, anyway. However, leiningen seems to ignore the classpath in this instance because it always reports that
Currently, project.clj looks like this for me:
(defproject alyra.mana-punk/character "1.0.0-SNAPSHOT"
:description "FIXME: write"
:dependencies [[org.clojure/clojure "1.2.0"]
[org.clojure/clojure-contrib "1.2.0"]
[org.eclipse/swt-gtk-linux-x86 "3.5.2"]]
:main alyra.mana-punk.character.core)
The relevant line is the org.eclipse/swt-gtk-linux-x86
line. If I want to make an uberjar for Windows, I have to depend on org.eclipse/swt-win32-win32-x86
, and another one for x86-64
, and so on and so forth.
My current solution is to simply create a separate branch for each build environment with a different project.clj
. This seems kinda like using a semi to deliver a single gallon of milk, but I am using bazaar for version control, so branching and repeated integrations are easy. Maybe the better way is to have a project.linux.clj
, project.win32.clj
, etc, but I do not see any way to tell leiningen which project descriptor to use.
What are other (preferably more elegant) ways to set up such an environment?
Here's a quite elegant solution using Java system properties:
(let [properties (select-keys (into {} (System/getProperties))
["os.arch" "os.name"])
platform (apply format "%s (%s)" (vals properties))
swt (case platform
"Windows XP (x86)" '[org.eclipse/swt-win32-win32-x86 "3.5.2"]
"Linux (x86)" '[org.eclipse/swt-gtk-linux-x86 "3.5.2"])]
(defproject alyra.mana-punk/character "1.0.0-SNAPSHOT"
:description "FIXME: write"
:dependencies [[org.clojure/clojure "1.2.0"]
[org.clojure/clojure-contrib "1.2.0"]
~swt]
:main alyra.mana-punk.character.core))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With