【问题标题】:How do you determine the current leiningen profiles from a running repl?您如何从正在运行的 repl 中确定当前的 le​​iningen 配置文件?
【发布时间】:2016-06-16 20:46:43
【问题描述】:

当您的 IDE 为您启动 REPL 时,当前的活动配置文件集尚不清楚。在这种情况下,您能否以某种方式查询 Leiningen 以找出它们可能是什么?

【问题讨论】:

  • 不知道一般的答案,但您总是可以制作一个只有 1 个配置文件的临时 project.clj 文件。请务必同时禁用 ~/.lein/profiles.clj。

标签: clojure leiningen


【解决方案1】:

通常我会在我的project.clj 上定义各种配置文件,它们分别指向不同的配置文件,例如

  :profiles {:release {:resource-paths ["config/release"]
                          :source-paths ["src"]
                          }
             :test {:resource-paths ["config/test"]
                       :source-paths ["src" "test"]
                       }
             :dev {:resource-paths ["config/dev"]
                   :source-paths ["src" "dev"]}}

因此,对于“config”中的每个文件夹都有一个 config.edn,其中包含我所拥有的每个配置文件所需的信息,您可以在每个 config.edn 中添加一个 :profile 关键字,并为每个配置一个不同的值以显示此时哪个配置文件处于活动状态。我使用yogthos config 来加载配置文件。

除此之外,我真的不知道 IDE 控制 nrepl 的想法,通常它会在 IDE 关闭时杀死 repl,并且它们可能对您传递给 lein 的选项非常严格。我更喜欢使用 lein with-profile dev repl 在与我的编辑器不同的终端中启动 repl,然后在我的编辑器上连接该 nrepl 会话,这样您就可以确定您正在使用哪个配置文件。

【讨论】:

    【解决方案2】:

    据我所知,无法查看作为运行 REPL 的一部分加载的配置文件。就像任何程序都不知道它是从哪个终端窗口开始的一样。也就是说,profiles and how they work is documented

    而且,仅仅知道哪些是“活跃的”并不总是足够的。有时,知道按哪个顺序也很重要。

    要解决这个问题,请将以下内容添加到您的 project.clj

      :profiles {
                 :dev {:injections [(prn "including dev profile")]}
                 :test {:injections [(prn "including test profile")]}
                 :repl {:injections [(prn "including repl profile")]}
                 :my-profile {:injections [(prn "including my-profile profile")]}
    

    现在运行以下命令并查找输出"including ...

    lein repl
    lein test
    lein with-profile my-profile test
    lein with-profile +my-profile test
    

    请注意,:injections 不会在 jars 或 uberjars 中执行(lein jarlein uberjar)。这就是为什么我将其排除在上述操场之外的原因。

    【讨论】:

      猜你喜欢
      • 2016-08-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-08-23
      • 2013-07-18
      • 1970-01-01
      • 2012-01-20
      相关资源
      最近更新 更多