导入io.r2dbc.postgresql.codec时gradle的问题
每次我尝试从gradle(gradle bootrun或./gradlew bootrun)构建或运行时,导入io.r2dbc.postgresql.codec.json时,我会收到此错误:
Stack trace> Task :compileJava FAILED
/home/repos/test-backend/src/main/java/com/dnt/backend/BackendApplication.java:3: error: package io.r2dbc.postgresql.codec does not exist
import io.r2dbc.postgresql.codec.Json;
^
1 error
重现
package com.test.backend;
import io.r2dbc.postgresql.codec.Json;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class BackendApplication {
public static void main(String[] args) {
SpringApplication.run(BackendApplication.class, args);
Json test = Json.of("testing");
System.out.println(test);
}
}
build.gradle.gradle.gradle:
plugins {
id 'org.springframework.boot' version '2.6.7'
id 'io.spring.dependency-management' version '1.0.11.RELEASE'
id 'java'
}
group = 'com.test'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '18'
configurations {
compileOnly {
extendsFrom annotationProcessor
}
}
repositories {
mavenCentral()
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-jdbc'
implementation 'org.springframework.boot:spring-boot-starter-data-r2dbc'
implementation 'org.springframework.boot:spring-boot-starter-validation'
implementation 'org.springframework.boot:spring-boot-starter-webflux'
compileOnly 'org.projectlombok:lombok'
runtimeOnly 'io.r2dbc:r2dbc-postgresql'
runtimeOnly 'org.postgresql:postgresql'
annotationProcessor 'org.projectlombok:lombok'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'io.projectreactor:reactor-test'
}
tasks.named('test') {
useJUnitPlatform()
}
预期行为/代码
时,从IDE(VSCODE)调试项目,它可以工作并打印JSON对象。
版本
- 驱动程序:0.8.12
- 数据库:14.2
- Java:18
- OS:Linux 5.10
- Gradle:7.4.2
Every time i try to build or run from gradle (gradle bootRun or ./gradlew bootRun), while importing io.r2dbc.postgresql.codec.Json, i get this error:
Stack trace
> Task :compileJava FAILED
/home/repos/test-backend/src/main/java/com/dnt/backend/BackendApplication.java:3: error: package io.r2dbc.postgresql.codec does not exist
import io.r2dbc.postgresql.codec.Json;
^
1 error
Steps to reproduce
package com.test.backend;
import io.r2dbc.postgresql.codec.Json;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class BackendApplication {
public static void main(String[] args) {
SpringApplication.run(BackendApplication.class, args);
Json test = Json.of("testing");
System.out.println(test);
}
}
build.gradle:
plugins {
id 'org.springframework.boot' version '2.6.7'
id 'io.spring.dependency-management' version '1.0.11.RELEASE'
id 'java'
}
group = 'com.test'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '18'
configurations {
compileOnly {
extendsFrom annotationProcessor
}
}
repositories {
mavenCentral()
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-jdbc'
implementation 'org.springframework.boot:spring-boot-starter-data-r2dbc'
implementation 'org.springframework.boot:spring-boot-starter-validation'
implementation 'org.springframework.boot:spring-boot-starter-webflux'
compileOnly 'org.projectlombok:lombok'
runtimeOnly 'io.r2dbc:r2dbc-postgresql'
runtimeOnly 'org.postgresql:postgresql'
annotationProcessor 'org.projectlombok:lombok'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'io.projectreactor:reactor-test'
}
tasks.named('test') {
useJUnitPlatform()
}
Expected behavior/code
When i debug-run the project from the IDE (vscode) it works and prints the Json object.
Versions
- Driver: 0.8.12
- Database: 14.2
- Java: 18
- OS: Linux 5.10
- Gradle: 7.4.2
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我通过将build.gradle更改为:
I solved it by changing the build.gradle to:
它必须是版本控制问题,我尝试了此问题,并解决了:
It must be versioning problems, I tried this and it is solved: