org.apache.http.entity.ContentType
在里面org.apache.httpcomponents:httpcore:4.3.x
模块。但也是如此org.apache.http.HttpEntity
。您找到一个而不是另一个的事实很可能意味着它们没有从 v4.3.x JAR 中提取。 Apache HttpCommponents 项目最近移动了很多类。所以可能会发现HttpEntity
在较旧的/不同的版本中httpcore
不知何故,它被拉进来了;没有的版本ContentType
班级。您需要验证它在哪里找到HttpEntity
。有几种方法可以查看从何处引入依赖项。
Option 1
One of the easiest ways is to put your cursor on the class (either in the import statement or a variable declaration) and open the quick documentation (Ctrl+Q or ⌃J). At the top of the documentation dialog, it will show the dependency where the class is found:
Option 2
This option will show you if you have multiple instances of a class on your class path. Open the Goto Class dialog (Ctrl+N or ⌘O) and enter the class name (you can fully qualify or not. You can even paritally enter the name and use camel case search). In the list of classes that are found, to the right will be where the class is found.
TO the right is the dependency from which the class is coming from. If it shows more than once, it means that it is being pulled in multiple times in different jars. This can happen (when using a build tool) if another dependency is pulling in a different version of httpcore
as a transitive dependency. So you will need to resolve that. Notice in my screen shot I have two different versions of the org.springframework.http.HttpEntity
class. One from Spring 3.2.10 and one from 4.0.6. In this particular case it is because I have a Spring 3.2.x based module and a separate Spring 4.0.x module in my project. So I'm OK with that as they do not clash since those are independent modules. But in most cases, that would be cause for concern.
Option 3您还可以展开并查看外部库中的节点Project用于查看依赖项是否被拉入两次的工具窗口。
It's unclear how your project is configured. You mentioned gradle, but it seemed more like an after thought. If you are using maven or gradle, and the proper httpcore
dependency is declared in your pom or build file, make sure you perform a reimport on the appropriate build tool window so that it synchronizes properly and that module is added to the project's dependency. Then use the above information to see if you have multiple versions of the httpcore
module being pulled in.