-
Notifications
You must be signed in to change notification settings - Fork 9.1k
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
Add constant OkHttp.VERSION #5981
Conversation
By "Java package implementation version" I meant whether the right fix is to make sure this works
And not have a new Version class |
I'm not sure to understand 😅 |
Yep, rather than new API, maybe it's better to expose the version number using existing mechanics. https://docs.oracle.com/javase/tutorial/deployment/jar/packageman.html Anyway, I'll let others weigh in. I wouldn't change yet. The danger of this new API is it encourages people to use it, which we may not want to encourage. |
Okay, I see 👍 |
Was hoping it was this simple in the build.gradle for okhttp jar, but not working.
So maybe this PR is the right approach? |
I'm not sold on just exposing this previously internal method as public API. For example the Conscrypt version as a public API is usable. https://github.com/google/conscrypt/blob/ce2fbf2d740437655c7774c4c0cd3c3f8ee159f9/common/src/main/java/org/conscrypt/Conscrypt.java#L58
n.b. I think JAR versioning is broken in Android
|
Shall we create a version constant? We can say that we do semver and sufficiently motivated callers can use the Maven rules to parse it.
|
Are there any subtleties to that? If we just change the @ filename annotation in a Version.kt file, does that grab this top level file class forever? |
Or maybe the file name is My preference is we document the version being strictly confirmant to semver 2.0.0. We will need to be careful to avoid version names where Maven and Semver disagree. |
For anyone following along curious about where Maven and Semver disagree on order: |
@Kevinrob Thanks for your patience on this, does this version field suit your needs? Care to update the PR? |
98b204b
to
2919d6e
Compare
@yschimke Yes. I updated the PR with @swankjesse proposition 👍 |
Version
from package okhttp3.internal to okhttp3
Looks good, I think it's worth a test because of the build dependency. Would you add a single test for this, starts with "4." Or whatever you think makes sense. |
|
@Test | ||
fun testVersion() { | ||
val semVerRegex = Regex("^[0-9]+\\.[0-9]+\\.[0-9]+(-.+)?$") | ||
assert(semVerRegex.matches(VERSION)) |
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.
instead of java assertions, can you replace with assertj?
import org.assertj.core.api.Assertions.assertThat
...
assertThat(VERSION).matches("[0-9]+\\.[0-9]+\\.[0-9]+(-.+)?")
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.
Yes, changed ✔
@Kevinrob sorry for being finicky, and thanks for working through this. |
@yschimke No problem 🙂 |
Thank you @yschimke for merging this PR! |
If it's a clear improvement to the code, but not if it's just to appease a lint rule/warning that we don't generally agree with. We don't actively sprinkle code with annotations to appease Intellij. |
Related to issue #5969
Since OkHttp 4.0.0, the okhttp3.internal package is not a published API.
It's impossible to get default userAgent without access to this.
As @yschimke suggest, we can move
Version
from packageokhttp3.internal
tookhttp3
.