diff --git a/library/src/main/kotlin/com/gabrielfeo/gradle/enterprise/api/Config.kt b/library/src/main/kotlin/com/gabrielfeo/gradle/enterprise/api/Config.kt index 8e5c7e8d..be1eca2b 100644 --- a/library/src/main/kotlin/com/gabrielfeo/gradle/enterprise/api/Config.kt +++ b/library/src/main/kotlin/com/gabrielfeo/gradle/enterprise/api/Config.kt @@ -37,15 +37,16 @@ data class Config( }, /** - * Provider of an [OkHttpClient.Builder] to use when building the library's internal client. - * Has a default value and shouldn't be needed in scripts. + * [OkHttpClient.Builder] to use when building the library's internal [OkHttpClient]. * - * This is aimed at using the library inside a full Kotlin project. Allows the internal client to - * share resources such as thread pools with another [OkHttpClient], useful for full Kotlin projects - * and rarely needed for scripting. See [OkHttpClient] for all that is shared. + * This is aimed at using the library inside a full Kotlin project. Allows the internal client + * to share resources such as thread pools with another [OkHttpClient]. See [OkHttpClient] + * for all that is shared. + * + * The default is to share resources only within the library, i.e. multiple `Config()` with + * the default [clientBuilder] will already share resources. */ - val clientBuilder: OkHttpClient.Builder = - OkHttpClient.Builder(), + val clientBuilder: OkHttpClient.Builder = basicOkHttpClient.newBuilder(), /** * Maximum amount of concurrent requests allowed. Further requests will be queued. By default, diff --git a/library/src/main/kotlin/com/gabrielfeo/gradle/enterprise/api/internal/OkHttpClient.kt b/library/src/main/kotlin/com/gabrielfeo/gradle/enterprise/api/internal/OkHttpClient.kt index 5e96bfbe..84dfc855 100644 --- a/library/src/main/kotlin/com/gabrielfeo/gradle/enterprise/api/internal/OkHttpClient.kt +++ b/library/src/main/kotlin/com/gabrielfeo/gradle/enterprise/api/internal/OkHttpClient.kt @@ -12,6 +12,16 @@ import java.time.Duration import java.util.logging.Level import java.util.logging.Logger +/** + * Base instance just so that multiple created [Config]s will share resources by default. + */ +internal val basicOkHttpClient by lazy { + OkHttpClient.Builder().build() +} + +/** + * Builds the final `OkHttpClient` with a `Config`. + */ internal fun buildOkHttpClient( config: Config, ) = with(config.clientBuilder) {