无法让 liquibase-hibernate 插件与 gradle 一起工作
Unable to get liquibase-hibernate plugin work with gradle
在尝试将 liquibase:hibernate 插件与 spring-boot:gradle:postgres 集成时,当我 运行 gradle diff
命令。
Unexpected error running Liquibase: org/springframework/orm/jpa/persistenceunit/DefaultPersistenceUnitManager
SEVERE 3/11/18 5:27 PM: liquibase: org/springframework/orm/jpa/persistenceunit/DefaultPersistenceUnitManager
java.lang.NoClassDefFoundError: org/springframework/orm/jpa/persistenceunit/DefaultPersistenceUnitManager
at liquibase.ext.hibernate.database.HibernateSpringPackageDatabase.createEntityManagerFactory(HibernateSpringPackageDatabase.java:69)
at liquibase.ext.hibernate.database.HibernateEjb3Database.buildMetadataFromPath(HibernateEjb3Database.java:51)
at liquibase.ext.hibernate.database.HibernateDatabase.buildMetadata(HibernateDatabase.java:136)
at liquibase.ext.hibernate.database.HibernateDatabase.setConnection(HibernateDatabase.java:75)
at liquibase.database.DatabaseFactory.findCorrectDatabaseImplementation(DatabaseFactory.java:131)
at liquibase.database.DatabaseFactory.openDatabase(DatabaseFactory.java:151)
at liquibase.integration.commandline.CommandLineUtils.createDatabaseObject(CommandLineUtils.java:85)
at liquibase.integration.commandline.Main.createReferenceDatabaseFromCommandParams(Main.java:1283)
at liquibase.integration.commandline.Main.doMigration(Main.java:996)
at liquibase.integration.commandline.Main.run(Main.java:188)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:93)
at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:325)
at org.codehaus.groovy.runtime.callsite.StaticMetaMethodSite.invoke(StaticMetaMethodSite.java:46)
at org.codehaus.groovy.runtime.callsite.StaticMetaMethodSite.call(StaticMetaMethodSite.java:91)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:125)
at org.liquibase.gradle.LiquibaseTask.runLiquibase(LiquibaseTask.groovy:113)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
这是我的 build.gradle :
buildscript {
ext {
springBootVersion = '2.0.0.RELEASE'
runList = 'main'
diffLog = '$projectDir/src/main/resources/db/changelog/db.changelog-master.xml'
}
repositories {
mavenCentral()
maven { url 'https://plugins.gradle.org/m2/' }
maven { url 'https://repo.spring.io/libs-snapshot' }
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
classpath 'org.liquibase:liquibase-gradle-plugin:1.2.4'
classpath 'org.liquibase:liquibase-core'
classpath 'org.postgresql:postgresql:42.2.1'
classpath 'org.liquibase.ext:liquibase-hibernate5:3.6'
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
apply plugin: 'org.liquibase.gradle'
group = 'com.project.sample'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = 1.8
diffLog = '$projectDir/src/main/resources/db/changelog/db.changelog-{$version}.xml'
repositories {
mavenCentral()
}
dependencies {
compile('org.springframework.boot:spring-boot-starter-data-jpa')
compile('org.springframework.boot:spring-boot-starter-security')
compile('org.springframework.boot:spring-boot-starter-web')
compile('org.liquibase:liquibase-core')
compile('org.springframework.session:spring-session-core')
runtime('org.postgresql:postgresql')
testCompile('org.springframework.boot:spring-boot-starter-test')
testCompile('org.springframework.security:spring-security-test')
}
liquibase {
activities {
//noinspection GroovyAssignabilityCheck
main {
changeLogFile project.ext.diffLog
url 'jdbc:postgresql://localhost:5432/quora'
username 'ueducation'
password 'u3duc@tion'
referenceUrl 'hibernate:spring:com.project.sample.src.main.web.entities?dialect=org.hibernate.dialect.PostgreSQL9Dialect'
referenceDriver 'liquibase.ext.hibernate.database.connection.HibernateDriver'
logLevel 'debug'
}
runList = project.ext.runList
}
}
版本:
- Spring-数据-jpa : 2.0.5
- 休眠:5.2.14
- Liquibase-hibernate5 插件:3.6
我试过很多关于 SO 和周围的帖子,但无法弄清楚。
感谢任何帮助。
所以,java.lang.NoClassDefFoundError 意味着 class 没有被 classloader 加载。
因此,只需要将 sprind-data-jpa 添加到 class 路径。
build.gradle
中更新后的 buildscript
看起来像
buildscript {
ext {
springBootVersion = '2.0.0.RELEASE'
runList = 'main'
diffLog = '$projectDir/src/main/resources/db/changelog/db.changelog-master.xml'
}
repositories {
mavenCentral()
maven { url 'https://plugins.gradle.org/m2/' }
maven { url 'https://repo.spring.io/libs-snapshot' }
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
classpath 'org.liquibase:liquibase-gradle-plugin:1.2.4'
classpath 'org.liquibase:liquibase-core'
classpath 'org.postgresql:postgresql:42.2.1'
classpath 'org.liquibase.ext:liquibase-hibernate5:3.6'
classpath 'org.springframework.data:spring-data-jpa:2.0.5.RELEASE'
}
}
在尝试将 liquibase:hibernate 插件与 spring-boot:gradle:postgres 集成时,当我 运行 gradle diff
命令。
Unexpected error running Liquibase: org/springframework/orm/jpa/persistenceunit/DefaultPersistenceUnitManager
SEVERE 3/11/18 5:27 PM: liquibase: org/springframework/orm/jpa/persistenceunit/DefaultPersistenceUnitManager
java.lang.NoClassDefFoundError: org/springframework/orm/jpa/persistenceunit/DefaultPersistenceUnitManager
at liquibase.ext.hibernate.database.HibernateSpringPackageDatabase.createEntityManagerFactory(HibernateSpringPackageDatabase.java:69)
at liquibase.ext.hibernate.database.HibernateEjb3Database.buildMetadataFromPath(HibernateEjb3Database.java:51)
at liquibase.ext.hibernate.database.HibernateDatabase.buildMetadata(HibernateDatabase.java:136)
at liquibase.ext.hibernate.database.HibernateDatabase.setConnection(HibernateDatabase.java:75)
at liquibase.database.DatabaseFactory.findCorrectDatabaseImplementation(DatabaseFactory.java:131)
at liquibase.database.DatabaseFactory.openDatabase(DatabaseFactory.java:151)
at liquibase.integration.commandline.CommandLineUtils.createDatabaseObject(CommandLineUtils.java:85)
at liquibase.integration.commandline.Main.createReferenceDatabaseFromCommandParams(Main.java:1283)
at liquibase.integration.commandline.Main.doMigration(Main.java:996)
at liquibase.integration.commandline.Main.run(Main.java:188)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:93)
at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:325)
at org.codehaus.groovy.runtime.callsite.StaticMetaMethodSite.invoke(StaticMetaMethodSite.java:46)
at org.codehaus.groovy.runtime.callsite.StaticMetaMethodSite.call(StaticMetaMethodSite.java:91)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:125)
at org.liquibase.gradle.LiquibaseTask.runLiquibase(LiquibaseTask.groovy:113)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
这是我的 build.gradle :
buildscript {
ext {
springBootVersion = '2.0.0.RELEASE'
runList = 'main'
diffLog = '$projectDir/src/main/resources/db/changelog/db.changelog-master.xml'
}
repositories {
mavenCentral()
maven { url 'https://plugins.gradle.org/m2/' }
maven { url 'https://repo.spring.io/libs-snapshot' }
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
classpath 'org.liquibase:liquibase-gradle-plugin:1.2.4'
classpath 'org.liquibase:liquibase-core'
classpath 'org.postgresql:postgresql:42.2.1'
classpath 'org.liquibase.ext:liquibase-hibernate5:3.6'
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
apply plugin: 'org.liquibase.gradle'
group = 'com.project.sample'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = 1.8
diffLog = '$projectDir/src/main/resources/db/changelog/db.changelog-{$version}.xml'
repositories {
mavenCentral()
}
dependencies {
compile('org.springframework.boot:spring-boot-starter-data-jpa')
compile('org.springframework.boot:spring-boot-starter-security')
compile('org.springframework.boot:spring-boot-starter-web')
compile('org.liquibase:liquibase-core')
compile('org.springframework.session:spring-session-core')
runtime('org.postgresql:postgresql')
testCompile('org.springframework.boot:spring-boot-starter-test')
testCompile('org.springframework.security:spring-security-test')
}
liquibase {
activities {
//noinspection GroovyAssignabilityCheck
main {
changeLogFile project.ext.diffLog
url 'jdbc:postgresql://localhost:5432/quora'
username 'ueducation'
password 'u3duc@tion'
referenceUrl 'hibernate:spring:com.project.sample.src.main.web.entities?dialect=org.hibernate.dialect.PostgreSQL9Dialect'
referenceDriver 'liquibase.ext.hibernate.database.connection.HibernateDriver'
logLevel 'debug'
}
runList = project.ext.runList
}
}
版本:
- Spring-数据-jpa : 2.0.5
- 休眠:5.2.14
- Liquibase-hibernate5 插件:3.6
我试过很多关于 SO 和周围的帖子,但无法弄清楚。 感谢任何帮助。
所以,java.lang.NoClassDefFoundError 意味着 class 没有被 classloader 加载。
因此,只需要将 sprind-data-jpa 添加到 class 路径。
build.gradle
中更新后的 buildscript
看起来像
buildscript {
ext {
springBootVersion = '2.0.0.RELEASE'
runList = 'main'
diffLog = '$projectDir/src/main/resources/db/changelog/db.changelog-master.xml'
}
repositories {
mavenCentral()
maven { url 'https://plugins.gradle.org/m2/' }
maven { url 'https://repo.spring.io/libs-snapshot' }
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
classpath 'org.liquibase:liquibase-gradle-plugin:1.2.4'
classpath 'org.liquibase:liquibase-core'
classpath 'org.postgresql:postgresql:42.2.1'
classpath 'org.liquibase.ext:liquibase-hibernate5:3.6'
classpath 'org.springframework.data:spring-data-jpa:2.0.5.RELEASE'
}
}