Home > Back-end >  Maven javax dependency exclusion doesn't work
Maven javax dependency exclusion doesn't work

Time:03-15

I'm trying to implement OAuth2 password grant type with feign client. I followed this guide (only the feign client part). I do it in the separate project (let's call it feign) and then use it as dependency in the other project (let's call it like this). The problem is that if I do everything like in the guide, the javax.ws.rs.core.Response class in the project becomes different from what it was, so one method just disappers. My pom.xml of feign if I follow the guide fully (the source code of the guide)

    <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>

I don't need to write versions here because they're in the pom dependency. But after I do that, the project starts seeing other javax.ws.rs.core.Response than it was before, I switched branches and compared these two classes, they're in fact different, the only difference I touched is that added feign as dependency in project. So I tried to exclude dependencyManagement and added latest versions manually in the 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>

It didn't help, javax.ws.rs.core.Response changed again (the method readEntity disappears). I assume it's used in one of the dependencies in the feign so I tried to exclude it in the project manually:

<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>

But it didn't help too, after mvn clean install it still doesn't see the method readEntity. Can someone look into it, how do I achieve leaving the old version of Response how it was before?

CodePudding user response:

Solved just by adding this dependency before dependency on feign module:

        <dependency>
            <groupId>javax.ws.rs</groupId>
            <artifactId>javax.ws.rs-api</artifactId>
            <version>2.1.1</version>
        </dependency>
  • Related