基于构建平台设置需要不同依赖项的 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.到目前为止,太好了,我已经为 Linux 构建了一个 uberjar.
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.
问题在于,我想为 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 系统属性的非常优雅的解决方案:
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))
这篇关于基于构建平台设置需要不同依赖项的 leiningen 项目的优雅方式是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!