{% include nav.md %}
NOTE: This example assumes Gradle 4 or higher.
Gradle is a build automation tool in the same space as Maven, Leiningen, and Boot. Gradle is primarily targeted at projects using the JVM, but has plugins for many other languages. (Now including Clojure!)
See Gradle's installation documentation.
$ mkdir my-project
$ cd my-project
$ gradle init
From here on out you'll use
./gradlew
instead ofgradle
in your commands.gradlew
is the Gradle Wrapper which allows you to set a per-project Gradle version. This ensures all developers use the same Gradle version for the project, instead of whatever happens to be on theirPATH
.
Also see Gradle's Creating New Gradle Builds.
To include plugins from Gradle's Plugin Portal you'll use a plugins {}
block. This should be at the top of your build.gradle
.
plugins {
id 'gradle-clojure.clojure' version '0.4.0'
// any additional plugins declared here
}
Also see Gradle's Using Plugins.
group = 'my.example' // the group ID your artifacts should be published under
version = '0.1.0-SNAPSHOT' // the version your artifacts should be published under
See Gradle's Introduction to Dependency Management.
No repositories are specified by default, so you must list any repositories you want to search for your dependencies.
IMPORTANT: gradle-clojure currently requires jcenter()
(or mavenCentral()
and Clojars) be included in your repository list.
repositories {
// shorthand for https://repo1.maven.org/maven2
mavenCentral()
// shorthand for https://jcenter.bintray.com/
jcenter()
// for any other maven repository
maven {
name = 'Clojars' // name can be ommitted, but is helpful in troubleshooting
url = 'https://repo.clojars.org/'
}
}
Also see Gradle's Declaring Repositories.
Unless you have a reason to do otherwise, use Gradle's shorthand syntax <configuration> '<group>:<artifact>:<version>'
(e.g. compile 'org.clojure:clojure:1.9.0'
) to specify dependencies.
Dependencies are put in different configurations (somewhat similar to Maven scopes). For Clojure's purposes, the three main ones to be aware of are:
implementation
- dependencies of your main application codetestImplementation
- dependencies of your test codedevImplementation
- dependencies used only in the REPLdependencies {
implementation 'org.clojure:clojure:1.9.0'
// due to how clojure.test is executed, an explicit JUnit 4 dependency is needed
testImplementation 'junit:junit:4.12'
// due to the way Gradle's REPL is started, if you need tools.namespace, you must be on 0.3+
devImplementation 'org.clojure:tools.namespace:0.3.0-alpha4'
}
Also see Gradle's Declaring Dependencies
Full build.gradle
example:
plugins {
id 'gradle-clojure.clojure' version '0.4.0'
}
group = 'my.example'
version = '0.1.0-SNAPSHOT'
repositories {
jcenter()
}
dependencies {
implementation 'org.clojure:clojure:1.9.0'
testImplementation 'junit:junit:4.12'
devImplementation 'org.clojure:tools.namespace:0.3.0-alpha4'
}
Can you improve this documentation?Edit on GitHub
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close