panosjuan
panosjuan

Reputation: 49

Jackson not being imported with gradle

I am trying to parse some objects to JSON files, and apparently I can import some phantom libraries (more on that later) but when I try to execute my code, it fails here:

String jsonStr = new ObjectMapper().writeValueAsString(adv);  

With this exception:

Exception in thread "main" java.lang.NoClassDefFoundError:com/fasterxml/jackson/annotation/JsonView

My build.gradle:

plugins {
    id 'java'
}

group 'com.myGroup.util'
version '1.0-SNAPSHOT'

repositories {
    mavenCentral()
}

dependencies {
    testImplementation 'org.junit.jupiter:junit-jupiter-api:5.7.0'
    testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.7.0'

    compileOnly 'org.projectlombok:lombok:1.18.4'
    annotationProcessor 'org.projectlombok:lombok:1.18.4'
    
    implementation group: 'com.fasterxml.jackson.core', name: 'jackson-core', version: '2.0.1'
    implementation group: 'com.fasterxml.jackson.core', name: 'jackson-annotations', version: '2.0.1'
    implementation group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.0.1'
    
}

test {
    useJUnitPlatform()
}

And in my Main.java class I can do this import:

import com.fasterxml.jackson.core.*;

with no problems, the only issue is that when I put the mouse on top it displays that no JavaDoc has been found, fishy... I even tried removing all the dependencies from my gradle.build file and it will still let me import the package but it seems like it is empty.

Upvotes: 3

Views: 13239

Answers (1)

ndkshr
ndkshr

Reputation: 55

I had the same issue, while taking gradle dependency as

implementation 'com.fasterxml.jackson.dataformat.jackson-dataformat-xml:2.13.0'

But apparently, it has to be declared as @PickedBrain pointed out

implementation 'com.fasterxml.jackson.dataformat:jackson-dataformat-xml:2.13.0'

Gradle dependency syntax

implementation '{domain/group}:{package/name}:{version}'

Upvotes: 3

Related Questions