Usage of BootJar instead of BootRepackage in Gradle as part of Spring Boot Migration from 1..5.x to 2.x - spring-boot

I am working on Spring Boot migration from 1.5.12 to 2.1.14. We are using Gradle as a build tool, so as part of Spring Boot migration we had to change
Gradle from 3.x to 4.x and trying to update the build.gradle as required. In Spring Boot 2.x migration we have to change the following task in build.gradle
task msnServiceBoot(type: BootRepackage, dependsOn:msnJar) {
println " Executing MsnServiceBoot task"
mainClassName = 'com.msn.service.MsnApplication'
customConfiguration = "cloudconfigexclusion"
withJarTask = msnJar
}
In the above code we have to update BootRepackage to BootJar as per the latest Spring documentation.
The error, I'm getting after changing from BootRepackage to BootJar is customConfiguration is unknown property.
May I know how to make customConfiguration for Spring Boot 2.x with gradle 4.x

Related

getting Spring Boot [2.7.0] is not compatible with this Spring Cloud release train error

I am new to spring.
I was trying to upgrade spring boot version from 2.3.3.RELEASE to 2.6.7 in existing spring batch project.
Project build completed successfully but I am getting bellow error when I run batch. Please help.
***************************
APPLICATION FAILED TO START
***************************
Description:
Your project setup is incompatible with our requirements due to following reasons:
- Spring Boot [2.6.7] is not compatible with this Spring Cloud release train
Action:
Consider applying the following actions:
- Change Spring Boot version to one of the following versions [2.3.x, 2.4.x] .
You can find the latest Spring Boot versions here [https://spring.io/projects/spring-boot#learn].
If you want to learn more about the Spring Cloud Release train compatibility, you can visit this page [https://spring.io/projects/spring-cloud#overview] and check the [Release Trains] section.
If you want to disable this check, just set the property [spring.cloud.compatibility-verifier.enabled=false]
My current code of build.gradle is as below,
buildscript {
ext {
springBootVersion = '2.6.7'
}
}
plugins {
id 'org.springframework.boot' version "${springBootVersion}"
}
apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
sourceCompatibility = 11
tasks.named("bootJar") {
archiveFileName = "${archiveBaseName.get()}.${archiveExtension.get()}"
mainClass = 'jp.co.BatchApplication'
}
jar.archiveFileName = bootJar.archiveFileName
repositories {
mavenCentral()
}
dependencies {
implementation("org.springframework.boot:spring-boot-starter-batch:${springBootVersion}")
implementation("org.springframework.boot:spring-boot-starter-web:${springBootVersion}")
implementation("org.springframework.boot:spring-boot-starter-thymeleaf:${springBootVersion}")
implementation("org.springframework.boot:spring-boot-starter-aop:${springBootVersion}")
implementation("org.springframework.retry:spring-retry:1.2.5.RELEASE")
implementation("org.projectlombok:lombok:1.18.24")
annotationProcessor("org.projectlombok:lombok:1.18.24")
implementation('mysql:mysql-connector-java:8.0.17')
implementation('org.seasar.doma.boot:doma-spring-boot-starter:1.4.0')
annotationProcessor('org.seasar.doma:doma-processor:2.35.0')
implementation('org.apache.commons:commons-lang3:3.11')
implementation('org.apache.commons:commons-collections4:4.4')
implementation('com.fasterxml.jackson.dataformat:jackson-dataformat-xml:2.11.2')
implementation("javax.xml.bind:jaxb-api:2.3.1")
implementation(fileTree(dir: 'lib', include: ['*.jar']))
implementation("org.hibernate.validator:hibernate-validator:6.1.5.Final")
implementation('org.apache.httpcomponents:httpclient:4.5.12')
// for r3-id-1.0.1.jar
implementation('commons-digester:commons-digester:2.1')
// Azure App Configuration
implementation('com.microsoft.azure:spring-cloud-azure-appconfiguration-config-web:1.3.0')
implementation('com.microsoft.azure:spring-cloud-azure-feature-management-web:1.3.0')
testImplementation("org.springframework.boot:spring-boot-starter-test:${springBootVersion}")
}
*
*
*
*
I guess it is not relevant to this error but I have also change DefaultBatchConfigurer class from use of MapJobRepositoryFactoryBean to JobRepositoryFactoryBean. As MapJobRepositoryFactoryBean is deprecated.
The error is quite explanatory ...
- Spring Boot [2.6.7] is not compatible with this Spring Cloud release train
Spring Cloud versions are tied to specific Spring Boot versions. When using Spring Cloud you cannot just upgrade Spring Boot you also need to upgrade Spring Cloud to a version that supports that Spring Boot version.
As you are using some Azure Cloud dependencies you need to upgrade those to a newer version (if available) that support a Spring Cloud version that supports Spring Boot 2.6.
Pro Tip I would also suggest to cleanup your dependencies so you benefit, more, from the Spring Boot dependency management
dependencies {
implementation("org.springframework.boot:spring-boot-starter-batch")
implementation("org.springframework.boot:spring-boot-starter-web")
implementation("org.springframework.boot:spring-boot-starter-thymeleaf")
implementation("org.springframework.boot:spring-boot-starter-aop")
implementation("org.springframework.boot:spring-boot-starter-validation")
implementation("org.springframework.retry:spring-retry")
implementation("org.projectlombok:lombok")
annotationProcessor("org.projectlombok:lombok")
implementation('mysql:mysql-connector-java')
implementation('org.seasar.doma.boot:doma-spring-boot-starter:1.4.0')
annotationProcessor('org.seasar.doma:doma-processor:2.35.0')
implementation('org.apache.commons:commons-lang3:3.11')
implementation('org.apache.commons:commons-collections4:4.4')
implementation('com.fasterxml.jackson.dataformat:jackson-dataformat-xml')
implementation("javax.xml.bind:jaxb-api")
// for Mu Client
implementation(fileTree(dir: 'lib', include: ['*.jar']))
implementation('org.apache.httpcomponents:httpclient')
// for r3-id-3.0.1.jar
implementation('commons-digester:commons-digester:2.1')
// Azure App Configuration
implementation('com.microsoft.azure:spring-cloud-azure-appconfiguration-config-web:1.3.0')
implementation('com.microsoft.azure:spring-cloud-azure-feature-management-web:1.3.0')
testImplementation("org.springframework.boot:spring-boot-starter-test")
}

bootRepackage classifier is not working when upgrade to gradle 6.6.1 (also gralde 5)

Our project still worked well in gradle 4.10.2 (Spring boot 1.5.22), but when i have upgraded gradle to 6.6.1 it thrown exception
org.gradle.api.ProjectConfigurationException: A problem occurred configuring project ':my-app'.
Caused by: org.gradle.internal.event.ListenerNotificationException: Failed to notify project evaluation listener
Caused by: java.lang.NoSuchMethodError: org.gradle.api.tasks.TaskInputs.file(Ljava/lang/Object;)Lorg/gradle/api/tasks/TaskInputs;
at org.springframework.boot.gradle.repackage.RepackagePluginFeatures$RegisterInputsOutputsAction.setupInputOutputs(RepackagePluginFeatures.java:150)
at org.springframework.boot.gradle.repackage.RepackagePluginFeatures$RegisterInputsOutputsAction.execute(RepackagePluginFeatures.java:136)
I have tried with gradle 5 it still happend.
This is my gradle.build bootRepackage section, when i removed classifier = "boot" it work without classifier feature
bootRepackage {
enabled = true
classifier = "boot"
doLast{
//some tasks
}
}
Why could this be?
Gradle 5 has removed a method that Spring Boot 1.5’s Gradle plugin requires. Spring Boot 1.5 supports Gradle 2.x or 3.x so it isn’t surprising that it does not work with Gradle 5.
If you want to use a more up-to-date version of Gradle, you’ll have to upgrade to a more up-to-date version of Spring Boot as well. At the time of writing 2.3.x is the oldest generation of Spring Boot that is still supported.

How to use JPA metamodel with gradle, intellij IDEA?

I am using java 8, spring boot 2.0.0, spring-data-jpa(spring-boot-starter-data-jpa), gradle, intellij. I've been trying to use JPA Metamodel, but having difficulty on finding how to configure.
Metamodels for Entity classes aren't just generated.
I guessed it would be simple, but now it seems that can be wrong. How can I use it?
JDK11 / Gradle 5.0 / Hibernate 5.3.7.Final
sourceSets.main.java.srcDirs += "${buildDir}/generated"
compileJava {
options.annotationProcessorGeneratedSourcesDirectory = file("${buildDir}/generated")
}
dependencies {
annotationProcessor("javax.xml.bind:jaxb-api")
annotationProcessor("org.hibernate:hibernate-jpamodelgen")
}
Generated Metamodel classes will be generated at 'build/generated'
If you are using JDK8 or Hibernate 5.4+, annotationProcessor("javax.xml.bind:jaxb-api") may unnecessary.
I did this the other day using the scalified metamodel gradle plugin (https://plugins.gradle.org/plugin/com.scalified.plugins.gradle.metamodel). I'm using Spring Boot 2.0.5, but I don't see why it wouldn't work the same with Spring Boot 2.0.0. I'm using Gradle 4.8.1 as well.
Below is an excerpt of my build.gradle.
buildscript {
repositories {
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath (
"org.springframework.boot:spring-boot-gradle-plugin:2.0.0",
"gradle.plugin.com.scalified.plugins.gradle:metamodel:0.0.1");
}
}
apply plugin: "com.scalified.plugins.gradle.metamodel"
// The plugin will default to the latest version of Hibernate if this is not specified
metamodel {
hibernateVersion = '5.2.14.Final' // For Spring Boot 2.0.0
hibernateVersion = '5.2.17.Final' // For Spring Boot 2.0.5
}
This builds the metamodal files under src/generated and they can be used in your code. I had to also change an IntelliJ setting because IntelliJ's Build Automatically excludes some Gradle tasks that could be long running. See Automatically run Gradle task in project build with IntelliJ IDEA and https://youtrack.jetbrains.com/issue/IDEA-175165 for more details.
This setting I changed to overcome this is: Preferences->Build/Execution/Deployment->Gradle->Runner->Delegate IDE build/run actions to Gradle. An alternative would be to run the metamodelCompile gradle task manually as needed. That would lessen the time to rebuild by a little if you aren't frequently change your entities.

error when upgrading Spring Boot version in Vaadin Gradle project

I have a Gradle project that uses Spring Boot + Vaadin.
The Gradle plugins for Spring Boot and Vaadin configured as follows:
buildscript {
ext {
springBootVersion = '1.3.7.RELEASE'
}
...
dependencies {
classpath "org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}"
classpath "fi.jasoft.plugin:gradle-vaadin-plugin:0.11.1"
}
}
The Vaadin version is specified as follows:
vaadin {
version '7.6.8'
widgetset 'com.vaadin.DefaultWidgetSet'
}
Vaadin dependencies are specified as follows:
dependencies {
compile 'com.vaadin:vaadin-spring-boot-starter:1.0.0'
compile 'com.vaadin:vaadin-server:${vaadin.version}'
compile 'com.vaadin:vaadin-client:${vaadin.version}'
...
}
This works fine, but as soon as I change the Spring Boot version to
springBootVersion = '1.4.0.RELEASE'
then I get the error:
Illegal character in path at index 89:
https://oss.sonatype.org/content/repositories/vaadin-snapshots/com/vaadin/vaadin-server/${vaadin.version}/vaadin-server-${vaadin.version}.pom
Update
Groovy (which Gradle uses) supports String interpolation only when using double quotes (") so changing the Vaadin dependencies to
dependencies {
compile "com.vaadin:vaadin-spring-boot-starter:1.0.0"
compile "com.vaadin:vaadin-server:${vaadin.version}"
compile "com.vaadin:vaadin-client:${vaadin.version}"
...
}
fixes it. Now the real question is why the single quotes work fine if I downgrade Spring Boot to 1.3.7-RELEASE.
If you are using a recent Spring Boot version you should upgrade your Gradle Vaadin plugin. Recent versions of the plugin has much better support for Spring Boot.
Here is a guide to get you started https://github.com/johndevs/gradle-vaadin-plugin/wiki/Creating-a-Spring-Boot-Project

How do I run FlyWay clean with Spring Boot?

I'm using Spring Boot and FlyWay together. I added the FlyWay dependency to my Gradle build file like this:
dependencies {
compile("org.springframework.boot:spring-boot-starter-data-jpa")
compile("org.springframework.boot:spring-boot-starter-web")
compile("org.postgresql:postgresql:9.4-1202-jdbc42")
compile("org.flywaydb:flyway-core")
testCompile("org.springframework.boot:spring-boot-starter-test")
}
I also added a db/migrations folder with an initial migration file. The migration works as expected. But now I want to clean by using the gradle flywayClean task. However, when I run this, I get an error saying the task can't be found. Is there another way I'm supposed to do this with Spring Boot?
To run gradle flywayClean, you have to apply the plugin: 'org.flywaydb.flyway'
See http://flywaydb.org/getstarted/firststeps/gradle.html

Resources