DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

How does AI transform chaos engineering from an experiment into a critical capability? Learn how to effectively operationalize the chaos.

Data quality isn't just a technical issue: It impacts an organization's compliance, operational efficiency, and customer satisfaction.

Are you a front-end or full-stack developer frustrated by front-end distractions? Learn to move forward with tooling and clear boundaries.

Developer Experience: Demand to support engineering teams has risen, and there is a shift from traditional DevOps to workflow improvements.

Related

  • Maven Dependency Scope Applied
  • How To Approach Dependency Management in Java [Video]
  • How To Convert Image Files Into GIF or WebP Format Using Java
  • How To Validate Names Using Java

Trending

  • How Node.js Works Behind the Scenes (HTTP, Libuv, and Event Emitters)
  • Supercharge Your Java Apps With AI: A Practical Tutorial
  • Operationalizing Data Quality in Cloud ETL Workflows: Automated Validation and Anomaly Detection
  • From Code to Customer: Building Fault-Tolerant Microservices With Observability in Mind
  1. DZone
  2. Coding
  3. Java
  4. Dependency Convergence in Maven

Dependency Convergence in Maven

By 
Jason Whaley user avatar
Jason Whaley
·
Jul. 11, 12 · Interview
Likes (1)
Comment
Save
Tweet
Share
24.4K Views

Join the DZone community and get the full member experience.

Join For Free

I was running in to a problem with a Java project that occured only in IntelliJ Idea, but not on the command line, when running specific test classes in Maven. The exception stack trace had the following in it:

Caused by: com.sun.jersey.api.container.ContainerException: No WebApplication provider is present

That seems like an easy problem to fix - it is the exception message that is given when jersey can’t find the provider for JAX-RS. Fixing it is normally just a matter of making sure jersey-core is on the classpath to fulfill SPI requirements for JAX-RS. For some reason though this isn’t happening in IntelliJ Idea. I inspected the log output of the test run and it is quite clear that all of the jersey dependencies are on the classpath. Then it dawns me on the try running mvn dependency:tree from inside of Idea. Here is what I found:

[INFO] +- org.mule.modules:mule-module-jersey:jar:3.2.1:provided
[INFO] |  +- com.sun.jersey:jersey-server:jar:1.6:provided
[INFO] |  +- com.sun.jersey:jersey-json:jar:1.6:provided
[INFO] |  |  +- com.sun.xml.bind:jaxb-impl:jar:2.2.3-1:provided
[INFO] |  |  \- org.codehaus.jackson:jackson-xc:jar:1.7.1:provided
[INFO] |  +- com.sun.jersey:jersey-client:jar:1.6:provided
[INFO] |  \- org.codehaus.jackson:jackson-jaxrs:jar:1.8.0:provided
...
[INFO] +- org.jclouds.driver:jclouds-sshj:jar:1.4.0-rc.3:compile
[INFO] |  +- org.jclouds:jclouds-compute:jar:1.4.0-rc.3:compile
[INFO] |  |  \- org.jclouds:jclouds-scriptbuilder:jar:1.4.0-rc.3:compile
[INFO] |  +- org.jclouds:jclouds-core:jar:1.4.0-rc.3:compile
[INFO] |  |  +- net.oauth.core:oauth:jar:20100527:compile
[INFO] |  |  +- com.sun.jersey:jersey-core:jar:1.11:compile
[INFO] |  |  +- com.google.inject.extensions:guice-assistedinject:jar:3.0:compile

Notice how I have jersey-core 1.11 coming from jclouds-core but jersey 1.6 everywhere else. That, my friends, is a dependency convergence problem. Maven with its default set of plugins (read: no maven-enforcer-plugin) does not even warn you if something like this happens. In this case, somehow jclouds-core depends directly on jersey-core and happens to resolve the dependency to the version that jclouds-core declared first before jersey-core can be resolved as a transitive dependency on mule-module-jersey.

To fix the symptom, all I had to do was add the jersey-core dependency explicitely as a top level dependency in my pom:

<dependency>
    <groupId>com.sun.jersey</groupId>
    <artifactId>jersey-core</artifactId>
    <version>${jersey.version}</version>
    <scope>provided</scope>
</dependency>

But doing so only fixes the symptom, not the problem. The real problem is that the maven project I’m working on does not presently attempt to detect or resolve dependency convergence problems. This is where the maven-enforcer-plugin comes in handy. You can have the enforcer plugin run the DependencyConvergence rule agaisnt your build and have it fail when you have potential conflicts in your transitive dependencies that you haven’t resolved through exclusions or declaring direct dependencies yet. Binding the maven-enforcer-plugin to your build would look something like this:

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-enforcer-plugin</artifactId>
            <version>1.0.1</version>
            <executions>
                <execution>
                    <id>enforce</id>
                    <configuration>
                        <rules>
                            <DependencyConvergence/>
                        </rules>
                    </configuration>
                    <goals>
                        <goal>enforce</goal>
                    </goals>
                    <phase>validate</phase>
                </execution>
            </executions>
        </plugin>
    </plugins>
...
</build>

I chose to bind to the validate phase since that is the first phase to be run in the maven lifecycle. Now my build fails immediately and contains very useful output that looks like the following:

Dependency convergence error for org.codehaus.jackson:jackson-jaxrs:1.7.1 paths to dependency are:
+-com.nodeable:server:1.0-SNAPSHOT
  +-org.mule.modules:mule-module-jersey:3.2.1
    +-com.sun.jersey:jersey-json:1.6
      +-org.codehaus.jackson:jackson-jaxrs:1.7.1
and
+-com.nodeable:server:1.0-SNAPSHOT
  +-org.mule.modules:mule-module-jersey:3.2.1
    +-org.codehaus.jackson:jackson-jaxrs:1.8.0

There are many rules you can apply besides DependencyConvergence. However, if the output from the DependencyConvergence rule looks anything like mine does presently, it might take you a while before you get around to getting your maven build to pass and conform to other rules.

 

Dependency Apache Maven

Published at DZone with permission of Jason Whaley, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • Maven Dependency Scope Applied
  • How To Approach Dependency Management in Java [Video]
  • How To Convert Image Files Into GIF or WebP Format Using Java
  • How To Validate Names Using Java

Partner Resources

×

Comments

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • [email protected]

Let's be friends: