diff --git a/buildSrc/build.gradle.kts b/buildSrc/build.gradle.kts index b0b098c84..a241cc8c5 100644 --- a/buildSrc/build.gradle.kts +++ b/buildSrc/build.gradle.kts @@ -19,4 +19,8 @@ dependencies { tasks.test { useJUnitPlatform() + workingDir(layout.projectDirectory) + inputs + .file(layout.projectDirectory.file("../scripts/detect-breaking-changes")) + .withPathSensitivity(PathSensitivity.RELATIVE) } diff --git a/buildSrc/src/test/kotlin/com/openai/gradle/ApiCompatibilityCachePolicyTest.kt b/buildSrc/src/test/kotlin/com/openai/gradle/ApiCompatibilityCachePolicyTest.kt new file mode 100644 index 000000000..f3de36c55 --- /dev/null +++ b/buildSrc/src/test/kotlin/com/openai/gradle/ApiCompatibilityCachePolicyTest.kt @@ -0,0 +1,24 @@ +package com.openai.gradle + +import java.nio.file.Path +import kotlin.io.path.readText +import kotlin.test.Test +import kotlin.test.assertContains +import kotlin.test.assertFalse + +class ApiCompatibilityCachePolicyTest { + @Test + fun `compatibility compilation always executes while production caching stays enabled`() { + val detector = Path.of("../scripts/detect-breaking-changes").readText() + + assertFalse( + detector.contains("--no-build-cache"), + "The API compatibility detector must leave the build cache enabled for production compilation.", + ) + assertContains(detector, "compileExternalApiCompatibilityKotlin") + assertContains(detector, "compileProposedApiCompatibilityKotlin") + assertContains(detector, "project.tasks.named(taskName).configure") + assertContains(detector, "task.outputs.upToDateWhen { false }") + assertContains(detector, "task.outputs.doNotCacheIf") + } +} diff --git a/scripts/detect-breaking-changes b/scripts/detect-breaking-changes index db524948e..f08f17f26 100755 --- a/scripts/detect-breaking-changes +++ b/scripts/detect-breaking-changes @@ -291,6 +291,18 @@ gradle.beforeProject { project -> System.getenv("PROPOSED_FIXTURE_SOURCE_ROOT"), System.getenv("PROPOSED_DEPENDENCIES_FILE") ) + + [ + "compileExternalApiCompatibilityKotlin", + "compileProposedApiCompatibilityKotlin" + ].each { taskName -> + project.tasks.named(taskName).configure { task -> + task.outputs.upToDateWhen { false } + task.outputs.doNotCacheIf( + "API compatibility compilation must always execute" + ) { true } + } + } } } } @@ -305,8 +317,7 @@ GENERATED_TEST_SOURCE_ROOT="${GENERATED_TEST_SOURCE_ROOT}" \ ./scripts/gradle \ --init-script "${COMPATIBILITY_INIT_SCRIPT}" \ :openai-java-core:compileExternalApiCompatibilityKotlin \ - :openai-java-core:compileProposedApiCompatibilityKotlin \ - --no-build-cache + :openai-java-core:compileProposedApiCompatibilityKotlin validate_public_api_signatures() { local manifest_path="$1"