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.
sourceSets {
main {
clojure {
srcDirs = ['src']
}
}
}
The other issue was with missing dependencies:
repositories {
maven { url "http://clojars.org/repo" }
mavenCentral()
}
dependencies {
compile "org.clojure:clojure:1.6.0"
}
gradle build will generate the class files.
Get the jar file
We need to set the main class for the jar file.
jar
{
manifest.attributes("Main-Class": "hello.core")
}
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:
java -cp .:<PATH>/clojure-1.6.0.jar:build/libs/clojure_test.jar hello.core
uberjar
There are three modifications needed: hints from https://github.com/DevonStrawn/Clojuresque-Boilerplate/blob/master/UberJar/build.gradle.
uberjar
{
manifest.attributes("Main-Class": "hello.core")
}
apply plugin: 'application'
uberjar.enabled = true
Execute the uberjar
Now just one jar for the execution
clojure_test> java -jar build/libs/clojure_test-standalone.jar
Hello, World!
The new build.gradle file
buildscript {
repositories {
maven { url "http://clojars.org/repo" }
mavenCentral()
}
dependencies {
classpath "clojuresque:clojuresque:1.7.0"
}
}
apply plugin: 'clojure'
clojure.aotCompile = true
sourceSets {
main {
clojure {
srcDirs = ['src']
}
}
}
repositories {
maven { url "http://clojars.org/repo" }
mavenCentral()
}
dependencies {
compile "org.clojure:clojure:1.7.0"
}
jar
{
manifest.attributes("Main-Class": "hello.core")
}
uberjar
{
manifest.attributes("Main-Class": "hello.core")
}
apply plugin: 'application'
uberjar.enabled = true
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.
buildscript {
repositories {
maven { url "http://clojars.org/repo" }
mavenCentral()
jcenter()
}
dependencies {
classpath "clojuresque:clojuresque:1.7.0"
classpath 'com.github.jengelman.gradle.plugins:shadow:1.2.0'
}
}
apply plugin: 'application'
apply plugin: 'clojure'
apply plugin: 'com.github.johnrengelman.shadow'
clojure.aotCompile = true
mainClassName = 'hello.core'
sourceSets {
main {
clojure {
srcDirs = ['src']
}
}
}
repositories {
maven { url "http://clojars.org/repo" }
mavenCentral()
}
dependencies {
compile "org.clojure:clojure:1.7.0"
}
Or use these two lines of code instead of the manifest change code:
apply plugin: 'application'
mainClassName = 'hello.core'
Execute the shadow jar
Get the ubjer jar
gradle shadow
It's the same as uberjar.
clojure_test> java -jar build/libs/clojure_test-all.jar
Hello, World!
References
https://github.com/johnrengelman/shadow
Boiler plate - https://github.com/DevonStrawn/Clojuresque-Boilerplate
Building a uberjar with Gradle
You're missing maven central repository:
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" }
mavenCentral()
}
dependencies {
compile "org.clojure:clojure:1.6.0"
}
And you both modify gradle source sets or move hello/core.clj to src/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 enables hello.core to be run with the following command:
java -cp build/libs/29015575-all.jar hello.core
EDIT2
Now the github example produces runnable jar.
Related
im using liferay 7.1 ,and when i want to deploy a SpringMvcPortlet i got this error :
Could not resolve all files for configuration ':wars:mySpringMvcPortlet:compileClasspath'.
Could not find javax.validation:validation-api:.
Required by:
project :wars:SpringMvcPortletFormation
Could not find org.hibernate.validator:hibernate-validator:.
Required by:
project :wars:SpringMvcPortletFormationPossible solution:
Declare repository providing the artifact, see the documentation at https://docs.gradle.org/current/userguide/declaring_repositories.html
Do you have an idea where my error is?
Thanks in advance
You have a dependency issue here, you have to manage all your dependency for the SpringMvcPortletFormationPossible project, and you need to put them properly in the build.gradle file,
So I recommand to add mavenLocal() to the repositories { } to be able to search all the local dependencies from the local repo and find them properly:
Example:
buildscript {
dependencies {
classpath group: "com.liferay", name: "com.liferay.gradle.plugins", version: "3.13.8"
}
repositories {
mavenLocal()
maven {
url "https://repository-cdn.liferay.com/nexus/content/groups/public"
}
}
}
apply plugin: "com.liferay.plugin"
dependencies { .... // your dependency here // .... }
repositories {
mavenLocal()
maven {
url "https://repository-cdn.liferay.com/nexus/content/groups/public"
}
}
So I have a spring boot project that is using freemarker and is built using gradle.
This is my build.gradle
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:2.1.9.RELEASE")
}
}
plugins {
id 'org.springframework.boot' version '2.1.9.RELEASE'
id 'io.spring.dependency-management' version '1.0.8.RELEASE'
id 'java'
id 'application'
}
group = 'some.project'
version = '4'
mainClassName = "some.project.Application"
repositories {
mavenCentral()
}
dependencies {
compile("org.springframework.boot:spring-boot-starter-web") {
exclude group: 'org.springframework.boot', module: 'spring-boot-starter-tomcat'
}
compile('org.springframework.boot:spring-boot-starter-data-jpa') {
exclude group: 'org.apache.tomcat', module: 'tomcat-jdbc'
}
implementation 'org.springframework.boot:spring-boot-starter-jetty'
implementation 'org.springframework.boot:spring-boot-starter-freemarker'
}
jar {
// include all the jars
from {
(configurations.runtime).collect {
it.isDirectory() ? it : zipTree(it)
}
}
manifest {
attributes 'Main-Class': 'some.project.Application'
}
}
I have decided to start using scss because my css files were becoming a little difficult to manage and keep consistent. However I can't seem to figure out how to get my application to load up scss files. All the scss files are located in resources/static/scss, what should I do with them so that they become css and readable by my spring boot application and freemarker?
I have this as settings.gradle
buildscript {
repositories {
maven {
url 'https://plugins.gradle.org/m2/'
}
}
dependencies {
classpath 'gradle.plugin.net.vivin:gradle-semantic-build-versioning:4.0.0'
}
}
apply plugin: 'net.vivin.gradle-semantic-build-versioning'
I need to convert it to a settings.gradle.kts kotlin DSL file. I tried:
buildscript {
repositories {
maven {
url = uri("https://plugins.gradle.org/m2/")
}
}
dependencies {
classpath("gradle.plugin.net.vivin:gradle-semantic-build-versioning:4.0.0")
}
}
apply ("gradle.plugin.net.vivin.gradle-semantic-build-versioning")
This gives the error:
Cannot apply plugin of class 'org.gradle.api.Plugin' to
'net.vivin.gradle-semantic-build-versioning' (class: java.lang.String)
as it does not implement PluginAware
What is the problem here?
The solution is:
plugins.apply("net.vivin.gradle-semantic-build-versioning")
react-native-cli: 2.0.1
react-native: 0.42.0
npm :3.5.2
I install sqlite on react native using this tutorial:
https://github.com/remobile/react-native-sqlite
when I'm done I executed this command :
react-native run-android
I have this error :
Cannot parse yarn version: 0.22
Scanning 547 folders for symlinks in /home/sofiane/projet/sql/node_modules (6ms)
Starting JS server...
Building and installing the app on the device (cd android && ./gradlew installDebug)...
FAILURE: Build failed with an exception.
* Where:
Build file '/home/sofiane/projet/sql/android/build.gradle' line: 9
* What went wrong:
A problem occurred evaluating root project 'sql'.
> Could not find method compile() for arguments [project ':react-native-sqlite'] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.
build.gradle :
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.3'
compile project(':react-native-sqlite')
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
mavenLocal()
jcenter()
maven {
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
url "$rootDir/../node_modules/react-native/android"
}
}
}
You should configure <name-project>/android/app/build.gradle' not <name-project>/android/build.gradle'.
In my case the structure of the gradle file was the problem, i accidetally duplicated the dependencias on allprojects session
from :
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.5.2'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
google()
}
dependencies { //=> duplicated
classpath 'com.android.tools.build:gradle:3.5.2'
classpath "io.realm:realm-gradle-plugin:6.0.1"
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
to
buildscript {
ext.objectboxVersion = '2.1.0'
repositories {
jcenter()
maven {
url 'https://maven.google.com/'
name 'Google'
}
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.5.1'
classpath "io.realm:realm-gradle-plugin:6.0.1"
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
Hope this helps someone.
The problem:
I have a jar in some repository.
I want to run the jar and do something with it during gradle task.
The attempt:
apply plugin: 'java'
repositories {
maven {
url "<<<valid repo url>>>"
}
mavenCentral()
}
dependencies {
compile(group: 'com.google.developers', name: 'compiler', version: 'v20150315', ext: 'pom')
}
task doTheJar {
dependsOn configurations.compile
exec {
executable "sh"
args "-c","java -jar <<the-artifact>> smoething something"
}
}
Is there a way to do it?
Is there a way to do it without java plugin?
Thanks.
It will be better to do it in the following way:
apply plugin: 'java'
repositories {
maven {
url "<<<valid repo url>>>"
}
mavenCentral()
}
configurations {
runjar
}
dependencies {
runjar 'some:artifact:1.0'
}
task runTheJar(type: JavaExec) {
main 'main.class.to.be.run'
classpath configurations.runjar
args 's1', 's2', 's3'
}