diff --git a/build-logic/src/main/kotlin/Osgi.kt b/build-logic/src/main/kotlin/Osgi.kt index 18869a86c120..1066b33507fd 100644 --- a/build-logic/src/main/kotlin/Osgi.kt +++ b/build-logic/src/main/kotlin/Osgi.kt @@ -28,11 +28,10 @@ import org.gradle.kotlin.dsl.findByType import org.gradle.kotlin.dsl.get import org.gradle.kotlin.dsl.getByName import org.gradle.kotlin.dsl.named +import org.gradle.kotlin.dsl.provideDelegate fun Project.applyOsgi(vararg bndProperties: String) { - plugins.withId("org.jetbrains.kotlin.jvm") { - applyOsgi("jar", "osgiApi", bndProperties) - } + plugins.withId("org.jetbrains.kotlin.jvm") { applyOsgi("jar", "osgiApi", bndProperties) } } private fun Project.applyOsgi( @@ -43,24 +42,29 @@ private fun Project.applyOsgi( val osgi = project.sourceSets.create("osgi") val osgiApi = project.configurations.getByName(osgiApiConfigurationName) - project.dependencies { - osgiApi(kotlinOsgi) - } + project.dependencies { osgiApi(kotlinOsgi) } val jarTask = tasks.getByName(jarTaskName) val bundleExtension = - jarTask.extensions.findByType() ?: jarTask.extensions.create( - BundleTaskExtension.NAME, - BundleTaskExtension::class.java, - jarTask, - ) + jarTask.extensions.findByType() + ?: jarTask.extensions.create( + BundleTaskExtension.NAME, + BundleTaskExtension::class.java, + jarTask, + ) bundleExtension.run { setClasspath(osgi.compileClasspath + sourceSets["main"].compileClasspath) bnd(*bndProperties) } // Call the convention when the task has finished, to modify the jar to contain OSGi metadata. - jarTask.doLast { - bundleExtension.buildAction().execute(this) + val okhttpForceConfigurationCache: String by project + if (!okhttpForceConfigurationCache.toBoolean()) { + val buildAction = bundleExtension.buildAction() + jarTask.doLast { buildAction.execute(this) } + } else { + logger.warn( + "Skipping OSGi metadata generation for ${jarTask.name} because configuration caching is enabled and BND is not compatible.", + ) } } @@ -100,16 +104,11 @@ fun Project.applyOsgiMultiplatform(vararg bndProperties: String) { target: String?, ) = "${jvmMainSourceSet.getTaskName(verb, target)}ForFakeMain" } - extensions - .getByType(JavaPluginExtension::class.java) - .sourceSets - .add(mainSourceSet) + extensions.getByType(JavaPluginExtension::class.java).sourceSets.add(mainSourceSet) tasks.named { it.endsWith("ForFakeMain") }.configureEach { onlyIf { false } } val osgiApi = configurations.create("osgiApi") - dependencies { - osgiApi(kotlinOsgi) - } + dependencies { osgiApi(kotlinOsgi) } // Call the convention when the task has finished, to modify the jar to contain OSGi metadata. tasks.named("jvmJar").configure { @@ -120,12 +119,21 @@ fun Project.applyOsgiMultiplatform(vararg bndProperties: String) { BundleTaskExtension::class.java, this, ).apply { - classpath(osgiApi.artifacts) + val osgiApiArtifacts = osgiApi.artifacts + classpath(osgiApiArtifacts) classpath(tasks.named("jvmMainClasses").map { it.outputs }) bnd(*bndProperties) } - doLast { - bundleExtension.buildAction().execute(this) + val okhttpForceConfigurationCache: String by project + if (!okhttpForceConfigurationCache.toBoolean()) { + val buildAction = bundleExtension.buildAction() + doLast { buildAction.execute(this) } + } else { + // Configuration caching is enabled, and BND's buildAction is not compatible. + // We skip OSGi metadata generation for now when configuration caching is enabled. + logger.warn( + "Skipping OSGi metadata generation for :okhttp:jvmJar because configuration caching is enabled and BND is not compatible.", + ) } } } diff --git a/build-logic/src/main/kotlin/okhttp.base-conventions.gradle.kts b/build-logic/src/main/kotlin/okhttp.base-conventions.gradle.kts index 2c7c3a7bf517..5bdff2c6f2da 100644 --- a/build-logic/src/main/kotlin/okhttp.base-conventions.gradle.kts +++ b/build-logic/src/main/kotlin/okhttp.base-conventions.gradle.kts @@ -48,13 +48,12 @@ tasks.withType().configureEach { friendPaths.from(friendsTestImplementation.incoming.artifactView { }.files) } +val resolvableConfigurations = configurations.filter { it.isCanBeResolved } tasks.register("downloadDependencies") { description = "Download all dependencies to the Gradle cache" doLast { - for (configuration in configurations) { - if (configuration.isCanBeResolved) { - configuration.files - } + for (configuration in resolvableConfigurations) { + configuration.files } } } diff --git a/build-logic/src/main/kotlin/okhttp3/buildsupport/OkHttpBuildUtils.kt b/build-logic/src/main/kotlin/okhttp3/buildsupport/OkHttpBuildUtils.kt index d78cd0551e9b..3ae040629f8e 100644 --- a/build-logic/src/main/kotlin/okhttp3/buildsupport/OkHttpBuildUtils.kt +++ b/build-logic/src/main/kotlin/okhttp3/buildsupport/OkHttpBuildUtils.kt @@ -3,13 +3,13 @@ package okhttp3.buildsupport import org.gradle.api.Project val Project.platform: String - get() = findProperty("okhttp.platform")?.toString() ?: "jdk9" + get() = findProperty("okhttp.platform")?.toString() ?: "jdk9" val Project.testJavaVersion: Int - get() = findProperty("test.java.version")?.toString()?.toInt() ?: 21 + get() = findProperty("test.java.version")?.toString()?.toInt() ?: 21 val Project.androidBuild: Boolean - get() = findProperty("androidBuild")?.toString()?.toBoolean() ?: false + get() = findProperty("androidBuild")?.toString()?.toBoolean() ?: false val Project.alpnBootVersion: String? - get() = findProperty("alpn.boot.version")?.toString() + get() = findProperty("alpn.boot.version")?.toString() diff --git a/gradle.properties b/gradle.properties index 5ee973826ad9..9f7d385a24e5 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,6 +1,9 @@ org.gradle.caching=true org.gradle.parallel=true +# Blocked on BND +org.gradle.configuration-cache=false + android.useAndroidX=true kotlin.mpp.applyDefaultHierarchyTemplate=false @@ -11,6 +14,9 @@ containerTests=false okhttpModuleTests=false okhttpDokka=false +# When true BND is disabled to allow testing configuration-cache +okhttpForceConfigurationCache=false + org.gradle.jvmargs='-Dfile.encoding=UTF-8' # AGP 9.0 Settings diff --git a/okhttp-osgi-tests/build.gradle.kts b/okhttp-osgi-tests/build.gradle.kts index 0e58640655e5..94a7af0822e9 100644 --- a/okhttp-osgi-tests/build.gradle.kts +++ b/okhttp-osgi-tests/build.gradle.kts @@ -67,9 +67,13 @@ dependencies { } val testJavaVersion = project.testJavaVersion +val okhttpForceConfigurationCache: String by project tasks.withType { dependsOn(copyOsgiTestDeployment) onlyIf("Tests require JDK 17") { testJavaVersion >= 17 } + onlyIf("OSGi tests are incompatible with configuration cache due to BND limitations") { + !okhttpForceConfigurationCache.toBoolean() + } } diff --git a/okhttp/build.gradle.kts b/okhttp/build.gradle.kts index 97f8cd55938f..afa384d9304b 100644 --- a/okhttp/build.gradle.kts +++ b/okhttp/build.gradle.kts @@ -30,8 +30,7 @@ val copyKotlinTemplates = filteringCharset = Charsets.UTF_8.toString() expand( - // Build & use okhttp3/internal/-InternalVersion.kt - "projectVersion" to project.version, + "projectVersion" to project.version.toString(), ) } @@ -284,7 +283,7 @@ tasks.named("jvmJar").configure { ) } - from(compileJavaModuleInfo.get().destinationDirectory) { + from(compileJavaModuleInfo.map { it.destinationDirectory }) { into("META-INF/versions/9/") } }