[英]Maven javax dependency exclusion doesn't work
我正在尝试使用假客户端实现 OAuth2 密码授予类型。 我遵循了本指南(仅假装客户端部分)。 我在单独的项目中执行此操作(我们称之为feign
),然后将其用作另一个project
中的依赖项(我们这样称呼它)。 问题是,如果我按照指南中的方式执行所有操作,项目中的javax.ws.rs.core.Response
class 就会变得与原来不同,因此一种方法就会消失。 我的pom.xml
feign
如果我完全按照指南(指南的源代码)
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Edgware.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-oauth2</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-feign</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka</artifactId>
</dependency>
</dependencies>
我不需要在这里写版本,因为它们在 pom 依赖中。 但是在我这样做之后, project
开始看到其他javax.ws.rs.core.Response
比以前更多,我切换分支并比较这两个类,它们实际上是不同的,我接触到的唯一区别是添加了feign
作为project
。 所以我试图排除dependencyManagement
并在feign
中手动添加最新版本:
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-oauth2</artifactId>
<version>2.2.5.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-feign</artifactId>
<version>1.4.7.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-security</artifactId>
<version>2.2.5.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka</artifactId>
<version>1.4.7.RELEASE</version>
</dependency>
它没有帮助, javax.ws.rs.core.Response
再次更改(方法readEntity
消失)。 我假设它在feign
的依赖项之一中使用,所以我尝试手动将其排除在project
中:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.4.3</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<filters>
<filter>
<artifact>feign-client</artifact>
<excludes>
<exclude>javax/ws/rs/core/**</exclude>
</excludes>
</filter>
</filters>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
...
<dependency>
<groupId>...</groupId>
<artifactId>feign-client</artifactId>
<version>...</version>
<optional>true</optional>
</dependency>
但它也没有帮助,在mvn clean install
之后它仍然没有看到方法readEntity
。 有人可以调查一下,我如何才能让旧版本的Response
保持原状?
只需在对feign
模块的依赖之前添加此依赖即可解决:
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>javax.ws.rs-api</artifactId>
<version>2.1.1</version>
</dependency>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.