December 31, 2019
By: Kevin
Leiningen 基础用法
Leiningen 是一个用途广泛的工具, 是clojure工具链的纽带.
- 管理库依赖
- 编译、打包
- 工程模版
- 插件集成
创建新工程
lein new [app | default | plugin | template ] name
- app – 创建一个带
-main函数的模版工程 - default – 创建一个库项目, 可以被其它的项目依赖
- plugin – 创建一个插件
- template – 创建一个模版, 类似Marvin创建的红创模版,这部分待他补充吧.
执行项目
lein run
启动repl
lein repl
打包一个库
lein jar 或者lein install
这样打的包不包含外部依赖的jar, 不可以单独执行.
编译, 打包, 在target目录下生成一个jar
$ lein jar
Created /Users/user/source/me/my-library/target/my-library-0.1.0-SNAPSHOT.jar
编译, 打包,生成pom.xml文件和jar, 并且copy这两个文件到本地的~/.m2目录下.
$ lein install
Created /Users/user/source/me/my-library/target/my-library-0.1.0-SNAPSHOT.jar
Wrote /Users/user/source/me/my-library/pom.xml
Installed jar and pom into local repo.
打包一个应用程序
lein uberjar 给我们打包应用程序的能力,它会把依赖的库,资源文件一起打包. 成功打包以后可以直接执行.
$ lein uberjar
Compiling my-project.core
Created /Users/user/source/me/my-project/target/uberjar/my-project-0.1.0-SNAPSHOT.jar
Created /Users/user/source/me/my-project/target/uberjar/my-project-0.1.0-SNAPSHOT-standalone.jar
查找依赖
lein search 可以用来查照Maven的库里有的包
$lein search excel
Searching central ...
[com.weicoder/excel "3.2.0"]
[io.github.mrdear/excel "0.2.1"]
[com.gitee.lwpwork/excel "0.0.2-RELEASE"]
[cn.com.binging/excel "2.2.3"]
[com.wkclz.util/excel "1.0.10"]
[com.gitee.oumingyuan/excel "1.3-release"]
[com.github.jindz/excel "1.1"]
[net.guerlab/excel "1.1.1"]
[com.daioware.file/excel "1.0.0-RELEASE"]
[org.qsardb.conversion/excel "1.0.0"]
Searching clojars ...
[grafter/clj-excel "0.0.9"]
Excel bindings for Clojure, based on Apache POI.
[com.outpace/clj-excel "0.0.9"]
Excel bindings for Clojure, based on Apache POI.
[outpace/clj-excel "0.0.2"]
Excel bindings for Clojure, based on Apache POI.
[hellonico/clj-excel "0.0.2"]
Excel bindings for Clojure, based on Apache POI.
[kaleidocs/clj-excel "0.0.1"]
Excel bindings for Clojure, based on Apache POI.
[incanter/incanter-excel "1.9.3"]
Incanter-excel provides access to reading and writing Excel files.
[clj-excel "0.0.1"]
Excel bindings for Clojure, based on Apache POI.
[com.pennymacusa/excel-formulas "0.2.2"]
Excel formulas ported to Clojure
[org.clojars.mjdowney/excel-clj "1.2.0"]
Generate Excel documents & PDFs from Clojure data.
[joinr/incanter-excel "1.9.3-SNAPSHOT"]
Incanter-excel provides access to reading and writing Excel files.
[incanter/excel "1.2.3-SNAPSHOT"]
Incanter-excel provides access to reading and writing Excel files.
[kixi/incanter-excel "1.9.1-p0-3bf644a"]
Incanter-excel provides access to reading and writing Excel files.
[steve-incanter/incanter-excel "1.9.3-SNAPSHOT"]
Incanter-excel provides access to reading and writing Excel files.
[com.infolace/excel-templates "0.3.3"]
Build Excel files by combining a template with plain old data
[com.madriska/excel-templates "0.3.3.1"]
Build Excel files by combining a template with plain old data
[org.clojars.datasio/clj-excel "0.0.1-9780eddfde-17-May-2014"]
Excel bindings for Clojure, based on Apache POI.
[cljsjs/exceljs "1.15.0-0"]
Excel Workbook Manager
[ontodev/excel "0.2.4"]
A thin Clojure wrapper around a small part of Apache POI for reading .xlsx files.
[cc.artifice/excel "0.3.0"]
A thin Clojure wrapper around a small part of Apache POI for reading .xlsx files.
[brandonparsons/excel "0.2.3"]
A thin Clojure wrapper around a small part of Apache POI for reading .xlsx files.
[org.clojars.tnoda/incanter.read-xlsx "0.0.9"]
Provide a Incanter function to read Excel 2007 and Excel 97/2000/XP/2003 file formats
[io.bfpcorporation/excel "0.2.5"]
A thin Clojure wrapper around a small part of Apache POI for reading .xlsx files.
[tnoda.incanter.xlsx "0.0.1"]
Provide a Incanter function to read Excel 2007 and Excel 97/2000/XP/2003 file formats
[org.clojars.tnoda/incanter.xlsx "0.0.2"]
Provide a Incanter function to read Excel 2007 and Excel 97/2000/XP/2003 file formats
测试
比如我们工程中的:
lein test: 执行一次test
lein test-refresh: test runner 始终运行test
lein cloverage: 查看测试覆盖率
编译
把clj文件和java文件编译为class.
lein compile
在我们的项目中执行这个命令什么都不会发生, 因为我们
- 没有指定
:aot(ahead of time)的编译 - 没有指定
:java-source-paths, 也就是没有Java文件
我们稍后会有一篇文章专门讲Java和Clojure的编译和interop的问题.