Spring Batch with Grails - spring-boot

im currently using grails 3.0.3 along with gradle 2.5 and hoping to generate a plugin that will use Spring Batch. I've just created a plugin via the command line, and update the build.gradle with just the
compile "org.springframework.boot:spring-boot-starter-batch"
However the batch folder does not seem to downloaded to the local .m2 cache and therefore the import org.springframework.batch libs not available.
The following is the build.gradle. Just wondering if anybody could suggest the reasons why?
Thanks
buildscript {
ext {
grailsVersion = project.grailsVersion
}
repositories {
mavenLocal()
mavenCentral()
maven { url "https://repo.grails.org/grails/core" }
}
dependencies {
classpath "org.grails:grails-gradle-plugin:$grailsVersion"
}
}
plugins {
id "io.spring.dependency-management" version "0.5.2.RELEASE"
id "com.jfrog.bintray" version "1.2"
}
version "0.1-SNAPSHOT"
group "org.grails.plugins"
apply plugin: 'maven-publish'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: "spring-boot"
apply plugin: "org.grails.grails-plugin"
apply plugin: "org.grails.grails-gsp"
// Used for publishing to central repository, remove if not needed
apply from:'https://raw.githubusercontent.com/grails/grails-profile-repository/master/profiles/plugin/templates/grailsCentralPublishing.gradle'
apply from:'https://raw.githubusercontent.com/grails/grails-profile-repository/master/profiles/plugin/templates/bintrayPublishing.gradle'
ext {
grailsVersion = project.grailsVersion
gradleWrapperVersion = project.gradleWrapperVersion
}
sourceCompatibility = 1.7
targetCompatibility = 1.7
repositories {
mavenLocal()
mavenCentral()
maven { url "https://repo.grails.org/grails/core" }
}
dependencyManagement {
imports {
mavenBom "org.grails:grails-bom:$grailsVersion"
}
applyMavenExclusions false
}
dependencies {
provided 'org.springframework.boot:spring-boot-starter-logging'
provided "org.springframework.boot:spring-boot-starter-actuator"
provided "org.springframework.boot:spring-boot-autoconfigure"
provided "org.springframework.boot:spring-boot-starter-tomcat"
provided "org.grails:grails-web-boot"
provided "org.grails:grails-dependencies"
provided 'javax.servlet:javax.servlet-api:3.1.0'
testCompile "org.grails:grails-plugin-testing"
console "org.grails:grails-console"
//compile "org.springframework.boot:spring-boot-starter-batch:1.2.5.RELEASE"
compile "org.springframework.boot:spring-boot-starter-batch"
}
task wrapper(type: Wrapper) {
gradleVersion = gradleWrapperVersion
}

Related

unable to run the springboot jar from command line

My requirement is to build a spring boot jar in standalone tomcat executable.I am not able to run the jar from command line.
I am using gradle
buildscript {
ext {
springBootVersion = '1.4.0.RELEASE'
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'spring-boot'
group = 'com.test'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
compile project(':testProject')
implementation('org.springframework.boot:spring-boot-starter-web')
testImplementation('org.springframework.boot:spring-boot-starter-test')
}
configurations {
all*.exclude module: 'spring-boot-starter-logging'
}
jar {
manifest {
attributes 'Implementation-Title': 'SpringAppApplication',
'Implementation-Version': version
}
}
running java -jar target/SpringAppApplication-0.0.1-SNAPSHOT.jar
I get error Invalid or corrupt jarfile SpringApp-0.0.1-SNAPSHOT.jar
.Tried giving the complete path also.

Gradle build doesn't add version to package

I'm creating a REST microservice using Spring Boot 2.0.0.M7 with Gradle 4.2.
When I build from Eclipse or run from console ./gradlew build, the produced package in build/libs is named $app.jar instead of $app-$version.jar.
What am I missing? my build.gradle is the same as the Spring Boot Docker GS guide, and this problem prevent docker image to be built because the jar can't be found.
Here is my build.gradle file:
buildscript {
ext {
springBootVersion = '2.0.0.M7'
springCloudVersion = 'Finchley.M5'
gradleDockerVersion = '0.13.0'
}
repositories {
mavenCentral()
maven { url 'https://plugins.gradle.org/m2/' }
maven { url 'https://repo.spring.io/snapshot' }
maven { url 'https://repo.spring.io/milestone' }
maven { url 'https://repo.spring.io/libs-milestone' }
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
classpath("gradle.plugin.com.palantir.gradle.docker:gradle-docker:${gradleDockerVersion}")
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'com.palantir.docker'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
jar {
baseName = 'networks'
version = '0.9'
}
group = 'test'
sourceCompatibility = 1.8
targetCompatibility = 1.8
repositories {
mavenCentral()
maven { url 'https://repo.spring.io/snapshot' }
maven { url 'https://repo.spring.io/milestone' }
maven { url 'https://repo.spring.io/libs-milestone' }
}
dependencyManagement {
imports {
mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
}
}
dependencies {
compile 'org.springframework.boot:spring-boot-starter-web'
compile 'org.springframework.boot:spring-boot-starter-data-jpa'
compile 'org.springframework.boot:spring-boot-starter-data-rest'
compile 'org.springframework.boot:spring-boot-starter-json'
compile 'org.springframework.boot:spring-boot-starter-actuator'
compile 'org.springframework.cloud:spring-cloud-starter-netflix-eureka-client'
runtime 'org.springframework.boot:spring-boot-devtools'
runtime 'org.postgresql:postgresql'
testCompile 'org.springframework.boot:spring-boot-starter-test'
testCompile 'junit:junit'
}
docker {
name "${project.group}/${jar.baseName}"
files jar.archivePath
buildArgs(['JAR_FILE': "${jar.archiveName}"])
}
The version should be specified outside jar:
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'com.palantir.docker'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
version = "0.9"
jar {
baseName = 'networks'
}

Using Spring.IO dependency management, how can I override the version of a particular jar?

I'm making use of the aws java sdk that relies on a jackson version that is greater than what is in the spring bom, I need to be able to override the version (to use a version more compatible with the aws sdk). How can I override the version of a particular jar?
buildscript {
repositories {
maven { url "https://mvnrepo.----.net/nexus/content/groups/public/" }
}
dependencies {
classpath 'io.spring.gradle:dependency-management-plugin:0.5.3.RELEASE'
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'io.spring.dependency-management'
sourceCompatibility = 1.8
targetCompatibility = 1.8
version = 1.0
repositories {
maven { url "https://mvnrepo.-----.net/nexus/content/groups/public/"}
}
dependencyManagement {
imports {
mavenBom 'io.spring.platform:platform-bom:1.1.4.RELEASE'
}
}
dependencies {
compile 'org.springframework:spring-context',
'org.springframework:spring-core',
'org.springframework:spring-test',
'com.amazonaws:aws-java-sdk-dynamodb:1.10.+',
'com.amazonaws:aws-java-sdk-s3:1.10.+',
'com.amazonaws:aws-java-sdk-sns:1.10.+',
'com.amazonaws:aws-java-sdk-logs:1.10.+',
'com.google.code.gson:gson',
'joda-time:joda-time',
'org.slf4j:slf4j-api'
testCompile 'junit:junit:4.12',
'org.mockito:mockito-core:1.+'
}
task wrapper(type: Wrapper) {
gradleVersion = '2.7'
}
dependencyManagement {
imports {
mavenBom 'io.spring.platform:platform-bom:1.1.4.RELEASE'
}
dependencies {
dependency 'com.fasterxml.jackson.core:jackson-core:2.6.3'
dependency 'com.fasterxml.jackson.core:jackson-databind:2.6.3'
dependency 'com.fasterxml.jackson.core:jackson-annotations:2.6.3'
}
}

Gradle dependency plugin in a multi module Spring Boot project

What does a correct Gradle configuration look like in a multi-module project that uses the Gradle plugins spring-boot-dependencies and spring-boot?
I have the following project setup:
parent
|
+ build.gradle
|
+ alpha
| |
| + build.gradle
|
+ beta
| |
| + build.gradle
The parent module contains common project configuration.
The alpha module is a module in which I would like to import dependencies using versions numbers specified in the spring-boot-dependencies bom, but the result of the is a standard jar.
The beta module is a module that depends on alpha and the result is an executable Spring Boot jar file (including all dependencies). Consequently, this project needs both the spring-boot-dependencies as well as the spring-boot plugin.
In order to keep the Gradle files DRY, I have extracted common module scripts to the parent's build.gradle file.
Attempts to execute $ gradle build using the project configuration below results in:
> Plugin with id 'io.spring.dependency-management' not found.
parent gradle.build
allprojects {
group = "com.example"
version '0.0.1-SNAPSHOT'
ext {
dependencyManagementPluginVersion = '0.5.3.RELEASE'
springBootVersion = '1.3.0.RC1'
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
}
subprojects {
sourceCompatibility = 1.8
targetCompatibility = 1.8
buildscript {
repositories {
jcenter()
maven { url "https://repo.spring.io/snapshot" }
maven { url "https://repo.spring.io/milestone" }
}
dependencies {
classpath("io.spring.gradle:dependency-management-plugin:${dependencyManagementPluginVersion}")
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
apply plugin: 'io.spring.dependency-management'
dependencyManagement {
imports {
mavenBom("org.springframework.boot:spring-boot-dependencies:${springBootVersion}")
// mavenBom("org.springframework.boot:spring-boot-starter-parent:${springBootVersion}")
}
}
}
alpha build.gradle
dependencies {
compile('org.springframework:spring-web')
}
beta gradle.build
apply plugin: 'spring-boot'
dependencies {
compile project(':alpha')
compile('org.springframework.boot:spring-boot-starter')
compile('org.springframework.boot:spring-boot-starter-web')
}
Comments:
The behavior of the spring-boot plugin was changed in Spring Boot 1.3.0.M1
Gradle version: 2.8
Spring Boot version 1.3.0.RC1
It turns out that parent/build.gradle should be rearranged in the following way:
buildscript {
ext {
dependencyManagementPluginVersion = '0.5.3.RELEASE'
springBootVersion = '1.3.0.RC1'
}
repositories {
jcenter()
maven { url "https://repo.spring.io/snapshot" }
maven { url "https://repo.spring.io/milestone" }
}
dependencies {
classpath("io.spring.gradle:dependency-management-plugin:${dependencyManagementPluginVersion}")
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
allprojects {
group = "com.example"
version '0.0.1-SNAPSHOT'
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
}
subprojects {
sourceCompatibility = 1.8
targetCompatibility = 1.8
apply plugin: 'io.spring.dependency-management'
dependencyManagement {
imports {
mavenBom("org.springframework.boot:spring-boot-dependencies:${springBootVersion}")
// mavenBom("org.springframework.boot:spring-boot-starter-parent:${springBootVersion}")
}
}
}
The problem lies in the fact that buildscript block for subprojects was indeed configured well but... in a wrong place. This subprojects block relates to subprojects but it will be evaluated in the script it was declared, and there were no dependencies declared for the plugin it was trying to apply.

How to use Gradle with Spring Boot to get Gosling Release Train of Spring data?

How can I get the latest Gosling release train into my Gradle build file?
I used to be using the 1.1.9.RELEASE group for most of my dependencies. Now I need to fix the problem with RepositoryRestMvcConfiguration mentioned here and to do so I am trying to upgrade to the latest release of spring Data, which has fixed the bug according to the github issue I linked to.
When I added the Gosling release train dependencies I also removed the spring boot starters for spring-data-jpa and spring-data-rest thinking I might have dependency conflicts. Doing this pulled in the new jar files but now I am getting cannot find symbol errors on all my javax.persistence annotations.
Can I use the Gosling release train with the spring boot starters or do I have to figure out how to pull in all spring boot dependencies manually in order to use Gosling?
I am using Gradle 2.3.10 on Mac OS X Yosemite.
New Code
buildscript {
ext {
springBootVersion = '1.3.0.M3'
}
repositories {
jcenter()
mavenCentral()
//maven { url "https://repo.spring.io/snapshot" }
maven { url "https://repo.spring.io/milestone" }
}
dependencies {
classpath "io.spring.gradle:dependency-management-plugin:0.5.0.RELEASE"
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'spring-boot'
apply plugin: "io.spring.dependency-management"
ext {
springVersion = '4.1.6.RELEASE'
springDataVersion = 'Gosling-RELEASE'
}
dependencyManagement {
imports {
mavenBom "org.springframework:spring-framework-bom:${springVersion}"
mavenBom "org.springframework.data:spring-data-releasetrain:${springDataVersion}"
}
}
jar {
baseName = 'my-data-api'
version = '0.0.1'
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
repositories {
jcenter()
mavenCentral()
//maven { url "https://repo.spring.io/snapshot" }
maven { url "https://repo.spring.io/milestone" }
}
dependencies {
compile("org.springframework.boot:spring-boot-starter-actuator:1.3.0.M3")
compile("org.springframework.boot:spring-boot-starter-aop:1.3.0.M3")
compile 'org.springframework.data:spring-data-jpa'
compile 'org.springframework.data:spring-data-rest-webmvc'
compile("org.springframework.boot:spring-boot-starter-web:1.3.0.M3")
compile("org.springframework.boot:spring-boot-starter-jdbc:1.3.0.M3")
compile('org.antlr:stringtemplate:4.0.2')
compile('org.apache.commons:commons-lang3:3.0')
compile('commons-io:commons-io:2.4')
compile('com.ingres.jdbc:iijdbc:10.0-4.0.5')
testCompile("org.springframework.boot:spring-boot-starter-test:1.3.0.M3")
}
Old code
buildscript {
ext {
springBootVersion = '1.3.0.M2'
}
repositories {
jcenter()
mavenCentral()
maven { url "https://repo.spring.io/snapshot" }
maven { url "https://repo.spring.io/milestone" }
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'spring-boot'
jar {
baseName = 'my-data-api'
version = '0.0.1'
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
repositories {
jcenter()
mavenCentral()
maven { url "https://repo.spring.io/snapshot" }
maven { url "https://repo.spring.io/milestone" }
}
dependencies {
compile("org.springframework.boot:spring-boot-starter-actuator:1.2.0.RC2")
compile("org.springframework.boot:spring-boot-starter-aop:1.1.9.RELEASE")
compile("org.springframework.boot:spring-boot-starter-data-jpa:1.1.9.RELEASE")
compile("org.springframework.boot:spring-boot-starter-web:1.1.9.RELEASE")
compile("org.springframework.boot:spring-boot-starter-data-rest:1.1.9.RELEASE")
compile("org.springframework.boot:spring-boot-starter-jdbc:1.1.9.RELEASE")
compile('org.antlr:stringtemplate:4.0.2')
compile('org.apache.commons:commons-lang3:3.0')
compile('commons-io:commons-io:2.4')
compile('com.ingres.jdbc:iijdbc:10.0-4.0.5')
testCompile("org.springframework.boot:spring-boot-starter-test:1.1.9.RELEASE")
}
Edit:
If I put a javax persistence dependency in my build.gradle then I can successfully build and use RepositoryRestConfigurerAdapter, but I get runtime problems with dependencies missing for my entityManagerFactory
If you are already using milestone versions of Spring Boot, I suggest you switch to M5. It includes Gosling-RELEASE Spring Data.

Resources