Gradle import com.fasterxml.jackson.datatype无法解析

时间:2017-12-24 02:20:46

标签: java spring gradle jackson fasterxml

import com.fasterxml.jackson.datatype cannot be resolved

如屏幕截图所示,无法解析导入com.fasterxml.jackson.datatype。

我在build.gradle中导入了jackson-datatype-jsr310',版本:' 2.9.3,

buildscript {
    ext {
        springBootVersion = '1.5.9.RELEASE'
    }
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
    }
}

apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'

group = 'com.linkedin.learning'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = 1.8

repositories {
    mavenCentral()
}

dependencies {
    compile('org.springframework.boot:spring-boot-starter-data-jpa')
    compile('org.springframework.boot:spring-boot-starter-web')
    runtime('com.h2database:h2')
    testCompile('org.springframework.boot:spring-boot-starter-test')

    // https://mvnrepository.com/artifact/com.fasterxml.jackson.datatype/jackson-datatype-jsr310
compile group: 'com.fasterxml.jackson.datatype', name: 'jackson-datatype-jsr310', version: '2.9.3'


}

最后几行来自Maven Repo:https://mvnrepository.com/artifact/com.fasterxml.jackson.datatype/jackson-datatype-jsr310/2.9.3

我想要使用的是

com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;

但是,即使是com.fasterxml.jackson.datatype也无法正确导入。

为了解决这个问题,我尝试在build.gradle中添加更多依赖项,正如这篇文章建议的那样

Jackson cannot access com.fasterxml.jackson.core.ObjectCodec

buildscript {
    ext {
        springBootVersion = '1.5.9.RELEASE'
    }
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
    }
}

apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'

group = 'com.linkedin.learning'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = 1.8

repositories {
    mavenCentral()
}

dependencies {
    compile('org.springframework.boot:spring-boot-starter-data-jpa')
    compile('org.springframework.boot:spring-boot-starter-web')
    runtime('com.h2database:h2')
    testCompile('org.springframework.boot:spring-boot-starter-test')

    // https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-annotations
compile group: 'com.fasterxml.jackson.core', name: 'jackson-annotations', version: '2.9.3'


    // https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-core
compile group: 'com.fasterxml.jackson.core', name: 'jackson-core', version: '2.9.3'

    // https://mvnrepository.com/artifact/com.fasterxml.jackson.module/jackson-module-parameter-names
compile group: 'com.fasterxml.jackson.module', name: 'jackson-module-parameter-names', version: '2.9.3'

    // https://mvnrepository.com/artifact/com.fasterxml.jackson.datatype/jackson-datatype-jdk8
compile group: 'com.fasterxml.jackson.datatype', name: 'jackson-datatype-jdk8', version: '2.9.3'

    // https://mvnrepository.com/artifact/com.fasterxml.jackson.datatype/jackson-datatype-jsr310
compile group: 'com.fasterxml.jackson.datatype', name: 'jackson-datatype-jsr310', version: '2.9.3'

}

但它仍未导入。

我使用的IDE是Spring Tool Suite,它是一个Web应用程序

谢谢!

编辑:

我知道jackson-datatype-jsr310已被弃用,并且自Jackson 2.8.5起已成为Jackson Java 8模块的一部分。

https://github.com/FasterXML/jackson-datatype-jsr310

但是,我将它添加到build.gradle的末尾,

    // https://mvnrepository.com/artifact/com.fasterxml.jackson.datatype/jackson-datatype-jdk8
compile group: 'com.fasterxml.jackson.datatype', name: 'jackson-datatype-jdk8', version: '2.9.3'

并导入此

import com.fasterxml.jackson.datatype.jdk8;

它仍然显示无法解析导入com.fasterxml.jackson.datatype。

enter image description here

0 个答案:

没有答案