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
Migrate HTTP client to okhttp. #188
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
src/main/groovy/io/codearte/gradle/nexus/infra/SimplifiedHttpJsonRestClient.groovy
Show resolved
Hide resolved
Response intercept(@NotNull Interceptor.Chain chain) throws IOException { | ||
Request.Builder request = chain.request().newBuilder() | ||
.header("Content-Type", "application/json") | ||
.header("Accept", "application/json") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there any ContentType-like class in OkHttp that could be used to get that "application/json" string?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately seems to only support parsing with no list of constants
https://square.github.io/okhttp/4.x/okhttp/okhttp3/-media-type/#companion-object-functions
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, in that case maybe just a constant String in that class?
src/main/groovy/io/codearte/gradle/nexus/infra/SimplifiedHttpJsonRestClient.groovy
Outdated
Show resolved
Hide resolved
src/main/groovy/io/codearte/gradle/nexus/infra/SimplifiedHttpJsonRestClient.groovy
Outdated
Show resolved
Hide resolved
src/main/groovy/io/codearte/gradle/nexus/infra/SimplifiedHttpJsonRestClient.groovy
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, updated
src/main/groovy/io/codearte/gradle/nexus/infra/SimplifiedHttpJsonRestClient.groovy
Show resolved
Hide resolved
Response intercept(@NotNull Interceptor.Chain chain) throws IOException { | ||
Request.Builder request = chain.request().newBuilder() | ||
.header("Content-Type", "application/json") | ||
.header("Accept", "application/json") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately seems to only support parsing with no list of constants
https://square.github.io/okhttp/4.x/okhttp/okhttp3/-media-type/#companion-object-functions
src/main/groovy/io/codearte/gradle/nexus/infra/SimplifiedHttpJsonRestClient.groovy
Outdated
Show resolved
Hide resolved
src/main/groovy/io/codearte/gradle/nexus/infra/SimplifiedHttpJsonRestClient.groovy
Outdated
Show resolved
Hide resolved
src/main/groovy/io/codearte/gradle/nexus/infra/SimplifiedHttpJsonRestClient.groovy
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will play with it with out e2e-test, but in general it look nice!
src/main/groovy/io/codearte/gradle/nexus/infra/SimplifiedHttpJsonRestClient.groovy
Show resolved
Hide resolved
Response intercept(@NotNull Interceptor.Chain chain) throws IOException { | ||
Request.Builder request = chain.request().newBuilder() | ||
.header("Content-Type", "application/json") | ||
.header("Accept", "application/json") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, in that case maybe just a constant String in that class?
Increased connection timeout helped e2e-test and I'm willing to merged it, but the other thing came into my mind. OkHttp seemed to be rewritten to Kotlin on the way. We would mix 3 languages in the project :). Do you have experience with the Kotlin dependencies? Should Kotlin (or even OkHttp and Kotlin) be shadowed? Or it should not be a problem and it could leave as is to make it easier to just override OkHttp (if needed) in the future, without having to release the new version of GNSP? |
@szpak That's an interesting point - okhttp 3.x is still a common dependency and pure Java which is why I use 3.x in most projects, but I picked 4.x here because Gradle mixes 3 languages already :) So Kotlin is already available for free I think and since it needs to be compatible for plugin authors anyways, I'm not too worried about shading. Shading okhttp is also an option, but in my experience they're great on not making backwards incompatible changes (I think they would change the package name when doing so) so I'd lean towards not worrying. |
Hi @szpak - I just found https://github.com/gradle-nexus/publish-plugin which seems to be the successor this plugin, and is already using okhttp. Should we go ahead and drop this PR? Or happy to let it merge if it's useful to anyone. I'm going to go ahead and give that plugin a go :D |
I'm happy that you proposed that change and I plan to merge it (soon) and release 0.40.0 right after that, probably the last release, unless there are some important bugs found. We created the new unified plugin to make it easier to release to Maven Central, which is important especially these days :). After checking if the new version of that plugin works fine for you, feel free to switch to the new plugin :-) |
Hopefully Gradle will not upgrade Kotlin to the incompatible version anytime soon :) |
I've just released 0.30.0, please let me know if it works in your project, before migrating to gradle-nexus-publish-plugin :-). Thanks for your contribution! |
When I try to use this plugin with
gradle-jib-plugin
, I get dependency conflicts due to the version of the Apache HTTP client. I tried several attempts to constrain versions to get something to work but couldn't. https://github.com/jgritman/httpbuilder hasn't been updated for 7 years so it's probably good to migrate off of it. I went with okhttp which is a very popular HTTP client.I haven't gotten to e2e test this yet on my end but sending for initial check. Thank you!
Fixes #42