1
0
mirror of https://github.com/square/okhttp.git synced 2025-08-07 12:42:57 +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:
Yuri Schimke
2025-05-10 12:15:14 +01:00
committed by GitHub
parent 889bb7b009
commit f2640e0b08
35 changed files with 71 additions and 38 deletions

View File

@@ -60,13 +60,15 @@ android {
dependencies { dependencies {
implementation(libs.kotlin.reflect) implementation(libs.kotlin.reflect)
implementation(libs.playservices.safetynet) implementation(libs.playservices.safetynet)
implementation(projects.okhttp) "friendsImplementation"(projects.okhttp)
"friendsImplementation"(projects.okhttpDnsoverhttps)
testImplementation(projects.okhttp)
testImplementation(libs.junit) testImplementation(libs.junit)
testImplementation(libs.junit.ktx) testImplementation(libs.junit.ktx)
testImplementation(libs.assertk) testImplementation(libs.assertk)
testImplementation(projects.okhttpTls) testImplementation(projects.okhttpTls)
testImplementation(projects.loggingInterceptor) "friendsTestImplementation"(projects.loggingInterceptor)
testImplementation(libs.androidx.test.runner) testImplementation(libs.androidx.test.runner)
testImplementation(libs.robolectric) testImplementation(libs.robolectric)
testImplementation(libs.androidx.espresso.core) testImplementation(libs.androidx.espresso.core)

View File

@@ -10,6 +10,7 @@ import org.jetbrains.kotlin.gradle.dsl.JvmTarget
import org.jetbrains.kotlin.gradle.dsl.kotlinExtension import org.jetbrains.kotlin.gradle.dsl.kotlinExtension
import org.jetbrains.kotlin.gradle.targets.jvm.tasks.KotlinJvmTest import org.jetbrains.kotlin.gradle.targets.jvm.tasks.KotlinJvmTest
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import org.jetbrains.kotlin.gradle.utils.addExtendsFromRelation
import ru.vyarus.gradle.plugin.animalsniffer.AnimalSnifferExtension import ru.vyarus.gradle.plugin.animalsniffer.AnimalSnifferExtension
import java.net.URI import java.net.URI
@@ -286,6 +287,51 @@ subprojects {
languageSettings.optIn("okhttp3.ExperimentalOkHttpApi") 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. */ /** Configure publishing and signing for published Java and JavaPlatform subprojects. */

View File

@@ -15,7 +15,7 @@ tasks.jar {
} }
dependencies { dependencies {
api(projects.okhttp) "friendsApi"(projects.okhttp)
api(projects.mockwebserver3) api(projects.mockwebserver3)
api(libs.junit) api(libs.junit)

View File

@@ -13,7 +13,6 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
@file:Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
package okhttp3.mockwebserver package okhttp3.mockwebserver

View File

@@ -15,6 +15,7 @@ tasks.jar {
} }
dependencies { dependencies {
api(projects.okhttp)
api(projects.mockwebserver3) api(projects.mockwebserver3)
api(libs.junit) api(libs.junit)

View File

@@ -21,6 +21,7 @@ tasks {
} }
dependencies { dependencies {
api(projects.okhttp)
api(projects.mockwebserver3) api(projects.mockwebserver3)
api(libs.junit.jupiter.api) api(libs.junit.jupiter.api)
compileOnly(libs.animalsniffer.annotations) compileOnly(libs.animalsniffer.annotations)

View File

@@ -15,7 +15,7 @@ tasks.jar {
} }
dependencies { dependencies {
api(projects.okhttp) "friendsApi"(projects.okhttp)
testImplementation(projects.okhttpTestingSupport) testImplementation(projects.okhttpTestingSupport)
testImplementation(projects.okhttpTls) testImplementation(projects.okhttpTls)

View File

@@ -13,7 +13,6 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
@file:Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
package mockwebserver3 package mockwebserver3

View File

@@ -14,7 +14,6 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
@file:Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
package mockwebserver3 package mockwebserver3

View File

@@ -13,7 +13,6 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
@file:Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
package mockwebserver3 package mockwebserver3

View File

@@ -15,7 +15,7 @@ project.applyOsgi(
) )
dependencies { dependencies {
api(projects.okhttp) "friendsApi"(projects.okhttp)
compileOnly(libs.findbugs.jsr305) compileOnly(libs.findbugs.jsr305)
testImplementation(projects.okhttpTestingSupport) testImplementation(projects.okhttpTestingSupport)

View File

@@ -208,17 +208,18 @@ class DnsOverHttps internal constructor(
.apply { .apply {
val query = DnsRecordCodec.encodeQuery(hostname, type) val query = DnsRecordCodec.encodeQuery(hostname, type)
val dnsUrl: HttpUrl = this@DnsOverHttps.url
if (post) { if (post) {
url(url) url(dnsUrl)
.cacheUrlOverride( .cacheUrlOverride(
url dnsUrl
.newBuilder() .newBuilder()
.addQueryParameter("hostname", hostname) .addQueryParameter("hostname", hostname)
.build(), .build(),
).post(query.toRequestBody(DNS_MESSAGE)) ).post(query.toRequestBody(DNS_MESSAGE))
} else { } else {
val encoded = query.base64Url().replace("=", "") val encoded = query.base64Url().replace("=", "")
val requestUrl = url.newBuilder().addQueryParameter("dns", encoded).build() val requestUrl = dnsUrl.newBuilder().addQueryParameter("dns", encoded).build()
url(requestUrl) url(requestUrl)
} }

View File

@@ -13,7 +13,6 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
@file:Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
package okhttp3.dnsoverhttps package okhttp3.dnsoverhttps

View File

@@ -15,7 +15,7 @@ project.applyOsgi(
) )
dependencies { dependencies {
api(projects.okhttp) "friendsApi"(projects.okhttp)
compileOnly(libs.findbugs.jsr305) compileOnly(libs.findbugs.jsr305)
compileOnly(libs.animalsniffer.annotations) compileOnly(libs.animalsniffer.annotations)
} }

View File

@@ -13,7 +13,6 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
@file:Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
package okhttp3.java.net.cookiejar package okhttp3.java.net.cookiejar

View File

@@ -15,7 +15,7 @@ project.applyOsgi(
) )
dependencies { dependencies {
api(projects.okhttp) "friendsApi"(projects.okhttp)
compileOnly(libs.findbugs.jsr305) compileOnly(libs.findbugs.jsr305)
testCompileOnly(libs.findbugs.jsr305) testCompileOnly(libs.findbugs.jsr305)

View File

@@ -13,7 +13,6 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
@file:Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
package okhttp3.logging package okhttp3.logging

View File

@@ -922,7 +922,6 @@ class HttpLoggingInterceptorTest {
.assertNoMoreLogs() .assertNoMoreLogs()
} }
@Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
@Test @Test
fun sensitiveQueryParamsAreRedacted() { fun sensitiveQueryParamsAreRedacted() {
url = server.url("/api/login?user=test_user&authentication=basic&password=confidential_password") url = server.url("/api/login?user=test_user&authentication=basic&password=confidential_password")
@@ -968,7 +967,6 @@ class HttpLoggingInterceptorTest {
.assertNoMoreLogs() .assertNoMoreLogs()
} }
@Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
@Test @Test
fun preserveQueryParamsAfterRedacted() { fun preserveQueryParamsAfterRedacted() {
url = url =

View File

@@ -5,7 +5,7 @@ plugins {
dependencies { dependencies {
api(libs.squareup.okio) api(libs.squareup.okio)
api(projects.okhttp) "friendsApi"(projects.okhttp)
api(projects.okhttpTls) api(projects.okhttpTls)
api(libs.assertk) api(libs.assertk)
api(libs.bouncycastle.bcprov) api(libs.bouncycastle.bcprov)

View File

@@ -13,7 +13,6 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
@file:Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
package okhttp3 package okhttp3

View File

@@ -13,7 +13,6 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
@file:Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
package okhttp3 package okhttp3

View File

@@ -13,7 +13,6 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
@file:Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
package okhttp3 package okhttp3

View File

@@ -13,11 +13,6 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
@file:Suppress(
"CANNOT_OVERRIDE_INVISIBLE_MEMBER",
"INVISIBLE_MEMBER",
"INVISIBLE_REFERENCE",
)
package okhttp3 package okhttp3

View File

@@ -13,7 +13,6 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
@file:Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
package okhttp3.internal.concurrent package okhttp3.internal.concurrent
@@ -370,6 +369,8 @@ class TaskFaker : Closeable {
val editCountBefore = editCount val editCountBefore = editCount
yieldUntil { nanoTime >= waitUntil || editCount > editCountBefore } yieldUntil { nanoTime >= waitUntil || editCount > editCountBefore }
} }
// TODO report compiler bug
TODO("Can't get here")
} }
} }

View File

@@ -13,7 +13,6 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
@file:Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
package okhttp3.internal.http package okhttp3.internal.http

View File

@@ -17,7 +17,7 @@ project.applyOsgi(
dependencies { dependencies {
api(libs.squareup.okio) api(libs.squareup.okio)
implementation(projects.okhttp) "friendsImplementation"(projects.okhttp)
compileOnly(libs.findbugs.jsr305) compileOnly(libs.findbugs.jsr305)
compileOnly(libs.animalsniffer.annotations) compileOnly(libs.animalsniffer.annotations)

View File

@@ -13,7 +13,6 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
@file:Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
package okhttp3.tls package okhttp3.tls

View File

@@ -13,7 +13,6 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
@file:Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
package okhttp3.tls.internal package okhttp3.tls.internal

View File

@@ -16,7 +16,7 @@ project.applyOsgi(
) )
dependencies { dependencies {
api(projects.okhttp) "friendsApi"(projects.okhttp)
api(projects.okhttpJavaNetCookiejar) api(projects.okhttpJavaNetCookiejar)
compileOnly(libs.findbugs.jsr305) compileOnly(libs.findbugs.jsr305)
compileOnly(libs.animalsniffer.annotations) compileOnly(libs.animalsniffer.annotations)

View File

@@ -13,7 +13,6 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
@file:Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
package okhttp3 package okhttp3

View File

@@ -4,7 +4,7 @@ plugins {
} }
dependencies { dependencies {
implementation(projects.okhttp) "friendsImplementation"(projects.okhttp)
implementation(projects.mockwebserver) implementation(projects.mockwebserver)
implementation(projects.okhttpTestingSupport) implementation(projects.okhttpTestingSupport)
implementation(projects.okhttpTls) implementation(projects.okhttpTls)

View File

@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
@file:Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE", "Since15") @file:Suppress("Since15")
package okhttp3.recipes.kt package okhttp3.recipes.kt

View File

@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
@file:Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE", "Since15") @file:Suppress("Since15")
package okhttp3.recipes.kt package okhttp3.recipes.kt

View File

@@ -3,6 +3,7 @@ plugins {
} }
dependencies { dependencies {
implementation(projects.okhttp)
implementation(projects.mockwebserver) implementation(projects.mockwebserver)
implementation(libs.squareup.moshi) implementation(libs.squareup.moshi)
} }

View File

@@ -14,6 +14,7 @@ tasks.jar {
} }
dependencies { dependencies {
implementation(projects.okhttp)
implementation(projects.mockwebserver) implementation(projects.mockwebserver)
} }