Skip to content

Class conflict with okio #1211

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
KerwinAusten opened this issue Jan 28, 2023 · 4 comments · Fixed by #1217
Closed

Class conflict with okio #1211

KerwinAusten opened this issue Jan 28, 2023 · 4 comments · Fixed by #1217

Comments

@KerwinAusten
Copy link

I have okhttp 4.10.0 and okio 3.0.0 in my project and after I upgrade to 0.4.0 it raises an error like this

Caused by: java.lang.NoSuchFieldError: Companion
	at okhttp3.internal.Util.<clinit>(Util.kt:70)
	at okhttp3.internal.concurrent.TaskRunner.<clinit>(TaskRunner.kt:309)
	at okhttp3.ConnectionPool.<init>(ConnectionPool.kt:41)
	at okhttp3.ConnectionPool.<init>(ConnectionPool.kt:47)
	at okhttp3.OkHttpClient$Builder.<init>(OkHttpClient.kt:471)

I found in version 0.4.0, there is a new dependency io.grpc and there is a okio.Options java class in this dependency.
On the other hand, there is also a okio.Options in okio, but it's writed with kotlin and this is the main culprit in this problem.

@KerwinAusten
Copy link
Author

Ok, when I use

<dependency>
    <groupId>com.clickhouse</groupId>
    <artifactId>clickhouse-jdbc</artifactId>
    <version>0.4.0</version>
    <!-- use uber jar with all dependencies included, change classifier to http for smaller jar -->
    <classifier>all</classifier>
    <exclusions>
        <exclusion>
            <groupId>*</groupId>
            <artifactId>*</artifactId>
        </exclusion>
    </exclusions>
</dependency>

It works well, But isn't the problem #1134 still there?

@zhicwu
Copy link
Contributor

zhicwu commented Jan 29, 2023

Thanks @IcebergXTY. You may exclude dependencies you don't need from clickhouse-jdbc. Shaded jar makes it simpler, if you picked the right classifier. If you don't need gRPC, which is still experimental by the way, you may change the classifier from all to http.

As to issue 1134, it seems you want a shaded jar with source? Let's reopen the issue and I'll fix that.

@KerwinAusten
Copy link
Author

As to issue 1134, it seems you want a shaded jar with source? Let's reopen the issue and I'll fix that.

@zhicwu Yeah, I want to use clickhouse-jdbc like below and then I can download all the dependencies's source code.

<dependency>
    <groupId>com.clickhouse</groupId>
    <artifactId>clickhouse-jdbc</artifactId>
    <version>0.4.0</version>
</dependency>

But it seems if I'm not use shaded jar, the io.grpc is also not shaded, then it raises an error.
I see you have copied the third-party code to io.grpc module, so why not put the source code in com.clickhouse package directly?Then they will not cause conflict error anymore.

@zhicwu
Copy link
Contributor

zhicwu commented Jan 29, 2023

I see. Let me explain:

  • com.clickhouse:io.grpc is required because we want to generate -all and -grpc shaded jar for clickhouse-jdbc, without creating any new module
  • grpc-java was repacked because the original lib does not support JPMS
  1. exclude unwanted dependencies
<dependency>
    <groupId>com.clickhouse</groupId>
    <artifactId>clickhouse-jdbc</artifactId>
    <version>0.4.0</version>
    <exclusions>
        <exclusion>
            <groupId>com.clickhouse</groupId>
            <artifactId>io.grpc</artifactId>
        </exclusion>
    </exclusions>
</dependency>
  1. use shaded jar with source - will fix in 0.4.1
<dependency>
    <groupId>com.clickhouse</groupId>
    <artifactId>clickhouse-jdbc</artifactId>
    <version>0.4.1</version>
    <classifier>http</classifier>
    <exclusions>
        <exclusion>
            <groupId>*</groupId>
            <artifactId>*</artifactId>
        </exclusion>
    </exclusions>
</dependency>

@zhicwu zhicwu linked a pull request Feb 1, 2023 that will close this issue
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants