管理配置档案、别名与环境
实际项目需要为开发、测试和生产环境使用不同设置。本课程将教您使用 Leiningen 配置档案和 deps.edn 别名管理配置及环境专属构建。
管理配置档案、别名与环境 是 CoddyKit 上的免费 Clojure Functional Programming & JVM Backend Development 课时。 这是第 4 节课,共 4 节。 你可以在下方免费阅读本课时的完整内容 — 然后在浏览器中使用内置代码编辑器和全天候 AI 导师进行实践。 这是 Clojure Functional Programming & JVM Backend Development 学习路径的一部分,你的进度在网页和 CoddyKit 应用中同步。 Clojure Functional Programming & JVM Backend Development 课程共包含 4 节课。
本课时的部分内容尚未翻译,以英文显示。
Why Profiles and Aliases
You should not ship dev tooling to production. Profiles (Leiningen) and aliases (deps.edn) let one project produce different configurations on demand.
Leiningen Profiles
A profile in project.clj overlays extra config, such as dev-only dependencies, that merge into the base.
{:profiles
{:dev {:dependencies [[midje "1.10.9"]]}
:uberjar {:aot :all}}}Activating a Profile
Use the with-profile task to run a command under a chosen profile.
lein with-profile +uberjar uberjarDefault Profiles
The :dev profile activates automatically for local commands like lein repl, so test tooling is available without extra flags.
deps.edn Aliases
In tools.deps, an alias adds dependencies or options under a keyword you activate with the -M or -X flags.
{:aliases
{:test {:extra-paths ["test"]
:extra-deps {lambdaisland/kaocha {:mvn/version "1.91.1392"}}}}}Running an Alias
Invoke an alias from the CLI; multiple aliases combine.
clojure -M:test:dev -m kaocha.runnerEnvironment Variables
Read configuration from the environment so the same artifact behaves differently per deployment without recompiling.
(def db-url (System/getenv "DATABASE_URL"))
(println db-url)Config Files Per Environment
Keep an config.edn read at startup. Choose the file via an env var so prod and dev load different settings.
(require '[clojure.edn :as edn])
(def config
(edn/read-string (slurp (or (System/getenv "CONFIG") "dev.edn"))))Keep Secrets Out of Source
Never commit credentials. Inject them through environment variables or a secrets manager, and reference them from profiles or aliases only by name.
Composition Over Duplication
Both profiles and aliases compose. Layer a base plus environment overlays rather than maintaining several near-identical full configs.
Reproducible Builds
Pin versions and avoid implicit defaults so a build on CI matches a build on a laptop. Profiles and aliases make these differences explicit and intentional.
Quick Check
Test your profiles and aliases knowledge.
Recap
You learned Leiningen profiles, deps.edn aliases, activating them from the CLI, reading environment variables and per-environment config files, keeping secrets out of source, and composing layers for reproducible builds.
用 AI 导师学习 Clojure — 免费
在浏览器中编写并运行真实代码,获得全天候 AI 导师的即时帮助,并在网页或应用中继续学习。
- 课程
- 12
- 课程
- 48
常见问题解答
「管理配置档案、别名与环境」课时是免费的吗?
是的 — 「管理配置档案、别名与环境」的完整文本可在网页上免费阅读。要进行交互式练习(内置代码编辑器和全天候 AI 导师)并解锁 Clojure Functional Programming & JVM Backend Development 课程的其余内容,请升级到 CoddyKit PRO。 Clojure Functional Programming & JVM Backend Development 课程共包含 4 节课。
「管理配置档案、别名与环境」这节课中我会学到什么?
实际项目需要为开发、测试和生产环境使用不同设置。本课程将教您使用 Leiningen 配置档案和 deps.edn 别名管理配置及环境专属构建。 你通过在浏览器中直接运行的动手代码来练习 Clojure Functional Programming & JVM Backend Development,全天候 AI 导师会在你学习这节课的过程中回答你的问题。
学习 Clojure Functional Programming & JVM Backend Development 需要有经验吗?
无需任何先前经验。CoddyKit 上的 Clojure Functional Programming & JVM Backend Development 课程适合初学者到高级学习者,你可以从这里开始或从头开始,按照自己的节奏学习。 这是第 4 节课,共 4 节。
「管理配置档案、别名与环境」课时需要多长时间?
大多数 CoddyKit 课程大约需要 5–10 分钟。每节课都很精短且互动,所以你能稳步进步,并在网页和应用中从离开的地方继续。
我能在这节 Clojure Functional Programming & JVM Backend Development 课中编写并运行代码吗?
能。每节 Clojure Functional Programming & JVM Backend Development 课都包含内置代码编辑器,你可以在浏览器中直接编写并运行真实代码,并获得即时 AI 反馈 — 无需本地设置。
此课程中的所有课时
- Leiningen 与 Deps.edn 基础
- 管理依赖与插件
- 构建、测试与部署
- 管理配置档案、别名与环境