I'm trying to use gradle/Clojuresque to build clojure code, run it, and get uberjar. I use hints from http://dev.clojure.org/display/doc/Getting+Started+with+Gradle, https://bitbucket.org/kotarak/clojuresque/wiki/Getting%20Started, and 'Could not find us.bpsm:edn-java:0.4.3' error with Gradle for Clojure (Clojuresque).
This is the grade script.
buildscript {
repositories {
maven { url "http://clojars.org/repo" }
mavenCentral()
}
dependencies {
classpath "clojuresque:clojuresque:1.7.0"
}
}
apply plugin: 'clojure'
clojure.aotCompile = true
repositories {
flatDir dirs: project.file("lib/runtime")
maven { url "http://clojars.org/repo" }
}
With gradle build
task, there is no error and I have a jar file, but I don't see any class file generated; I don't think the generated jar contains nothing, especially when I compared the results from manual build (Compile clojure source into class (AOT) from command line (not using lein)).
.
├── build
│ ├── libs
│ │ └── clojure.jar
│ └── tmp
│ └── jar
│ └── MANIFEST.MF
├── build.gradle
└── src
└── hello
└── core.clj
This is the core.clj
(ns hello.core
(:gen-class))
(defn -main
"This should be pretty simple."
[]
(println "Hello, World!"))
What might be wrong? Also, how to run the code and get uberjar like lein run
and lein uberjar
does?
I zipped the directory in https://dl.dropboxusercontent.com/u/10773282/share/2015/clojure_test.zip
Create the class files
The source code should be located in
./src/main/clojure
as it is the default directory.One can specify source file in gradle file, though.
The other issue was with missing dependencies:
gradle build
will generate the class files.Get the jar file
We need to set the main class for the jar file.
I'm not exactly sure if the setup is quite necessary;
gradle jar
will generate the jar file.execute the jar file
This is the command to run the code:
uberjar
There are three modifications needed: hints from https://github.com/DevonStrawn/Clojuresque-Boilerplate/blob/master/UberJar/build.gradle.
Execute the uberjar
Now just one jar for the execution
The new build.gradle file
Shadow jar
From Opal's answer, I add the gradle script that create shadowJar. It contains the MAINFEST file that sets up the Main-Class.
Or use these two lines of code instead of the manifest change code:
Execute the shadow jar
Get the ubjer jar
It's the same as uberjar.
References
You're missing maven central repository:
And you both modify gradle source sets or move
hello/core.clj
tosrc/main/clojure
where gradle by default looks for sources. With these changes jar file is generated and can be run when valid cp provided - I've no clojure installed so can't check it easily.EDIT
Here a sample project can be found that has all the changes I introduced. It also produces uber jar with
shadowJar
task that has clojure dependency built-in and can enableshello.core
to be run with the following command:EDIT2
Now the github example produces runnable jar.