mirror of
https://github.com/square/okhttp.git
synced 2025-08-08 23:42:08 +03:00
Create a friends configuration to use internals. (#8651)
* Create a friends configuration to use internals. From https://www.liutikas.net/2025/01/12/Kotlin-Library-Friends.html we should avoid using @file:Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE") So instead lets just be friends.
This commit is contained in:
@@ -60,13 +60,15 @@ android {
|
||||
dependencies {
|
||||
implementation(libs.kotlin.reflect)
|
||||
implementation(libs.playservices.safetynet)
|
||||
implementation(projects.okhttp)
|
||||
"friendsImplementation"(projects.okhttp)
|
||||
"friendsImplementation"(projects.okhttpDnsoverhttps)
|
||||
|
||||
testImplementation(projects.okhttp)
|
||||
testImplementation(libs.junit)
|
||||
testImplementation(libs.junit.ktx)
|
||||
testImplementation(libs.assertk)
|
||||
testImplementation(projects.okhttpTls)
|
||||
testImplementation(projects.loggingInterceptor)
|
||||
"friendsTestImplementation"(projects.loggingInterceptor)
|
||||
testImplementation(libs.androidx.test.runner)
|
||||
testImplementation(libs.robolectric)
|
||||
testImplementation(libs.androidx.espresso.core)
|
||||
|
@@ -10,6 +10,7 @@ import org.jetbrains.kotlin.gradle.dsl.JvmTarget
|
||||
import org.jetbrains.kotlin.gradle.dsl.kotlinExtension
|
||||
import org.jetbrains.kotlin.gradle.targets.jvm.tasks.KotlinJvmTest
|
||||
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
|
||||
import org.jetbrains.kotlin.gradle.utils.addExtendsFromRelation
|
||||
import ru.vyarus.gradle.plugin.animalsniffer.AnimalSnifferExtension
|
||||
import java.net.URI
|
||||
|
||||
@@ -286,6 +287,51 @@ subprojects {
|
||||
languageSettings.optIn("okhttp3.ExperimentalOkHttpApi")
|
||||
}
|
||||
}
|
||||
|
||||
// From https://www.liutikas.net/2025/01/12/Kotlin-Library-Friends.html
|
||||
|
||||
// Create configurations we can use to track friend libraries
|
||||
configurations {
|
||||
val friendsApi = register("friendsApi") {
|
||||
isCanBeResolved = true
|
||||
isCanBeConsumed = false
|
||||
isTransitive = true
|
||||
}
|
||||
val friendsImplementation = register("friendsImplementation") {
|
||||
isCanBeResolved = true
|
||||
isCanBeConsumed = false
|
||||
isTransitive = false
|
||||
}
|
||||
val friendsTestImplementation = register("friendsTestImplementation") {
|
||||
isCanBeResolved = true
|
||||
isCanBeConsumed = false
|
||||
isTransitive = false
|
||||
}
|
||||
configurations.configureEach {
|
||||
if (name == "implementation") {
|
||||
extendsFrom(friendsApi.get(), friendsImplementation.get())
|
||||
}
|
||||
if (name == "api") {
|
||||
extendsFrom(friendsApi.get())
|
||||
}
|
||||
if (name == "testImplementation") {
|
||||
extendsFrom(friendsTestImplementation.get())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Make these libraries friends :)
|
||||
tasks.withType<KotlinCompile>().configureEach {
|
||||
configurations.findByName("friendsApi")?.let {
|
||||
friendPaths.from(it.incoming.artifactView { }.files)
|
||||
}
|
||||
configurations.findByName("friendsImplementation")?.let {
|
||||
friendPaths.from(it.incoming.artifactView { }.files)
|
||||
}
|
||||
configurations.findByName("friendsTestImplementation")?.let {
|
||||
friendPaths.from(it.incoming.artifactView { }.files)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** Configure publishing and signing for published Java and JavaPlatform subprojects. */
|
||||
|
@@ -15,7 +15,7 @@ tasks.jar {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
api(projects.okhttp)
|
||||
"friendsApi"(projects.okhttp)
|
||||
api(projects.mockwebserver3)
|
||||
api(libs.junit)
|
||||
|
||||
|
@@ -13,7 +13,6 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
@file:Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
|
||||
|
||||
package okhttp3.mockwebserver
|
||||
|
||||
|
@@ -15,6 +15,7 @@ tasks.jar {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
api(projects.okhttp)
|
||||
api(projects.mockwebserver3)
|
||||
api(libs.junit)
|
||||
|
||||
|
@@ -21,6 +21,7 @@ tasks {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
api(projects.okhttp)
|
||||
api(projects.mockwebserver3)
|
||||
api(libs.junit.jupiter.api)
|
||||
compileOnly(libs.animalsniffer.annotations)
|
||||
|
@@ -15,7 +15,7 @@ tasks.jar {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
api(projects.okhttp)
|
||||
"friendsApi"(projects.okhttp)
|
||||
|
||||
testImplementation(projects.okhttpTestingSupport)
|
||||
testImplementation(projects.okhttpTls)
|
||||
|
@@ -13,7 +13,6 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
@file:Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
|
||||
|
||||
package mockwebserver3
|
||||
|
||||
|
@@ -14,7 +14,6 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
@file:Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
|
||||
|
||||
package mockwebserver3
|
||||
|
||||
|
@@ -13,7 +13,6 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
@file:Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
|
||||
|
||||
package mockwebserver3
|
||||
|
||||
|
@@ -15,7 +15,7 @@ project.applyOsgi(
|
||||
)
|
||||
|
||||
dependencies {
|
||||
api(projects.okhttp)
|
||||
"friendsApi"(projects.okhttp)
|
||||
compileOnly(libs.findbugs.jsr305)
|
||||
|
||||
testImplementation(projects.okhttpTestingSupport)
|
||||
|
@@ -208,17 +208,18 @@ class DnsOverHttps internal constructor(
|
||||
.apply {
|
||||
val query = DnsRecordCodec.encodeQuery(hostname, type)
|
||||
|
||||
val dnsUrl: HttpUrl = this@DnsOverHttps.url
|
||||
if (post) {
|
||||
url(url)
|
||||
url(dnsUrl)
|
||||
.cacheUrlOverride(
|
||||
url
|
||||
dnsUrl
|
||||
.newBuilder()
|
||||
.addQueryParameter("hostname", hostname)
|
||||
.build(),
|
||||
).post(query.toRequestBody(DNS_MESSAGE))
|
||||
} else {
|
||||
val encoded = query.base64Url().replace("=", "")
|
||||
val requestUrl = url.newBuilder().addQueryParameter("dns", encoded).build()
|
||||
val requestUrl = dnsUrl.newBuilder().addQueryParameter("dns", encoded).build()
|
||||
|
||||
url(requestUrl)
|
||||
}
|
||||
|
@@ -13,7 +13,6 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
@file:Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
|
||||
|
||||
package okhttp3.dnsoverhttps
|
||||
|
||||
|
@@ -15,7 +15,7 @@ project.applyOsgi(
|
||||
)
|
||||
|
||||
dependencies {
|
||||
api(projects.okhttp)
|
||||
"friendsApi"(projects.okhttp)
|
||||
compileOnly(libs.findbugs.jsr305)
|
||||
compileOnly(libs.animalsniffer.annotations)
|
||||
}
|
||||
|
@@ -13,7 +13,6 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
@file:Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
|
||||
|
||||
package okhttp3.java.net.cookiejar
|
||||
|
||||
|
@@ -15,7 +15,7 @@ project.applyOsgi(
|
||||
)
|
||||
|
||||
dependencies {
|
||||
api(projects.okhttp)
|
||||
"friendsApi"(projects.okhttp)
|
||||
compileOnly(libs.findbugs.jsr305)
|
||||
|
||||
testCompileOnly(libs.findbugs.jsr305)
|
||||
|
@@ -13,7 +13,6 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
@file:Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
|
||||
|
||||
package okhttp3.logging
|
||||
|
||||
|
@@ -922,7 +922,6 @@ class HttpLoggingInterceptorTest {
|
||||
.assertNoMoreLogs()
|
||||
}
|
||||
|
||||
@Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
|
||||
@Test
|
||||
fun sensitiveQueryParamsAreRedacted() {
|
||||
url = server.url("/api/login?user=test_user&authentication=basic&password=confidential_password")
|
||||
@@ -968,7 +967,6 @@ class HttpLoggingInterceptorTest {
|
||||
.assertNoMoreLogs()
|
||||
}
|
||||
|
||||
@Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
|
||||
@Test
|
||||
fun preserveQueryParamsAfterRedacted() {
|
||||
url =
|
||||
|
@@ -5,7 +5,7 @@ plugins {
|
||||
|
||||
dependencies {
|
||||
api(libs.squareup.okio)
|
||||
api(projects.okhttp)
|
||||
"friendsApi"(projects.okhttp)
|
||||
api(projects.okhttpTls)
|
||||
api(libs.assertk)
|
||||
api(libs.bouncycastle.bcprov)
|
||||
|
@@ -13,7 +13,6 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
@file:Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
|
||||
|
||||
package okhttp3
|
||||
|
||||
|
@@ -13,7 +13,6 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
@file:Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
|
||||
|
||||
package okhttp3
|
||||
|
||||
|
@@ -13,7 +13,6 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
@file:Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
|
||||
|
||||
package okhttp3
|
||||
|
||||
|
@@ -13,11 +13,6 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
@file:Suppress(
|
||||
"CANNOT_OVERRIDE_INVISIBLE_MEMBER",
|
||||
"INVISIBLE_MEMBER",
|
||||
"INVISIBLE_REFERENCE",
|
||||
)
|
||||
|
||||
package okhttp3
|
||||
|
||||
|
@@ -13,7 +13,6 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
@file:Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
|
||||
|
||||
package okhttp3.internal.concurrent
|
||||
|
||||
@@ -370,6 +369,8 @@ class TaskFaker : Closeable {
|
||||
val editCountBefore = editCount
|
||||
yieldUntil { nanoTime >= waitUntil || editCount > editCountBefore }
|
||||
}
|
||||
// TODO report compiler bug
|
||||
TODO("Can't get here")
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -13,7 +13,6 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
@file:Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
|
||||
|
||||
package okhttp3.internal.http
|
||||
|
||||
|
@@ -17,7 +17,7 @@ project.applyOsgi(
|
||||
|
||||
dependencies {
|
||||
api(libs.squareup.okio)
|
||||
implementation(projects.okhttp)
|
||||
"friendsImplementation"(projects.okhttp)
|
||||
compileOnly(libs.findbugs.jsr305)
|
||||
compileOnly(libs.animalsniffer.annotations)
|
||||
|
||||
|
@@ -13,7 +13,6 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
@file:Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
|
||||
|
||||
package okhttp3.tls
|
||||
|
||||
|
@@ -13,7 +13,6 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
@file:Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
|
||||
|
||||
package okhttp3.tls.internal
|
||||
|
||||
|
@@ -16,7 +16,7 @@ project.applyOsgi(
|
||||
)
|
||||
|
||||
dependencies {
|
||||
api(projects.okhttp)
|
||||
"friendsApi"(projects.okhttp)
|
||||
api(projects.okhttpJavaNetCookiejar)
|
||||
compileOnly(libs.findbugs.jsr305)
|
||||
compileOnly(libs.animalsniffer.annotations)
|
||||
|
@@ -13,7 +13,6 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
@file:Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
|
||||
|
||||
package okhttp3
|
||||
|
||||
|
@@ -4,7 +4,7 @@ plugins {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation(projects.okhttp)
|
||||
"friendsImplementation"(projects.okhttp)
|
||||
implementation(projects.mockwebserver)
|
||||
implementation(projects.okhttpTestingSupport)
|
||||
implementation(projects.okhttpTls)
|
||||
|
@@ -13,7 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
@file:Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE", "Since15")
|
||||
@file:Suppress("Since15")
|
||||
|
||||
package okhttp3.recipes.kt
|
||||
|
||||
|
@@ -13,7 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
@file:Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE", "Since15")
|
||||
@file:Suppress("Since15")
|
||||
|
||||
package okhttp3.recipes.kt
|
||||
|
||||
|
@@ -3,6 +3,7 @@ plugins {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation(projects.okhttp)
|
||||
implementation(projects.mockwebserver)
|
||||
implementation(libs.squareup.moshi)
|
||||
}
|
||||
|
@@ -14,6 +14,7 @@ tasks.jar {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation(projects.okhttp)
|
||||
implementation(projects.mockwebserver)
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user