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..0f7c5a3b 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 @@ -44,8 +44,7 @@ data class Config( * 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. */ - 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) {