设置需要基于构建平台的不同依赖项的 leiningen 项目的优雅方法是什么?

发布于 2024-10-12 06:53:21 字数 1096 浏览 3 评论 0原文

为了进行一些多平台 GUI 开发,我刚刚从 GTK + Clojure(因为 GTK 的 Java 绑定看起来从未移植到 Windows)切换到 SWT + Clojure。到目前为止,一切都很好,我已经得到了一个为 Linux 构建的 uberjar。

但问题是,我想为 Windows 构建一个 uberjar,并且我正在尝试找出一种干净的方法来管理 project.clj 文件。

起初,我想将类路径设置为指向 SWT 库,然后构建 uberjar。这需要我在运行 jar 之前设置 SWT 库的类路径,但无论如何我可能需要一个启动器脚本。然而,leiningen 似乎忽略了这种情况下的类路径,因为它总是报告

当前,project.clj 对我来说是这样的:

(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 的依赖,并且等等。

我当前的解决方案是简单地为每个具有不同 project.clj 的构建环境创建一个单独的分支。这看起来有点像使用半成品来运送一加仑牛奶,但我使用集市进行版本控制,因此分支和重复集成很容易。也许更好的方法是拥有 project.linux.cljproject.win32.clj 等,但我没有看到任何方法来告诉 leiningen 哪个项目描述符使用。

还有哪些其他(最好是更优雅的)方法来设置这样的环境?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

ぺ禁宫浮华殁 2024-10-19 06:53:21

这是一个使用 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))

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))
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文