clojure 项目构建 boot

本文介绍了Clojure程序的构建过程,首先讲解了Leiningen的使用,包括依赖管理、项目配置和任务操作。接着,重点探讨了Boot构建系统,它的灵活性、任务机制以及如何自定义任务。此外,还提到了ClojureScript的构建支持。通过本文,读者将了解Clojure项目从初始化到发布的完整构建流程。
摘要由CSDN通过智能技术生成

我们知道,c和c++程序是使用makefile来构建的;java程序使用ant,maven等构建;那么基于java的函数式编程clojure要怎么构建大型应用程序的呢?当然,也可以基于maven,本文主要先讲述clojure基于Leiningen的构建方式,然后会着重讲述clojure基于boot的构建方式。

构建程序相关的基本概念

构建是一个统称,包括我们写完代码之后到代码发布之前越来越多的东西;
编译;
依赖管理,可以系统地使用外部函数库;
把编译结果和项目资源打包成构件;
在依赖管理的情况下分发这些构件;

创建新的工程
工程之间的依赖关系?
测试?
运行?
部署?
发布库?

Leiningen

Leiningen is the easiest way to use Clojure. With a focus on project automation and declarative configuration, it gets out of your way and lets you focus on your code.

1.lein
lein重用了maven许多的基础设施;maven,gradle,ant都有插件帮助clojure的构建;
那么lein的使用方式是怎样的?
lein通过lein help获取一个任务列表,通过lein help $TASK获取到具体的任务信息。
比如说:

$ lein help uberjar
Package up the project files and all dependencies into a jar file.

Includes the contents of each of the dependency jars. Suitable for standalone distribution.

With an argument, the uberjar will be built with an alternate main.

The namespace you choose as main should have :gen-class in its ns form as well as defining a -main function.

Note: The :uberjar profile is implicitly activated for this task, and cannot be deactivated.

Arguments: ([main] [])

这里的profile的解;;; Profiles
;; Each active profile gets merged into the project map. The :dev
;; and :user profiles are active by default, but the latter should be
;; looked up in ~/.lein/profiles.clj rather than set in project.clj.
;; Use the with-profiles higher-order task to run a task with a
;; different set of active profiles.
;; See lein help profiles for a detailed explanation.
:profiles {:debug {:debug true
:injections [(prn (into {} (System/getProperties)))]}
:1.4 {:dependencies [[org.clojure/clojure “1.4.0”]]}
:1.5 {:dependencies [[org.clojure/clojure “1.5.0”]]}
;; activated by default
:dev {:resource-paths [“dummy-data”]
:dependencies [[clj-stacktrace “0.2.4”]]}
;; activated automatically during uberjar
:uberjar {:aot :all}
;; activated automatically in repl task
active的profile对应的map会并合并到project的map中去。比如说运行lein uberjar 的时候,{:aot :all}就会被合并到project的map中;运行:debug 的时候,{:debug true :injections [(prn (into {} (System/getProperties)))]}就会被合并。

lein works with projects。一个项目就是一个包含一组clojure源文件的目录,当然也包括员数据metadata.metadata存在一个叫做project.clj的root目录中,这个目录会告诉leiningen一些事情:

项目名字 版本信息 描述 依靠 clojure版本 怎么找源文件 以及main所在的名字空间等。
(defproject my-stuff "0.1.0-SNAPSHOT"
:description "FIXME: write description"
:url "http://example.com/FIXME"
:license {:name "Eclipse Public License"
:url "http://www.eclipse.org/legal/epl-v10.html"}
:dependencies [[org.clojure/clojure "1.8.0"]]
:main ^:skip-aot my-stuff.core
:target-path "target/%s"
:profiles {:uberjar {:aot :all}})

名字:my-stuff
版本信息:是一个字符串”0.1.0-SNAPSHOT”
描述:是一个字符串 “FIXME: write description”
url是一个字符串:”http://example.com/FIXME
clojure版本:[org.clojure/clojure “1.8.0”]
依赖信息:是一个以[]包裹的vector
整个project.clj符合clojure语法,是一个以defproject开头的form。

依赖 Dependencies

clojure是一个hosted language(托管),clojure的各种lib像jvm语言一样都被打包为jar文件发布,jar文件基本上就是简单的.zip文件,还有额外的JVM特定的元数据metadata。一个jar文件通常包括.class文件和clj源代码,通常也包括其他的一些文件,比如javascript和text文件。发布的JVM库一般都有标识符(artifact group和artifact id)和版本号。

那么在clojars上面是怎么搜索lib库的?通过artifact group就可以搜索到很多jar包,比如
这里写图片描述

点进去发现:
这里写图片描述

lein添加依赖的方法: [clj-http "3.1

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值