什么是优雅的方式来设置一个leiningen项目,需要不同的依赖于基于构建平台? [英] What is an elegant way to set up a leiningen project that requires different dependencies based on the build platform?
问题描述
为了做一些多平台的GUI开发,我刚从GTK + Clojure(因为它看起来像GTK的Java绑定从来没有移植到Windows)切换到SWT + Clojure。到目前为止,我已经得到了一个uberjar为Linux构建。
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.
但是,catch是,我想为Windows构建一个uberjar,找出一个干净的方式来管理project.clj文件。
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.
首先,我想我会设置类路径指向SWT库,然后构建uberjar 。这需要我在运行jar之前为SWT库设置一个类路径,但是我可能需要一个启动脚本。但是,leiningen似乎忽略了这个实例中的类路径,因为它总是报告
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
目前,project.clj对我来说是这样:
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)
行是org.eclipse / swt-gtk-linux-x86行。如果我想为Windows创建一个uberjar,我必须依赖于org.eclipse / swt-win32-win32-x86,另一个为x86-64,依此类推。
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.
我当前的解决方案是简单地创建一个单独的分支为每个构建环境与不同的project.clj。这似乎有点像使用半提交一加仑的牛奶,但我使用bazaar版本控制,所以分支和重复集成很容易。也许更好的方法是有一个project.linux.clj,project.win32.clj等,但我没有看到任何方式告诉leiningen哪个项目描述符使用。
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?
推荐答案
Java系统属性:
(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))
这篇关于什么是优雅的方式来设置一个leiningen项目,需要不同的依赖于基于构建平台?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!