Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ import com.ncorti.ktfmt.gradle.KtfmtExtension
import com.vanniktech.maven.publish.AndroidSingleVariantLibrary
import com.vanniktech.maven.publish.MavenPublishBaseExtension
import kotlinx.validation.ApiValidationExtension
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import org.jetbrains.kotlin.gradle.dsl.KotlinAndroidExtension

println("Building with Kotlin compiler version ${libs.versions.kotlin.get()}")

Expand Down Expand Up @@ -106,14 +105,17 @@ subprojects {
}
}

tasks.withType<KotlinCompile> {
compilerOptions {
// Allow warnings when running from IDE, makes it easier to experiment.
if (!isRunningFromIde) {
allWarningsAsErrors.set(true)
// AGP's built-in Kotlin registers the `kotlin` extension for every Android module.
// jvmTarget is not set here: with built-in Kotlin it defaults to each module's
// android.compileOptions.targetCompatibility.
plugins.withId("com.android.base") {
configure<KotlinAndroidExtension> {
compilerOptions {
// Allow warnings when running from IDE, makes it easier to experiment.
if (!isRunningFromIde) {
allWarningsAsErrors.set(true)
}
}

jvmTarget.set(JvmTarget.JVM_1_8)
}
}
}
11 changes: 1 addition & 10 deletions compose-tests/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
id("com.android.library")
kotlin("android")
id("org.jetbrains.kotlin.plugin.compose")
}

Expand Down Expand Up @@ -32,12 +28,7 @@ android {
testNamespace = "com.squareup.radiography.test.compose"
}

tasks.withType<KotlinCompile> {
compilerOptions {
jvmTarget.set(JvmTarget.JVM_11)
freeCompilerArgs.addAll("-opt-in=kotlin.RequiresOptIn")
}
}
kotlin { compilerOptions { freeCompilerArgs.add("-opt-in=kotlin.RequiresOptIn") } }

dependencies {
androidTestImplementation(project(":radiography"))
Expand Down
11 changes: 1 addition & 10 deletions compose-unsupported-tests/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
id("com.android.library")
kotlin("android")
id("org.jetbrains.kotlin.plugin.compose")
}

Expand Down Expand Up @@ -32,12 +28,7 @@ android {
testNamespace = "com.squareup.radiography.test.compose.unsupported"
}

tasks.withType<KotlinCompile> {
compilerOptions {
jvmTarget.set(JvmTarget.JVM_11)
freeCompilerArgs.addAll("-opt-in=kotlin.RequiresOptIn")
}
}
kotlin { compilerOptions { freeCompilerArgs.add("-opt-in=kotlin.RequiresOptIn") } }

dependencies {
androidTestImplementation(project(":radiography"))
Expand Down
4 changes: 0 additions & 4 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,3 @@ POM_LICENCE_DIST=repo

POM_DEVELOPER_ID=square
POM_DEVELOPER_NAME=Square, Inc.

# AGP 9 enables built-in Kotlin by default; keep using the standalone Kotlin Gradle plugin for now.
android.builtInKotlin=false
android.newDsl=false
72 changes: 56 additions & 16 deletions radiography/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import kotlinx.validation.KotlinApiBuildTask
import kotlinx.validation.KotlinApiCompareTask
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
id("com.android.library")
kotlin("android")
id("com.vanniktech.maven.publish.base")
}

Expand All @@ -44,25 +45,64 @@ android {
testNamespace = "com.squareup.radiography.test"
}

tasks.withType<KotlinCompile> {
compilerOptions {
freeCompilerArgs.addAll(
listOfNotNull(
"-opt-in=kotlin.RequiresOptIn",

// Require explicit public modifiers and types.
// TODO this should be moved to a top-level `kotlin { explicitApi() }` once that's working
// for android projects, see https://youtrack.jetbrains.com/issue/KT-37652.
"-Xexplicit-api=strict"
.takeUnless {
// Tests aren't part of the public API, don't turn explicit API mode on for them.
name.contains("test", ignoreCase = true)
},
)
kotlin {
// Require explicit public modifiers and types. AGP's built-in Kotlin only applies this to
// production sources; tests aren't part of the public API.
explicitApi()

compilerOptions { freeCompilerArgs.add("-opt-in=kotlin.RequiresOptIn") }
}

// The binary-compatibility-validator plugin (applied in the root build script) only configures
// Android modules when the standalone org.jetbrains.kotlin.android plugin is applied, which AGP's
// built-in Kotlin support replaces. Until BCV (or KGP's own abiValidation) supports built-in
// Kotlin, reproduce BCV's kotlin-android wiring here using its public task types: apiBuild dumps
// the public API of the release compilation, apiCheck compares it with api/radiography.api, and
// apiDump updates that file.
val apiDir = layout.projectDirectory.dir("api")
val apiFileName = "${project.name}.api"

// BCV only adds kotlin-metadata-jvm to its worker classpath when it sees a Kotlin plugin id.
dependencies.add(
"bcv-rt-jvm-cp",
"org.jetbrains.kotlin:kotlin-metadata-jvm:${libs.versions.kotlin.get()}",
)

val apiBuild =
tasks.register<KotlinApiBuildTask>("apiBuild") {
description = "Builds Kotlin API for the release compilation of ${project.name}."
// AGP's compilations don't populate output.classesDirs, so read the compile tasks' outputs.
inputClassesDirs.from(
tasks.named<KotlinCompile>("compileReleaseKotlin").flatMap { it.destinationDirectory },
tasks.named<JavaCompile>("compileReleaseJavaWithJavac").flatMap { it.destinationDirectory },
)
inputDependencies.from(
kotlin.target.compilations.named("release").map { it.compileDependencyFiles }
)
outputApiFile.set(layout.buildDirectory.file("api/$apiFileName"))
runtimeClasspath.from(configurations.named("bcv-rt-jvm-cp-resolver"))
}

val apiCheck =
tasks.register<KotlinApiCompareTask>("apiCheck") {
group = "verification"
description =
"Checks signatures of public API against the golden value in API folder for ${project.name}"
projectApiFile.set(apiDir.file(apiFileName))
generatedApiFile.set(apiBuild.flatMap { it.outputApiFile })
}

tasks.register("apiDump") {
description = "Syncs the API file for ${project.name}"
val from = apiBuild.flatMap { it.outputApiFile }
val to = apiDir.file(apiFileName)
inputs.file(from)
outputs.file(to)
doLast { from.get().asFile.copyTo(to.asFile, overwrite = true) }
}

tasks.named("check") { dependsOn(apiCheck) }

dependencies {
implementation(libs.curtains)
// We don't want to bring any Compose dependencies in unless the consumer of this library is
Expand Down
11 changes: 1 addition & 10 deletions sample-compose/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
id("com.android.application")
kotlin("android")
id("org.jetbrains.kotlin.plugin.compose")
}

Expand All @@ -29,12 +25,7 @@ android {
testNamespace = "com.squareup.radiography.sample.compose.test"
}

tasks.withType<KotlinCompile> {
compilerOptions {
jvmTarget.set(JvmTarget.JVM_1_8)
freeCompilerArgs.addAll("-opt-in=kotlin.RequiresOptIn")
}
}
kotlin { compilerOptions { freeCompilerArgs.add("-opt-in=kotlin.RequiresOptIn") } }

dependencies {
implementation(project(":radiography"))
Expand Down
5 changes: 1 addition & 4 deletions sample/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@
* limitations under the License.
*/

plugins {
id("com.android.application")
kotlin("android")
}
plugins { id("com.android.application") }

android {
compileSdk = 35
Expand Down
6 changes: 1 addition & 5 deletions stoic-plugin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
plugins {
id("com.android.application")
kotlin("android")
}
plugins { id("com.android.application") }

android {
namespace = "radiography.stoic"
Expand All @@ -38,7 +35,6 @@ android {

dependencies {
compileOnly("com.squareup.stoic:plugin-sdk:0.7.0")
implementation(kotlin("stdlib"))
implementation(project(":radiography"))
}

Expand Down
Loading