Reputation: 13517
Upgraded my Hibernate dependencies from 5.6.11.Final
to 6.1.7.Final
, migrated to the jakarta packages and my project will no longer gradle build because it cannot locate org.hibernate.common:hibernate-commons-annotations
.
If I exclude the annotations module from both hibernate dependencies, then I can gradle build, but not debug/compile because it's missing classes found in the annotations module. Adding the module manually at this point brings back the same error.
I'm not sure how to approach this, as the only other related question (also on this site) has no answer and is from a much older version.
Gradle Build Error
:api:dev: Could not resolve org.hibernate.common:hibernate-commons-annotations:6.0.6.Final.
Required by:
project :api > org.hibernate:hibernate-hikaricp:6.1.7.Final > org.hibernate.orm:hibernate-hikaricp:6.1.7.Final > org.hibernate.orm:hibernate-core:6.1.7.Final
Possible solution:
- Declare repository providing the artifact, see the documentation at https://docs.gradle.org/current/userguide/declaring_repositories.html
Here is my build.gradle
file:
plugins {
id 'java'
id 'com.github.johnrengelman.shadow' version '7.0.0' apply true
id 'org.flywaydb.flyway' version '8.0.0-beta2'
id 'maven-publish'
}
project.sourceCompatibility = "1.8"
project.targetCompatibility = "1.8"
repositories {
mavenCentral()
maven {
name = 'spongepowered-repo'
url = 'https://repo.spongepowered.org/maven'
}
maven {
name = 'jitpack-repo'
url = 'https://jitpack.io'
}
}
static def loadEnv() {
def env = [:]
try {
def file = new File('.env')
def scanner = new Scanner(file)
while (scanner.hasNextLine()) {
def line = scanner.nextLine()
if (line.contains('=')) {
def pair = line.split('=')
env.put(pair[0], pair.length == 2 ? pair[1] : '')
}
}
} catch (FileNotFoundException ignored) { }
env.putAll(System.getenv())
return env
}
def env = loadEnv()
shadowJar {
def remoteGson = 'com.google.code.gson'
def remoteCommon = 'com.google.common'
def remoteOpenfeign = 'openfeign'
def remoteMariaJdbc = 'org.mariadb.jdbc'
def remoteHibernate = 'org.hibernate'
def remoteYaml = 'org.yaml.snakeyaml'
def remoteApacheText = 'org.apache.commons.text'
def localGson = 'dev.sbs.api.util.google.gson'
def localCommon = 'dev.sbs.api.util.google.common'
def localOpenfeign = 'dev.sbs.api.util.openfeign'
def localMariaJdbc = 'dev.sbs.api.data.sql.mariadb'
def localHibernate = 'dev.sbs.api.data.sql.hibernate'
def localYaml = 'dev.sbs.api.data.yaml.snake'
def localApacheText = 'dev.sbs.api.util.text'
relocate remoteGson, localGson
relocate remoteCommon, localCommon
relocate remoteOpenfeign, localOpenfeign
relocate remoteMariaJdbc, localMariaJdbc
relocate remoteHibernate, localHibernate
relocate remoteYaml, localYaml
relocate remoteApacheText, localApacheText
}
sourceSets {
dev {
java {
srcDirs = ['src/main/java']
}
resources {
srcDirs = ['src/main/resources']
}
}
devTest {
java {
srcDirs = ['src/test/java']
compileClasspath += sourceSets.dev.output
runtimeClasspath += sourceSets.dev.output
}
resources {
srcDirs = ['src/test/resources']
}
}
}
dependencies {
// Deserialization
implementation group: 'com.google.code.gson', name: 'gson', version: '2.10.1'
implementation group: 'com.google.guava', name: 'guava', version: '31.1-jre'
implementation group: 'org.yaml', name: 'snakeyaml', version: '2.0'
// Database
implementation group: 'org.mariadb.jdbc', name: 'mariadb-java-client', version: '3.1.2'
implementation group: 'org.ehcache', name: 'ehcache', version: '3.10.6'
implementation group: 'org.hibernate', name: 'hibernate-hikaricp', version: '6.1.7.Final'
implementation group: 'org.hibernate', name: 'hibernate-jcache', version: '6.1.7.Final'
// Api Clients
implementation group: 'io.github.openfeign', name: 'feign-okhttp', version: '12.2'
implementation group: 'io.github.openfeign', name: 'feign-gson', version: '12.2'
implementation group: 'redis.clients', name: 'jedis', version: '4.3.1'
// Other
implementation group: 'org.apache.commons', name: 'commons-text', version: '1.10.0'
implementation group: 'ch.qos.logback', name: 'logback-classic', version: '1.4.6'
// Annotations
compileOnly group: 'org.projectlombok', name: 'lombok', version: '1.18.26'
annotationProcessor group: 'org.projectlombok', name: 'lombok', version: '1.18.26'
// Tests
testImplementation group: 'org.hamcrest', name: 'hamcrest', version: '2.2'
testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: '5.9.2'
testRuntimeOnly group: 'org.junit.jupiter', name: 'junit-jupiter-engine', version: '5.9.2'
}
configurations {
devImplementation.extendsFrom implementation
devCompileOnly.extendsFrom compileOnly
devAnnotationProcessor.extendsFrom annotationProcessor
devTestImplementation.extendsFrom implementation
devTestCompileOnly.extendsFrom compileOnly
devTestAnnotationProcessor.extendsFrom annotationProcessor
devTestImplementation.extendsFrom testImplementation
devTestRuntimeOnly.extendsFrom testRuntimeOnly
}
// Exclude specific packages while they are being refactored
task devJar(type: Jar, group: 'build') {
archiveAppendix.value('dev')
archiveBaseName.value(artifactIdProp)
archiveVersion.value(versionProp)
from sourceSets.dev.java
from sourceSets.dev.output
}
tasks.withType(JavaCompile) {
options.encoding = 'UTF-8'
}
publishing {
repositories {
maven {
name = 'GitHubPackages'
url = uri('https://maven.pkg.github.com/skyblock-simplified/sbs-api')
credentials {
username = env.get('GITHUB_USER')
password = env.get('GITHUB_TOKEN')
}
}
}
publications {
devPub(MavenPublication) {
groupId = groupIdProp
artifactId = artifactIdProp + '-dev'
version = versionProp
artifacts = [devJar]
pom.withXml {
def dependencies = asNode().appendNode('dependencies')
configurations.implementation.allDependencies.each {
def dependency = dependencies.appendNode('dependency')
dependency.appendNode('groupId', it.group)
dependency.appendNode('artifactId', it.name)
dependency.appendNode('version', it.version)
}
configurations.compileOnly.allDependencies.each {
def dependency = dependencies.appendNode('dependency')
dependency.appendNode('groupId', it.group)
dependency.appendNode('artifactId', it.name)
dependency.appendNode('version', it.version)
}
configurations.annotationProcessor.allDependencies.each {
def dependency = dependencies.appendNode('dependency')
dependency.appendNode('groupId', it.group)
dependency.appendNode('artifactId', it.name)
dependency.appendNode('version', it.version)
}
}
}
releasePub(MavenPublication) {
groupId = groupIdProp
artifactId = artifactIdProp
version = versionProp
artifacts = [shadowJar]
pom.withXml {
def dependencies = asNode().appendNode('dependencies')
configurations.implementation.allDependencies.each {
def dependency = dependencies.appendNode('dependency')
dependency.appendNode('groupId', it.group)
dependency.appendNode('artifactId', it.name)
dependency.appendNode('version', it.version)
}
configurations.compileOnly.allDependencies.each {
def dependency = dependencies.appendNode('dependency')
dependency.appendNode('groupId', it.group)
dependency.appendNode('artifactId', it.name)
dependency.appendNode('version', it.version)
}
configurations.annotationProcessor.allDependencies.each {
def dependency = dependencies.appendNode('dependency')
dependency.appendNode('groupId', it.group)
dependency.appendNode('artifactId', it.name)
dependency.appendNode('version', it.version)
}
}
}
}
}
flyway {
url = 'jdbc:mariadb://' + env.get('DATABASE_HOST') + ':' + env.get('DATABASE_PORT') + '/' + env.get('DATABASE_SCHEMA')
user = env.get('DATABASE_USER')
password = env.get('DATABASE_PASSWORD')
}
test {
useJUnitPlatform()
}
tasks.register('devTest', Test) {
useJUnitPlatform()
group = 'verification'
testClassesDirs = sourceSets.devTest.output.classesDirs
classpath = sourceSets.devTest.runtimeClasspath
}
Upvotes: 0
Views: 890
Reputation: 13517
The problem is with my target compatibility of 1.8, Hibernate 6.x only supports Java 11, 17 and 18 (as of this post).
https://hibernate.org/orm/releases/
Upvotes: 0