报错内容:
Caused by: org.apache.maven.plugin.compiler.CompilationFailureException: Compilation failure
error: cannot access NotThreadSafe
报错原因:
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.2</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpcore</artifactId>
<version>4.4.5</version>
</dependency>
httpclient 和 httpcore 包的版本不匹配。
注意!网上很多帖子都说降低httpcore到4.4.4 就能解决问题,因为4.5.2和4.4.4匹配。
但是这里的httpclient包本身就是有安全漏洞的,容易被XSS攻击。
httpclient问题详见: https://github.com/advisories/GHSA-7r82-7xv7-xcpj
Apache HttpClient versions prior to version 4.5.13 and 5.0.3 can misinterpret malformed authority component in request URIs passed to the library as java.net.URI object and pick the wrong target host for request execution.
因此,这里可以将httpclient升级到4.5.13,与httpcore的4.4.5匹配。两全其美。
正确的引用姿势:
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.13</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpcore</artifactId>
<version>4.4.5</version>
</dependency>