Spring Data Neo4j OGM Gradle依赖版本不符问题求助
Hey there, let’s get this dependency mismatch sorted out—this is a common hiccup with transitive dependencies in Gradle, but we can fix it quickly.
First, let’s confirm the basics: Spring Data Neo4j (SDN) 5.0.3.RELEASE does require Neo4j OGM 3.0.3 as per its POM, so the 2.1.5 version being pulled in is definitely a conflict from another dependency in your project. Here’s how to resolve it:
Step 1: Identify the source of the old Neo4j OGM version
Run this Gradle command to generate your dependency tree and track down where 2.1.5 is coming from:
./gradlew dependencies --configuration implementationClasspath | grep neo4j-ogm
Look for lines that show neo4j-ogm-core:2.1.5 and check the parent dependency listed next to it—this will tell you which library is pulling in the old version.
Step 2: Force the correct Neo4j OGM version
You have two reliable ways to fix this with Gradle’s dependency management:
Option A: Use Spring’s Dependency Management Plugin to lock versions
If you’re using the io.spring.dependency-management plugin, add these lines to your build.gradle to explicitly pin the Neo4j OGM versions:
dependencyManagement { imports { mavenBom "org.springframework.data:spring-data-neo4j:5.0.3.RELEASE" } dependencies { // Lock all required Neo4j OGM modules to 3.0.3 dependency "org.neo4j:neo4j-ogm-core:3.0.3" dependency "org.neo4j:neo4j-ogm-bolt-driver:3.0.3" dependency "org.neo4j:neo4j-ogm-http-driver:3.0.3" // Include if you use HTTP driver } }
Option B: Exclude old dependencies and declare the correct ones directly
If you prefer to be explicit, exclude the conflicting transitive dependencies from SDN and declare the correct OGM versions yourself:
implementation('org.springframework.data:spring-data-neo4j:5.0.3.RELEASE') { // Exclude the old Neo4j OGM modules pulled in transitively exclude group: 'org.neo4j', module: 'neo4j-ogm-core' exclude group: 'org.neo4j', module: 'neo4j-ogm-bolt-driver' } // Declare the correct OGM versions explicitly implementation 'org.neo4j:neo4j-ogm-core:3.0.3' implementation 'org.neo4j:neo4j-ogm-bolt-driver:3.0.3'
Step 3: Verify the fix
Run the dependency tree command again (from Step 1) to confirm that all Neo4j OGM modules are now at version 3.0.3. Once that’s done, the ConfigurationBuilder class should be available as expected.
A quick note: ConfigurationBuilder was introduced in Neo4j OGM 3.x—this is why it’s missing in 2.1.5. The key here is ensuring no other dependency in your project is forcing the older OGM version, which the dependency tree check will help you spot.
内容的提问来源于stack exchange,提问作者Jacob Mountain

