所以,我目前正在使用 Java Spring Boot v3.2.0 和 Gradle v8.5 构建一个项目。
我想使用 Liquibase 进行迁移,但每当我尝试运行任何 Liquibase 任务时,它都会显示
Liquibase-core was not found not found in the liquibaseRuntime configuration!
这是我的build.gradle:
plugins {
id 'java'
id 'org.springframework.boot' version '3.2.0'
id 'io.spring.dependency-management' version '1.1.4'
id 'org.liquibase.gradle' version '2.2.0'
}
group = 'com.ywa'
version = '0.0.1-SNAPSHOT'
java {
sourceCompatibility = '21'
targetCompatibility = '21'
}
configurations {
compileOnly {
extendsFrom annotationProcessor
}
}
repositories {
mavenCentral()
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-validation'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-security'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'io.jsonwebtoken:jjwt-orgjson:0.11.5'
implementation 'io.jsonwebtoken:jjwt-api:0.11.5'
implementation 'io.jsonwebtoken:jjwt-impl:0.11.5'
developmentOnly 'org.springframework.boot:spring-boot-devtools'
runtimeOnly 'org.postgresql:postgresql'
compileOnly 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'org.springframework.security:spring-security-test'
implementation 'org.postgresql:postgresql'
implementation 'org.liquibase:liquibase-core:4.20.0'
}
//tasks.named('test') {
// useJUnitPlatform()
//} (commented the tests to be able to be able to run at least the "gradle clean" and "gradle build" tasks
几乎一切。我尝试到处寻求帮助,使用了
liquibaseRuntime 'org.liquibase:liquibase-core:4.20.0'
,但没有任何效果。
另外,如果有必要,这里是我的 liquibase.properties 和 application.properties 文件,以及项目外观的图像:
liquibase.properties
changeLogFile=classpath:db/changelog/db.changelog-master.yaml
url=jdbc:postgresql://localhost:5431/dml-local-db
username=user
password=password
driver=org.postgresql.Driver
application.properties
#--Local host for devs--
spring.datasource.url= jdbc:postgresql://localhost:5431/dml-local-db
spring.datasource.username= user
spring.datasource.password= password
spring.liquibase.enabled= true
spring.jpa.properties.hibernate.jdbc.lob.non_contextual_creation= true
spring.jpa.properties.hibernate.dialect= org.hibernate.dialect.PostgreSQLDialect
# Hibernate ddl auto (create, create-drop, validate, update)
spring.jpa.hibernate.ddl-auto=validate
# App Properties
dml.app.jwtSecret= mysecret
dml.app.jwtExpirationMs= 3600000
dml.app.jwtRefreshExpirationMs= 86400000
## For test
#dml.app.jwtExpirationMs= 60000
#dml.app.jwtRefreshExpirationMs= 120000
您遇到异常的原因
Liquibase-core was not found not found in the liquibaseRuntime configuration!
是liquibase gradle插件需要在其类路径中有liquibase-core
库。
我检查了您的配置/设置,看起来您仍然缺少一些导入工件。
在
dependencies
块中需要添加liquibase运行时/类路径
dependencies {
// Put your same libraries here
// Then runtime libraries that required by plugin
liquibaseRuntime 'org.liquibase:liquibase-core:4.24.0'
liquibaseRuntime 'info.picocli:picocli:4.7.5'
liquibaseRuntime 'org.postgresql:postgresql'
}
配置 liquibase,让它知道从哪里获取
liquibabse.properies
liquibase {
activities {
main {
defaultsFile "src/main/resources/liquibase.properties"
}
}
}
不要忘记将您的
liquibase.properties
放入 src/main/resources/
文件夹中。
更新您的
liquibase.properties
(查看searchPath
和changeLogFile
的详细信息)
searchPath=src/main/resources
changeLogFile=db/changelog/db.changelog-master.yaml
url=jdbc:postgresql://localhost:5431/dml-local-db
username=user
password=password
driver=org.postgresql.Driver
您现在已准备好运行第一个迁移命令;
./gradlew update