error when upgrading Spring Boot version in Vaadin Gradle project - gradle

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

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")
}

Spring-boot BOM does not contain a dependency for tomcat-dbcp

Spring-boot BOM does not contain a dependency for tomcat-dbcp.
I have a Spring MVC project where I use a database connection pool for Hibernate ORM connections. This project is deployed in Tomcat. In my IntelliJ Idea development environment I use Tomcat embedded, by using the spring-boot-starter-tomcat. But the spring-boot-starter-tomcat does not define a dependency to tomcat-dbcp. Hence I decided to explicitly define a dependency to tomcat-dbcp in my build.gradle.kts file.
I had hoped that the Spring-boot BOM would have contained tomcat-dbcp, so that I would not need to specify it's version number and rely on the Spring Boot dependency management system to handle it's version number for me. But the Spring-boot BOM does not contain a dependency for tomcat-dbcp. Can Spring-Boot add it?
I came up with the following hack so as to not hard code the version number for tomcat-dbcp. Just added the following code to the build.gradle.kts file after dependencies section.
configurations.all {
resolutionStrategy.eachDependency {
if (requested.group == "org.apache.tomcat.embed" && requested.name == "tomcat-embed-core") {
dependencies {
providedRuntime("org.apache.tomcat", "tomcat-dbcp", requested.version) //to use tomcat connection pool in tomcat embedded mode.
}
}
}
}

How to use spring boot in gradle without the spring boot gradle plugin

Can anyone show me or point me to a spring boot gradle project that does not make use of the spring boot gradle plugin.
I'm looking for something like a spring boot starter web hello world example that doesn't use the gradle plugin.
I can't imagine that the plugin is a requirement, but a search for examples all seem to lean on the gradle plugin, which lets just say is not an option in my environment, and no I can't switch to maven either.
Ideally the gradle build would work by adding something like the following:
gradle.properties
springBootVersion=2.1.3.RELEASE
build.gradle
dependencies {
compile group: 'org.springframework.boot', name: 'spring-boot-starter-web', version: springBootVersion
}
I used the spring dependency management plugin, and it works
buildscript {
ext {
springDepManagementVersion = '1.0.10.RELEASE'
springBootVersion = '2.6.6'
springCloudVersion = "2021.0.1"
}
dependencies {
classpath "io.spring.gradle:dependency-management-plugin:${springDepManagementVersion}"
}
}
apply plugin: 'io.spring.dependency-management'
dependencyManagement {
imports {
mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
mavenBom "org.springframework.boot:spring-boot-dependencies:${springBootVersion}"
}
}
dependencies {
implementation "org.springframework.cloud:spring-cloud-starter-sleuth"
implementation 'org.springframework.boot:spring-boot-starter-json'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-mail'
implementation 'org.springframework.boot:spring-boot-starter-security'
...
}
I can't use spring boot gradle plugin, since I can only use gradle 6.7.1, while spring boot gradle plugin requires gradle version at least 6.8 to support spring boot 2.6. I was inspired by the spring cloud bom solution.

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.

Get Derived ("Blessed") Version of Dependency from Spring Boot Gradle Plugin

I have a Spring Boot project which uses "blessed" dependencies via the Gradle plugin. The dependencies block in my build.gradle file looks like this:
dependencies {
compile "org.springframework.boot:spring-boot-starter-web"
compile "org.springframework.boot:spring-boot-starter-data-jpa"
compile "com.fasterxml.jackson.core:jackson-core"
compile "com.fasterxml.jackson.dataformat:jackson-dataformat-csv"
}
(I've removed several other dependencies for brevity.)
The above code is broken because Spring Boot does not have a "blessed" version for the dataformat-csv extension.
All I want to do is get it to use the Spring Boot-derived version for jackson-core and use it for the jackson-dataformat-csv as well for consistency. How do I get the version number for that dependency if it's been derived by a plugin?

Resources