导入io.r2dbc.postgresql.codec时gradle的问题

发布于 2025-01-29 10:00:10 字数 2165 浏览 7 评论 0原文

每次我尝试从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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

手长情犹 2025-02-05 10:00:10

我通过将build.gradle更改为:

implementation 'io.r2dbc:r2dbc-postgresql'

I solved it by changing the build.gradle to:

implementation 'io.r2dbc:r2dbc-postgresql'
注定孤独终老 2025-02-05 10:00:10

它必须是版本控制问题,我尝试了此问题,并解决了:

implementation 'org.postgresql:r2dbc-postgresql'

It must be versioning problems, I tried this and it is solved:

implementation 'org.postgresql:r2dbc-postgresql'
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文