I am trying to manage my spring dependencies using gradle and the spring dependency management plugin. Currently this brings down version 5.0.3.RELEASE of spring-data-neo4j which according to the pom here, should bring down version 3.0.3 of the neo4j-ogm, but instead it brings down version 2.1.5. This means that even though I've followed the docs to the letter about configuration that the ConfigurationBuilder symbol is not found. Any help would be greatly appreciated. I am currently using gradle 4.4.1
buildscript {
repositories {
mavenCentral()
maven { url 'https://repo.spring.io/plugins-snapshot' }
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:1.5.8.RELEASE")
classpath 'io.spring.gradle:dependency-management-plugin:1.0.5.BUILD-SNAPSHOT'
}
}
plugins {
id "io.spring.dependency-management" version "1.0.4.RELEASE"
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'org.springframework.boot'
apply plugin: "io.spring.dependency-management"
ext {
springVersion = '5.0.3.RELEASE'
springDataVersion = 'Kay-SR3'
}
dependencyManagement {
imports {
mavenBom "org.springframework:spring-framework-bom:${springVersion}"
mavenBom "org.springframework.data:spring-data-releasetrain:${springDataVersion}"
}
}
repositories {
mavenCentral()
maven {
url 'https://repo.spring.io/libs-release'
}
}
dependencies {
compile group: "org.springframework.boot", name: "spring-boot-starter-web"
compile group: "org.springframework.boot", name: "spring-boot-starter-security"
compile group: "org.springframework", name: "spring-aspects"
compile group: "org.springframework.data", name: "spring-data-neo4j"
compile group: 'com.fasterxml.jackson.datatype', name: 'jackson-datatype-jsr310'
testCompile group: "org.springframework.boot", name: "spring-boot-starter-test"
testCompile group: "org.neo4j", name: "neo4j-ogm-embedded-driver", version: "3.1.0"
}
You are using the spring-boot-gradle-plugin with version 1.5.8.RELEASE. This will pull in the version 4 of SDN and its dependency OGM 2.1.x when you declare the dependency here compile group: "org.springframework.data", name: "spring-data-neo4j".
The only solution at this point is to use Spring Boot 2 RC1. If you would include SDN with its dependencies to Spring Data commons and Spring Framework 5 you will mess up your class path because Spring Boot 1 is based on Spring Framework 4.
Background: Tried it once to integrate SDN 5.x in Spring Boot 1 but it did not work out, you will lose all benefits of Spring Boot since you have to deactivate pretty everything.
Related
I have the following gradle settings:
plugins {
id 'org.springframework.boot' version '3.0.0'
id 'io.spring.dependency-management' version '1.1.0'
id 'java'
}
repositories {
mavenCentral()
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-actuator'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-aop'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
implementation 'org.springframework.boot:spring-boot-starter-amqp'
testImplementation 'org.springframework.amqp:spring-rabbit-test'
}
How can I lock or specify exactly the versions of all the dependencies libs, how do I check the compatibility with the other libs and chose the most new and updated ones?
as I understand - spring boot doesn't need spring framework specified?
checked other Stackoverflow posts.
checked compatibility matrix.
dependencyManagement {
imports {
mavenBom "org.springframework.boot:spring-boot-dependencies:3.0.0"
}
}
solved the issue.
I have a Gradle project and I want to create a submodule but I am getting an FAILURE when building the project.
The error message is
Execution failed for task ':child-project:compileJava'
> Could not resolve all files for configuration 'child-project:compileClasspath'.
> Could not find org.springframework.boot:spring-boot-starter:.
Required by:
project :parent-project
This is the parent project build.gradle file:
plugins {
id 'org.springframework.boot' version '2.3.0.RELEASE'
id 'io.spring.dependency-management' version '1.0.9.RELEASE'
id 'java'
}
allprojects {
apply plugin: 'java'
group = 'com.test'
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
repositories {
//local nexus
}
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter'
implementation 'org.springframework.boot:spring-boot-starter-actuator'
implementation 'org.springframework.boot:spring-boot-starter-web'
//other dependencies
}
This is the child project build.gradle:
plugins {
id 'java'
}
group = 'com.test'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = JavaVersion.VERSION_11
dependencies {
compile 'org.springframework.boot:spring-boot-starter'
testImplementation('org.springframework.boot:spring-boot-starter-test') {
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
}
}
Please help, thanks in advance.
In order to be able to specify Spring Boot dependencies without versions, you need to apply the Spring Boot plugin to all modules. Right now you only have it in the parent project, but not the child.
Because applying the plugin will also, by default, disable the normal jar task can create a bootJar instead, you need to change this for libraries:
// Child build file
plugins {
// Note that there are no versions on the plugins in the child project as this is defined by the ones in the parent
id 'org.springframework.boot'
id 'io.spring.dependency-management'
}
bootJar {
enabled = false
}
jar {
enabled = true
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter'
}
Alternatively, you could also scrap the io.spring.dependency-management plugin (and the org.springframework.boot plugin in the child project), and instead import the Spring Boot BOM as a platform:
// Child build file (alternative)
dependencies {
// Use 'platform' for making the versions in the BOM a recommendation only, and 'enforcedPlatform' for making them a requirement.
// Note that you need the version of the BOM, so I recommend putting it in a property.
implementation enforcedPlatform("org.springframework.boot:spring-boot-dependencies:2.3.0.RELEASE")
// Here you can leave out the version
implementation 'org.springframework.boot:spring-boot-starter'
}
I usually go for the latter alternative as this allows me to use normal Gradle semantics. But it is mostly just preference.
(And just a small note to your build script: the compile configuration is deprecated. It is used in the line compile 'org.springframework.boot:spring-boot-starter'. You probably just copy/pasted it from somewhere, but you should replace it with implementation.)
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.
My module's gradle configuration is following,
group 'com.ifox.platform'
version '1.0-SNAPSHOT'
apply plugin: 'java'
apply plugin: 'idea'
sourceCompatibility = 1.8
repositories {
mavenLocal()
jcenter()
}
dependencies {
compile project(":ifox-base-service")
testCompile group: 'junit', name: 'junit', version: '4.12'
}
buildscript {
repositories {
mavenLocal()
jcenter()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:1.5.4.RELEASE")
}
}
apply plugin: 'spring-boot'
If I gradle build with above configuration, I will get a jar file. Then I excute it:
javar -jar xxxx.jar
It's successful and I can visit my website:
http://localhost:8080/swagger-ui.html
But when I test method named listAll(), there is a exception:
java.lang.NoSuchMethodError: org.hibernate.Session.createQuery(Ljava/lang/String;)Lorg/hibernate/query/Query;
At this time, maybe you think it's my low-level code fault. I modified my gradle configuration, like this:
group 'com.ifox.platform'
version '1.0-SNAPSHOT'
apply plugin: 'java'
apply plugin: 'idea'
sourceCompatibility = 1.8
repositories {
mavenLocal()
jcenter()
}
dependencies {
compile project(":ifox-base-service")
testCompile group: 'junit', name: 'junit', version: '4.12'
}
Yes, I removed the spring boot plugin configuration. Then I test my method(listAll) again, it's successful to get all data from database.
How to fix it?
It's my low-level code fault, or spring-boot plugin configuration fault?
As far as I know gradle requires a version number when setting dependencies, but partial wildcards are allowed. For example if I want Guava, I cannot do this as it fails:
compile('com.google.guava:guava')
It has to be (as an example):
compile('com.google.guava:guava:21.0')
However, I'm learning Spring, which has the following:
compile("org.springframework.boot:spring-boot-starter")
compile("org.springframework:spring-web")
compile("com.fasterxml.jackson.core:jackson-databind")
How are these dependencies working with no version supplied?
Is it because of the following, but I thought these lines were required only for my plugin 'org.springframework.boot':
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:1.4.3.RELEASE")
}
}
It is worth mentioning that the trick is called BOM (bill of materials) and the actual versions can be checked in the related POM file (in this example, it is for the version 2.7.0) inside spring-boot-dependencies package. This is mentioned in the Spring Boot official documentation here: Build Systems.
Another way that Spring provides this (for non Boot projects) is through Spring Platform BOM where it actually provides version for the following dependencies.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'io.spring.gradle:dependency-management-plugin:0.6.0.RELEASE'
}
}
apply plugin: 'io.spring.dependency-management'
dependencyManagement {
imports {
mavenBom 'io.spring.platform:platform-bom:Athens-SR2'
}
}
TL;DR - spring boot uses custom dependencies resolver.
A spring boot plugin that is applied with the following piece of code:
apply plugin: 'spring-boot'
handles the dependencies that are listed without version. This logic is implemented in this class which delegates it to here. DependencyManagementPluginFeatures are applied here.
The spring boot gradle plugin documentation states the following:
The version of the spring-boot gradle plugin that you declare
determines the version of the spring-boot-starter-parent bom that is
imported (this ensures that builds are always repeatable). You should
always set the version of the spring-boot gradle plugin to the actual
Spring Boot version that you wish to use.
Spring Boot Dependency Management Plugin is not necessary.
You may use build-in Gradle BOM support instead of Spring Boot Dependency Management Plugin
For example:
plugins {
id 'java'
id 'org.springframework.boot' version '2.1.0.RELEASE'
}
repositories {
jcenter()
}
dependencies {
implementation platform('org.springframework.boot:spring-boot-dependencies:2.1.0.RELEASE')
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-security'
}
and for multi-module project:
in root build.gradle :
plugins {
id 'java-library'
id 'org.springframework.boot' version '2.1.0.RELEASE'
}
allprojects {
apply plugin: 'java-library'
repositories {
jcenter()
}
}
dependencies {
implementation project(':core')
implementation 'org.springframework.boot:spring-boot-starter-web'
}
and in core/build.gradle
dependencies {
api platform('org.springframework.boot:spring-boot-dependencies:2.1.0.RELEASE')
implementation 'org.springframework.boot:spring-boot-starter-web'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
}