繁体   English   中英

Maven javax 依赖排除不起作用

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM