DEV Community

Cover image for Leinigen: Configurando ambiente dev para Clojure
Arthur Fücher
Arthur Fücher

Posted on

Leinigen: Configurando ambiente dev para Clojure

Aloha!
No outro texto compartilhei sobre como instalar Clojure no Windows, agora iremos ver uma ferramenta muito utilizada em projetos Clojure: Leinigen

O que é?

De acordo com o site oficial:

for automating Clojure projects without setting your hair on fire.

Em uma tradução livre:
para automatizar projetos clojure sem colocar fogo no seu cabelo

Para quem vem do javascript, eu costumo comparar ao NPM.

A real é que o leinigen fornece diversas facilidades para criar e rodar projeto, rodar testes, instalar dependências, etc...

Instalando

Como sempre, fui no site oficial e segui o passo-a-passo.
Assim como o Clojure, ele precisa que você tenha o JAVA instalado. Como já temos, comecei a instalação que é bastante simples.

A primeira coisa é fazer o download do arquivo lein.bat

Depois precisamos adicionar o diretório desse arquivo no PATH do Windows. Para isso basta ir nas variáveis de ambientes do Windows, localizar a PATH e incluir o diretório.

Eu crio uma pasta D:\Utils e já configuro no PATH. Nela coloco todos os arquivos de script que quero deixar disponível no terminal ;)

O último passo é rodar o script que irá fazer a instalação.

⚠️⚠️⚠️ Quando rodei na minha máquinha deu erro, dizendo que não encontrou um arquivo .jar, para tentar rodar lein self-install.

C:\Users\user\.lein\self-installs\leiningen-2.10.0-standalone.jar can not be found. You can try running "lein self-install" or change LEIN_JAR environment variable or edit lein.bat to set appropriate LEIN_JAR path. 
Enter fullscreen mode Exit fullscreen mode

Acredito que a doc do site esteja desatualizada, pois rodei o comando sugerido e funcionou 😇

lein self-install

Validando

Para validar a instalação, você pode rodar o comando lein no terminal. Ele trará uma lista de comandos que você pode executar.
É bem interessante para ver a quantidade de coisas que o Leiningen faz:

lein Leiningen is a tool for working with Clojure projects. Several tasks are available: change Rewrite project.clj with f applied to the value at key-or-path. check Check syntax and warn on reflection. classpath Write the classpath of the current project to output-file. clean Removes all files from paths in clean-targets for a project compile Compile Clojure source into .class files. deploy Deploy jar and pom to remote repository. deps Download and examine dependencies. do Higher-order task to perform other tasks in succession. help Display a list of tasks or help for a given task or subtask. install Install jar and pom to the local repository; typically ~/.m2. jar Package up all the project's files into a jar file. javac Compile Java source files. new Generate scaffolding for a new project based on a template. plugin DEPRECATED. Please use the :user profile instead. pom Write a pom.xml file to disk for Maven interoperability. repl Start a repl session either with the current project or standalone. retest Run only the test namespaces which failed last time around. run Run the project's -main function. search Search Central and Clojars for published artifacts. show-profiles List all available profiles or display one if given an argument. test Run the project's tests. trampoline Run a task without nesting the project's JVM inside Leiningen's. uberjar Package up the project files and all dependencies into a jar file. update-in Perform arbitrary transformations on your project map. upgrade Upgrade Leiningen to specified version or latest stable. vcs Interact with the version control system. version Print version for Leiningen and the current JVM. with-profile Apply the given task with the profile(s) specified. 
Enter fullscreen mode Exit fullscreen mode

Outra coisa é que você pode rodar o REPL através do comando lein repl, o mesmo que rodamos quando instalamos o Clojure usando clj.
Com o lein ele faz mais coisas, mas que mostrarei em outros textos.
Uma coisa legal, é que agora para sair do REPL basta digitar exit:

 lein repl nREPL server started on port 52228 on host 127.0.0.1 - nrepl://127.0.0.1:52228 REPL-y 0.5.1, nREPL 1.0.0 Clojure 1.11.1 OpenJDK 64-Bit Server VM 17.0.5+8 Docs: (doc function-name-here) (find-doc "part-of-name-here") Source: (source function-name-here) Javadoc: (javadoc java-object-or-class-here) Exit: Control+D or (exit) or (quit) Results: Stored in vars *1, *2, *3, an exception in *e user=> exit Bye for now! 
Enter fullscreen mode Exit fullscreen mode

Se quiser continuar vendo mais sobre Leiningen sugiro ver o tutorial que eles tem


Já conhecia o Leiningen? Conseguiu instalar? Compartilha aí nos comentários.

Espero que tenha gostado da leitura! Até breve.

Abraços

Top comments (2)

Collapse
 
mebble profile image
Neil Syiemlieh

Obrigado por este artigo. Existe uma tradução em inglês disponível? Estou usando o google tradutor para escrever este comentário

Collapse
 
afucher profile image
Arthur Fücher

Hey @mebble, all good? unfortunately I'm just writing in Portuguese. My goal is to boost the local community, and we already have a lot of content in English.
But thanks to comment here, I will consider in a future to translate some content.