Search code examples
javamavenintellij-idea

Can't use external java library in Intellij IDEA


I've created java library that depends on jackson library and published it to maven repository. In my new project I implement only my library, not jackson. A method in this library throws JsonProcessingException, but when I call it I get error "cannot access JsonProcessingException. class file for com.fasterxml.jackson.core.JsonProcessingException not found". And I even can't import this class. However I can see com.fasterxml.jackson.core library in External Libraries in Intellij IDEA. Why does IDEA shows me this library, but does not allows to import classes from it?

In another project I tried implementing ord.springframework.boot:spring-boot-starter-web instead of my library. spring-boot-starter-web also depends on com.fasterxml.jackson.core and I can also see jackson library in External Libraries in Intellij IDEA. But in this case I can import com.fasterxml.jackson.core.JsonProcessingException. Any thoughts?


Solution

  • This is the difference between gradle's api and implementation scope dependencies. api dependencies can be used in downstream projects, implementation dependencies are internal to the library and cannot be used unless you also depend on them directly. IntelliJ will still show them, as they are needed at runtime.

    Maven may have a similar concept, but I'm not sure if it does or what it's called.