// plugins, etc.
repositories {
maven {
name = 'Clojars'
url = 'https://repo.clojars.org/'
}
}
// dependencies, etc.
To get dependencies from anywhere you need to list it in your project’s repositories block.
// plugins, etc.
repositories {
maven {
name = 'Clojars'
url = 'https://repo.clojars.org/'
}
}
// dependencies, etc.
You’ll want to set your Clojars credentials in environment variables (in this example, CLOJARS_USER
and CLOJARS_PASSWORD
).
plugins {
id 'maven-publish'
}
// other stuff
publishing {
publications {
main(MavenPublication) {
from components.java
}
}
repositories {
maven {
name = 'clojars'
url = 'https://repo.clojars.org'
credentials {
username = System.env['CLOJARS_USER']
password = System.env['CLOJARS_PASSWORD']
}
}
}
}
Then run the publish
task.
Use the Gradle Shadow plugin.
To create an executable uberjar:
plugins {
id 'dev.clojurephant.clojure' version '<version>'
// this tells Gradle you're generating an application with a main class
id 'application'
// Pulls in the shadow plugin which produces the uberjar
id 'com.github.johnrengelman.shadow' version '6.1.0'
}
mainClassName = 'whatever_your.main.ns.class.is'
// normal repositories and deps blocks
Ensure your main namespace has (:gen-class)
in the ns
declaration:
(ns sample.core
(:require [clojure.string :as string]
[java-time :as time])
(:gen-class))
(defn -main [& args]
(println (str (time/local-date))))
./gradlew shadowJar
will produce the uberjar (look in build/libs
)
./gradlew runShadow
will run the main class of your uberjar
./gradlew distShadowZip
or ./gradlew distShadowTar
will produce a distribution with OS-specific start scripts to run your uberjar. (look in build/distributions
)
Read the Shadow Plugin User Guide. for full details on their other features.
CIDER is a Clojure development environment for Emacs.
Right now you need to manually add the dependency and specify the handler/middleware.
Either apply to all of your projects via an init script:
allprojects {
plugins.withId('dev.clojurephant.clojure') {
dependencies {
devImplementation 'cider:cider-nrepl:0.25.6'
}
clojureRepl {
handler = 'cider.nrepl/cider-nrepl-handler'
}
}
}
Or add it manually to your project:
dependencies {
devImplementation 'cider:cider-nrepl:0.25.16'
}
clojureRepl {
handler = 'cider.nrepl/cider-nrepl-handler'
}
Optionally, omit the handler config and provide it on the CLI:
./gradlew clojureRepl --handler=cider.nrepl/cider-nrepl-handler
Once your REPL starts, use cider-connect
within Emacs to connect to the port listed in your Gradle output.
You can compile Clojure code that depends on Java out of the box. Just put your Java code in the same source set as the Clojure code:
<project>/ src/ main/ java/ sample_java/ Sample.java clojure/ sample_clojure/ core.clj
This requires changing the classpaths for the Clojure build and the Java compile.
// plugins, etc...
clojure.builds {
main {
// reset Clojure classpath to only include dependencies
classpath.from = sourceSets.main.compileClasspath
// or if you also need the sources on the classpath
// classpath.from = sourceSets.main.compileClasspath + tasks.named(sourceSets.main.processResourcesTaskName)
// makes sure you AOT at least the namespace that produces the class(es) Java uses
aotAll()
}
}
tasks.named('compileJava') {
// add clojure's compiled output onto the Java compiler output
classpath += files(sourceSets.main.clojure.classesDirectory)
}
// dependencies, etc...
Similar approaches should apply for other JVM languages (e.g. Groovy or Kotlin). |
Can you improve this documentation?Edit on GitHub
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close