How to resolve jar package conflicts that occur when using Gradle

Source: Internet
Author: User

Objective

Before I used Gradle's blog post already mentioned, Gradle to rely on the management is more intelligent, if there are two packages dependent on the same package, and the version is different, Gradle will make automatic selection, so as to avoid the jar package conflicts.

In other words, in the theory of using gradle generally, there will be no jar package conflict, then why this blog post today?

Gradle can help you manage a different version but package the same dependencies. But if two of different dependencies conflict with each other, the conflict gradle can't automatically help you, because it doesn't know which one you need.

Problem description

My side, for example, is the conflict that I have appeared:

The following error occurred on the console when the project was started

slf4j: class path contains Multiple slf4j bindings.
Slf4j:found binding in [jar:file:/d:/worksoftware/gradlerepository/caches/modules-2/files-2.1/org.slf4j/ slf4j-log4j12/1.7.25/110cefe2df103412849d72ef7a67e4e91e4266b4/slf4j-log4j12-1.7.25.jar!/org/slf4j/impl/ Staticloggerbinder.class]
Slf4j:found binding in [jar:file:/d:/worksoftware/gradlerepository/caches/modules-2/ files-2.1/ch.qos.logback/logback-classic/1.1.11/ccedfbacef4a6515d2983e3f89ed753d5d4fb665/ Logback-classic-1.1.11.jar!/org/slf4j/impl/staticloggerbinder.class]
Slf4j:see http://www.slf4j.org/ Codes.html#multiple_bindings for an explanation.
Slf4j:
Detected both Log4j-over-slf4j.jar and bound Slf4j-log4j12.jar on the class path, preempting stackoverflowerror.
Slf4j:see also http://www.slf4j.org/codes.html#log4jDelegationLoop for more details.
Exception in thread "main" Java.lang.ExceptionInInitializerError
At Org.slf4j.impl.staticloggerbinder.<init> (staticloggerbinder.java:72)

The important part I have already marked, it is obvious that log4j-over-slf4j.jar this package and the Slf4j-log4j12.jar package conflict.

This is two completely different packages, but there is also a conflict, Gradle no way to handle it, so we need to handle it manually.

Problem solving

First look at all the dependencies, you can use the gradlew-q app:dependencies command to view, if you use idea, in the Gradle window has this option, double-click Run can

The dependencies that appear are as follows

\---com.baidu.unbiz:fluent-validator-jsr303:1.0.9
+---com.baidu.unbiz:fluent-validator:1.0.9
| +---org.slf4j:slf4j-api:1.7.7-1.7.25
| \---org.slf4j:slf4j-log4j12:1.7.7-1.7.25
| +---org.slf4j:slf4j-api:1.7.25
| \---log4j:log4j:1.2.17
+---org.hibernate:hibernate-validator:5.2.1.final, 5.3.5.Final (*)
+---javax.el:javax.el-api:2.2.4
+---org.glassfish.web:javax.el:2.2.4
| \---javax.el:javax.el-api:2.2.4
+---org.slf4j:slf4j-api:1.7.7-1.7.25
\---org.slf4j:slf4j-log4j12:1.7.7-1.7.25 (*)

I just intercepted the part where you need to see all the dependencies have determined where your conflict is occurring and thus determine how you need to handle

All I need is to exclude log4j12 from this dependency

So the dependencies in modifying the Gradle configuration are as follows

Compile (group: ' Com.baidu.unbiz ', Name: ' fluent-validator-jsr303 ', version: ' 1.0.9 ') {
Exclude module: ' Slf4j-log4j12 '
and then restart the project, conflict resolution

Summarize

in fact, depending on the conflict in many cases Gradle has helped us to deal with, if the occurrence of the above unforeseen conflict, Gradle will also give a very clear hint. All we have to do is to calmly analyze the wrong information and then do a careful scrutiny.

How to resolve jar package conflicts that occur when using Gradle

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.