Example project for an "event app" can be found in event-app
branch.
- Sign up for account: https://home.openweathermap.org/users/sign_up
- Click the link that you received in your email. Activating the API key may take a few hours after confirming your email.
- Get API key: https://home.openweathermap.org/api_keys
- Register to Heroku: https://www.heroku.com/
- Create app with Heroku Git, e.g.,
clojure-training
- Select buildpack
heroku/clojure
. Can be found in Buildpacks under project Settings tab. - Add resource for Heroku Postgres, Hobby Dev tier. Can be found in Add-ons under Resources.
- See command line (CLI) installation below
At this point, we ask you to install a bunch of tools without too many questions. It will all make sense later, when we go through these and use them in practise.
If you already have working tools for some of these, please check that they are not terribly outdated.
- Java and JDK
- Check that you have at least Java 8 on command line with
java --version
- If needed, install Java. OpenJDK works well: https://openjdk.java.net/install/
- Check that you have at least Java 8 on command line with
- Clojure CLI tools
- https://clojure.org/guides/getting_started#_clojure_installer_and_cli_tools
- Verify that
clj
on command line opens a Clojure prompt. Close with Ctrl+D.
- Leiningen
- https://leiningen.org/
- Check that Leiningen is in the path with
lein --version
- Git
- Install: https://git-scm.com/book/en/v2/Getting-Started-Installing-Git
- Configure your identity and editor: https://git-scm.com/book/en/v2/Getting-Started-First-Time-Git-Setup
- Heroku CLI
- Requires Git to be installed first
- https://devcenter.heroku.com/articles/heroku-cli#download-and-install
- Docker and Docker Compose
- Mac or Windows: https://www.docker.com/products/docker-desktop
- Linux, Docker: https://docs.docker.com/install/
- Linux, Docker Compose: https://docs.docker.com/compose/install/
- Node.js & NPM/NPX
The important features that you should look for in Clojure IDE are:
- REPL, the IDE should allow access to project REPL
- Evaluating from source, you should be able to select part of source code and send it to REPL for evaluation
Content of the training will be demonstrated using IntelliJ IDEA with Cursive (Clojure) plugin. We are able to offer limited support for other IDEs and configurations.
- Community Edition (free) version of IntelliJ IDEA works well in Clojure development.
- Cursive plugin has a free trial of 30 days.
- See installation instructions: https://cursive-ide.com/userguide/
Calva is a decent and active environment for Clojure and ClojureScript development. See https://marketplace.visualstudio.com/items?itemName=betterthantomorrow.calva
Cider is the de-facto tool for CLJ(S) development in Emacs. See https://github.com/clojure-emacs/cider
Counterclockwise plugin provides Clojure support. It is not commonly used and has had problems with version compatibility. See https://marketplace.eclipse.org/category/free-tagging/counterclockwise.
- Checkout this Git repository on your own computer. Press the green
Clone or download
button in Github UI, and copy the repository URI. Open command line and entergit clone
followed by the repository URI. This will create a subdirectory in the current location of your command line. - Open IntelliJ IDEA and choose
Import project
. - Select
Import project from external sources
->Leiningen
- Do NOT import projects recursively
- When IDEA asks to select project SDK, check that a valid Java install can be found. See above for installing Java JDK.
- Go to
Settings
->Clojure
and selectEvaluate forms in REPL namespace
- Go to
Settings
->Plugins
->Cursive
- Check that you have usable keybindings for
Send form before caret to REPL
andSend top form to repl
- In top right of the IDE view, click on
Add Configuration...
- Press the plus icon to open a popup menu with title
Add New Configuration
.
- It’s an easy mistake to edit templates directly, as the path is the same as below.
- Select
Clojure REPL
->Local
- Give a descriptive name for the REPL. For present purposes, you may want to include
Backend
in the name. - Check that following are selected:
nREPL
andRun with Leiningen
, - Click OK to create this new launch configuration.
- Press "PLAY" icon to start the REPL.
- After REPL opens, top part is the read-only output. Type into the bottom part
(+ 1 1)
. You should get=> 2
as a result. - Open a source file in IDEA. There is a Clojure file under
src/main
. - Move the caret to inside the
(comment ...)
block at bottom. Place the caret after the closing bracket of form(hello "Morty Smith")
. - Use the keyboard shortcut assigned to
Send form before caret to REPL
. The form will be sent to REPL and evaluated. - Move the caret after last quote in
"Morty Smith"
. Try and see what is the difference between keyboard shortcutsSend form before caret to REPL
andSend top form to repl
.
- Add Heroku project’s Git repository as remote:
heroku git:remote -a clojure-training
- Deploy the example app located in
heroku-test
branch to Heroku
git push heroku heroku-test:master
- Open the URL shown in response to view the deployed Clojure web app
- Check the root path
/
for generic message. - Call
/add
with query paramsa
andb
to get dynamic response, e.g.,/?a=5&b=37
.
- Revert to local Git master in Heroku
git push heroku master -f
- NOTE: This time only, we are using
-f
flag to force-push to the remote repository. Usually you want to avoid force-pushing, especially when you have a shared repository.
- The app crashes, as the
master
branch does not have a valid Heroku configuration. Check the cause of the crash from the logs.
heroku logs -t