I'm using Gradle as my build configuration tool. I'm developing on my Windows desktop but the actual distribution will be run on Linux.
When I run the 'distZip' task it generates a zip file which contains a .bat file which runs fine on Windows but not on Linux.
Is there a way to configure Gradle so that it will create a Linux compatible script?
Here is my build.gradle file:
buildscript {
repositories {
maven { url "http://repo.spring.io/libs-snapshot" }
mavenLocal()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:1.0.0.RC3")
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'spring-boot'
jar {
baseName = 'gs-rest-service'
version = '0.1.0'
}
repositories {
mavenCentral()
maven { url "http://repo.spring.io/libs-snapshot" }
}
mainClassName="com.RestfulServer.Application"
dependencies {
compile("org.springframework.boot:spring-boot-starter-web")
compile("com.fasterxml.jackson.core:jackson-databind")
compile 'org.slf4j:slf4j-api:1.7.6'
compile 'ch.qos.logback:logback-classic:1.1.1'
compile 'ch.qos.logback:logback-core:1.1.1'
// Local file dependencies
compile files('libraries/AWS/aws-java-sdk-1.7.2.jar',
'libraries/AWS/third-party/joda-time-2.2/joda-time-2.2.jar',
'libraries/AWS/third-party/httpcomponents-client-4.2.3/httpclient-4.2.3.jar',
'libraries/AWS/third-party/httpcomponents-client-4.2.3/httpcore-4.2.jar')
testCompile("junit:junit")
}
task wrapper(type: Wrapper) {
gradleVersion = '1.11'
}
The distZip from the application plugin already creates shell scripts as well as .bat files. It should be in your zip file too.
Related
Spring boot makes it really easy to setup a simple app.
But it takes me longer to actually get a jar file which I can upload to a remote server.
I am using IntelliJ, no command line, and I use gradle. The application is running somehow out of Intellij. But where are the created files? Where is my jar from Bootjar?
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:2.0.0.RELEASE")
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
bootJar {
baseName = 'gs-spring-boot'
version = '0.1.0'
}
repositories {
mavenCentral()
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
dependencies {
compile("org.springframework.boot:spring-boot-starter-web")
compile("org.springframework.boot:spring-boot-starter-actuator")
testCompile("org.springframework.boot:spring-boot-starter-test")
// add spring data repos
compile("org.springframework.boot:spring-boot-starter-data-jpa")
compile("org.postgresql:postgresql:42.2.4")
// REST interface
compile("org.springframework.boot:spring-boot-starter-data-rest")
// Security
compile("org.springframework.boot:spring-boot-starter-security")
}
Update: Added a picture of the project structure:
Update 2: Folder structure:
There will not be a jar created if you are just running this in your IDE. In order to do that, you need to run the gradle build (in your case) either from your IDE or the command line to get it to build it into a jar.
From the command line, go to your project directory and type this:
./gradlew build
This executes the gradle wrapper, which should download everything you need to run the build, and then executes the build.
You will then find your jar in build/lib
build/libs (if you've ran build to build the jar file)
As of now I have made a chatbot application by combining Java and Google Sheets using the Google API which requires me to use Gradle. So far I have only been able to run the program through Gradle using the terminal.
In my end result I want to be able to send this program to someone and they should be able to install it or run it as easy as possible without having to run it through the terminal.
I suspect that the person might need to download Gradle to run the file since it is needed for the Google API. So I think the best way to do this is to send a zip file (or something else) with the Gradle Installer and the java file and somehow make it install everything automatically. Is this possible?
This is how my build.gradle file looks like
apply plugin: 'java'
apply plugin: 'application'
mainClassName = 'SheetsQuickstart'
sourceCompatibility = 1.7
targetCompatibility = 1.7
version = '1.0'
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.github.jengelman.gradle.plugins:shadow:2.0.1'
}
}
repositories {
mavenCentral()
}
dependencies {
compile 'com.google.api-client:google-api-client:1.23.0'
compile 'com.google.oauth-client:google-oauth-client-jetty:1.23.0'
compile 'com.google.apis:google-api-services-sheets:v4-rev516-1.23.0'
compile(group: 'org.springframework', name: 'spring-core', version:'4.3.11.RELEASE')
}
jar {
doFirst {
manifest {
if (!configurations.compile.isEmpty()) {
attributes(
'Class-Path':configurations.compile.collect{it.toURI().toString()}.join(' '),
'Main-Class': 'SheetsQuickstart')
}
}
}
}
Assuming google sheets api is a dependency within gradle, cant you just build a jar file through gradle build then run the jar as an executable file?
build.gradle file example:
version '1.0-SNAPSHOT'
apply plugin: 'java'
apply plugin: 'application'
apply plugin: 'com.github.johnrengelman.shadow'
group = 'your.package.path.here'
version = '0.0.1-SNAPSHOT'
mainClassName = 'your.package.path.here.MainClassName'
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.github.jengelman.gradle.plugins:shadow:2.0.1'
}
}
dependencies {
compile(group: 'org.springframework', name: 'spring-core', version:'4.3.11.RELEASE')
}
repositories {
mavenCentral()
}
jar {
doFirst {
manifest {
if (!configurations.compile.isEmpty()) {
attributes(
'Class-Path':configurations.compile.collect{it.toURI().toString()}.join(' '),
'Main-Class': 'your.package.path.here.MainClassName')
}
}
}
Should be enough for a reg min build file, then add your dependencies.
I am a gradle beginner and I am struggling to include the frontend distribution build folder in the backend jar (I use Spring Boot and the frontend is an ionic app). In the backend.gradle, I configured the jar-Task that should include the frontend-build folder (called www) into build folder of the backend. The jar task runs through, but the desired artifacts are not present in the backend-build folder and therefore not in the final jar. Would be glad for any help.
project structure:
project
build.gradle
settings.gradle
backend
--> backend.gradle
frontend
--> frontend.gradle
settings.gradle
include 'backend'
include 'frontend'
rootProject.children.each {
it.buildFileName = it.name + '.gradle'
}
build.gradle
allprojects {
buildscript {
repositories {
mavenCentral()
}
}
apply plugin: 'idea'
repositories {
mavenCentral()
}
}
frontend.gradle
plugins {
id "com.moowork.node" version "1.2.0"
}
task clean(dependsOn: 'npm_run_clean') {
}
task build(dependsOn: 'npm_run_build') {
}
backend.gradle
buildscript {
ext {
springBootVersion = '1.5.8.RELEASE'
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
apply plugin: 'java'
apply plugin: 'org.springframework.boot'
group = 'ch.renewinkler'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = 1.8
jar {
from('frontend/www') {
into('public')
}
}
processResources.dependsOn(':frontend:build')
dependencies {
compile('org.springframework.boot:spring-boot-starter-web')
testCompile('org.springframework.boot:spring-boot-starter-test')
}
You need to tell gradle that the jar task depends on the frontend's build task, otherwise it could run the jar file before the build task, and thus have nothing to include in the jar.
It's also a better idea to refer to projects by their name, instead of using absolute paths:
jar {
dependsOn(':frontend:build')
into('public') {
from "${project(':frontend').projectDir}/www"
}
}
I'm very new to whole tomcat/spring/eclipse world.
I used gradle a little bit for android projects.
This is a project with tomcat/spring/eclipse and I 'd like to build it with gradle.
I copied a build.gradle file from one of tutorial on the web.
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:1.2.5.RELEASE")
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'spring-boot'
jar {
baseName = 'gs-serving-web-content'
version = '0.1.0'
}
repositories {
mavenCentral()
}
sourceCompatibility = 1.7
targetCompatibility = 1.7
dependencies {
compile("org.springframework.boot:spring-boot-starter-thymeleaf")
testCompile("junit:junit")
}
task wrapper(type: Wrapper) {
gradleVersion = '2.3'
}
Now I run > gradle build and I see tons of errors which says 'org.springframework.*** does not exist'
I guess I need to somehow tell gradle to include *.jar files under
WebContent/WEB-INF/lib directory, but don't know how.
Please let me know if need to supply more info.
To add all jar files from WebContent/WEB-INF/lib and subfolders you must include the first line:
dependencies {
compile(fileTree(dir: "WebContent/WEB-INF/lib", include: "**/*.jar"))
compile("org.springframework.boot:spring-boot-starter-thymeleaf")
testCompile("junit:junit")
}
I am trying to make this application work and the building is configured in gradle. When I use jettyRun in cmd to run the application it works as expected however when I open the actuall code in eclipse I am missing all of these dependecies such as spring or hibernate and others... I am unsure how to resolve this
The gradle.build looks like this
apply plugin: 'java'
apply plugin: 'war'
apply plugin: 'eclipse-wtp'
apply plugin: 'jetty'
// JDK 7
sourceCompatibility = 1.8
targetCompatibility = 1.8
repositories {
mavenLocal()
mavenCentral()
}
dependencies {
compile 'ch.qos.logback:logback-classic:1.1.3'
compile 'org.springframework:spring-webmvc:4.1.6.RELEASE'
compile 'javax.servlet:jstl:1.2'
compile 'org.springframework:spring-orm:4.1.6.RELEASE'
compile 'org.springframework:spring-tx:4.1.6.RELEASE'
compile 'org.springframework:spring-jdbc:4.1.6.RELEASE'
compile 'mysql:mysql-connector-java:5.1.31'
compile 'org.hibernate:hibernate-core:4.3.10.Final'
compile 'org.hibernate:hibernate-entitymanager:4.3.10.Final'
}
// Embeded Jetty for testing
jettyRun{
contextPath = "etnshop"
httpPort = 8080
}
jettyRunWar{
contextPath = "etnshop"
httpPort = 8080
}
//For Eclipse IDE only
eclipse {
wtp {
component {
//define context path, default to project folder name
contextPath = 'etnshop'
}
}
}
Using the command gradle eclipse fixed the problem.