Skip to content
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

Merged
merged 5 commits into from Feb 26, 2021
Merged

Conversation

anuraaga
Copy link
Contributor

@anuraaga anuraaga commented Feb 15, 2021

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

Copy link
Member

@szpak szpak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank for your PR! HttpBuilder, indeed, is somehow problematic. On 19 Mar 2017, I even created a task to do it, but it had to wait for you :).

I put some suggestions and I requested a build with e2e-test (with real Nexus instance) to check it in practice :).

Response intercept(@NotNull Interceptor.Chain chain) throws IOException {
Request.Builder request = chain.request().newBuilder()
.header("Content-Type", "application/json")
.header("Accept", "application/json")
Copy link
Member

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?

Copy link
Contributor Author

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

Copy link
Member

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?

@szpak szpak added this to the 0.30.0 milestone Feb 16, 2021
Copy link
Contributor Author

@anuraaga anuraaga left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, updated

Response intercept(@NotNull Interceptor.Chain chain) throws IOException {
Request.Builder request = chain.request().newBuilder()
.header("Content-Type", "application/json")
.header("Accept", "application/json")
Copy link
Contributor Author

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

Copy link
Member

@szpak szpak left a 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!

Response intercept(@NotNull Interceptor.Chain chain) throws IOException {
Request.Builder request = chain.request().newBuilder()
.header("Content-Type", "application/json")
.header("Accept", "application/json")
Copy link
Member

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?

@szpak
Copy link
Member

szpak commented Feb 18, 2021

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?

@anuraaga
Copy link
Contributor Author

@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.

@anuraaga
Copy link
Contributor Author

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

@szpak
Copy link
Member

szpak commented Feb 25, 2021

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 :-)

@szpak
Copy link
Member

szpak commented Feb 25, 2021

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 :)

Hopefully Gradle will not upgrade Kotlin to the incompatible version anytime soon :)

@szpak szpak merged commit 5c6ed29 into Codearte:master Feb 26, 2021
@szpak
Copy link
Member

szpak commented Feb 26, 2021

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Switch internal implementation to more developer friendly library
2 participants