1

In the project I'm working on, my team has the following pom file:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xmlns="http://maven.apache.org/POM/4.0.0"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.example</groupId>
    <artifactId>example-project</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>example-project</name>
    <description>example-project</description>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.3.6.RELEASE</version>
        <relativePath/>
    </parent>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <java.version>1.8</java.version>
    </properties>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>com.amazonaws</groupId>
                <artifactId>aws-java-sdk-bom</artifactId>
                <version>1.11.13</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>com.jayway.jsonpath</groupId>
            <artifactId>json-path</artifactId>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>com.amazonaws</groupId>
            <artifactId>aws-java-sdk-s3</artifactId>
            <version>1.11.13</version>
        </dependency>

        <dependency>
            <groupId>com.netflix.hystrix</groupId>
            <artifactId>hystrix-core</artifactId>
            <version>1.5.3</version>
        </dependency>

        <dependency>
            <groupId>com.netflix.hystrix</groupId>
            <artifactId>hystrix-metrics-event-stream</artifactId>
            <version>1.5.3</version>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-configuration-processor</artifactId>
            <optional>true</optional>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>


    </dependencies>


    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-checkstyle-plugin</artifactId>
                <version>2.17</version>
                <dependencies>
                    <dependency>
                        <groupId>com.puppycrawl.tools</groupId>
                        <artifactId>checkstyle</artifactId>
                        <version>7.0</version>
                    </dependency>
                </dependencies>
                <configuration>
                    <configLocation>google_checks.xml</configLocation>
                </configuration>
                <executions>
                    <execution>
                        <id>checkstyle-check</id>
                        <phase>validate</phase>
                        <configuration>
                            <configLocation>
                                http://dummy-url.com
                            </configLocation>
                            <encoding>UTF-8</encoding>
                            <consoleOutput>true</consoleOutput>
                            <includeTestSourceDirectory>true</includeTestSourceDirectory>
                            <failsOnError>true</failsOnError>
                            <failOnViolation>true</failOnViolation>
                        </configuration>
                        <goals>
                            <goal>check</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.jacoco</groupId>
                <artifactId>jacoco-maven-plugin</artifactId>
                <version>0.7.4.201502262128</version>
                <executions>
                    <execution>
                        <id>default-prepare-agent</id>
                        <goals>
                            <goal>prepare-agent</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>default-report</id>
                        <goals>
                            <goal>report</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>default-check</id>
                        <goals>
                            <goal>check</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <excludes>
                        <exclude>**/Application.*</exclude>
                    </excludes>
                    <rules>
                        <rule>
                            <element>BUNDLE</element>
                            <limits>
                                <limit>
                                    <counter>COMPLEXITY</counter>
                                    <value>COVEREDRATIO</value>
                                    <minimum>0.80</minimum>
                                </limit>
                            </limits>
                        </rule>
                    </rules>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

I've attached a screenshot of the Maven dependencies in the Maven toolbar provided by Intellij that results from this POM file.Maven Dependencies in Intellij

Note that the red-highlighted portions only occur when we try to add the spring-boot JPA dependency. Without it, our project works fine. It seems like Maven is re-adding dependencies that have already been added which is weird because Hystrix, for example, has NO relation to JPA.

Anyone know how to resolve this?

Neil Stockton
  • 11,383
  • 3
  • 34
  • 29
Enis
  • 171
  • 9
  • Hysterix is a dependency of YOUR project (is in the Pom you posted). Why wouldn't you expect it? – Pace Jul 26 '16 at 00:03

3 Answers3

0

Maven seems to add the dependencies transitively and hence you get the extra dependencies with relevant versions present.

You can try to exclude the additional dependencies as needed. Refer: Exclude all transitive dependencies of a single dependency

Community
  • 1
  • 1
Amit Mahajan
  • 895
  • 6
  • 34
0

To verify that it is the jpa dependency that is pulling in those jars again you can run the following command in the same directory as your pom.xml

mvn dependency:tree -Dverbose

This will show an output of where the depdencies come from, just search for the duplicates.

You can add the exclusion tag to whatever may be transitively pulling in those libraries like:

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-data-jpa</artifactId>
    <exclusions>
            <exclusion>
                <groupId>*</groupId>
                <artifactId>*</artifactId>
        </exclusion>
    </exclusions>    
</dependency>

From Maven 3.2.1 onwards you are able to wildcard exclude transitive dependencies.

Or if you dont want to use the * wild card, explicitly state the groupId and artifactId.

UserF40
  • 3,533
  • 2
  • 23
  • 34
  • That didn't work, it still results in the same screenshot as what's in the question. We tried doing that for one of the red-underlined dependencies, and nothing happened. The thing that stumps us is that Maven should not be importing Hystrix dependencies into the project; there's no way Hystrix is a transitive dependency of JPA. – Enis Jul 25 '16 at 22:16
  • have you run rebuild on the project in intellij? – UserF40 Jul 25 '16 at 22:17
0

Its not realy a error, it is a warning.

A warning about duplicate dependencies.

If you add the spring-boot-jpa dependencies you add other spring-boot dependencies indirectly too. But if you add spring-boot strictly, the indirect dependencies of spring-boot-jpa is ignored and may resolve in incompatibilities.

Drop that spring-boot to use the spring-boot-jpa tree only please.

Grim
  • 1,938
  • 10
  • 56
  • 123