无法在IntelliJ IDEA中使用外部Java库。

huangapple go评论65阅读模式
英文:

Can't use external java library in Intellij IDEA

问题

我已经创建了一个依赖于jackson库并发布到maven仓库的Java库。
在我的新项目中,我只实现了我的库,没有包含jackson库。
这个库中的一个方法抛出JsonProcessingException异常,但是当我调用它时,出现了错误“无法访问JsonProcessingException。找不到com.fasterxml.jackson.core.JsonProcessingException的类文件”,甚至无法导入这个类。
然而,我可以在Intellij IDEA的External Libraries中看到com.fasterxml.jackson.core库。
为什么IDEA显示了这个库,但不允许导入其中的类?

在另一个项目中,我尝试实现ord.springframework.boot:spring-boot-starter-web,而不是使用我的库。spring-boot-starter-web也依赖于com.fasterxml.jackson.core,并且我也可以在Intellij IDEA的External Libraries中看到jackson库。但是在这种情况下,我可以导入com.fasterxml.jackson.core.JsonProcessingException。有什么想法吗?

英文:

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?

答案1

得分: 0

这是gradle的apiimplementation范围依赖之间的区别。 api依赖项可用于下游项目,implementation依赖项仅供库内部使用,除非您也直接依赖于它们,否则无法使用。 IntelliJ仍然会显示它们,因为它们在运行时是必需的。

Maven可能有类似的概念,但我不确定是否有,或者叫什么名字。

英文:

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.

huangapple
  • 本文由 发表于 2023年6月22日 13:33:07
  • 转载请务必保留本文链接:https://go.coder-hub.com/76528839.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定