Skip to content

Commit

Permalink
Refactor Android configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
martinbonnin committed Mar 6, 2024
1 parent c91399a commit 5d647d3
Show file tree
Hide file tree
Showing 38 changed files with 106 additions and 129 deletions.
33 changes: 33 additions & 0 deletions build-logic/src/main/kotlin/Android.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import com.android.build.api.dsl.CommonExtension
import org.gradle.api.Project

fun Project.configureAndroid(
namespace: String,
androidOptions: AndroidOptions
) {
plugins.apply("com.android.library")
extensions.findByName("android")?.apply {
this as CommonExtension<*, *, *, *, *>

compileSdk = getCatalogVersion("android.sdkversion.compile").toInt()
this.namespace = namespace

defaultConfig {
minSdk = if (androidOptions.withCompose) {
getCatalogVersion("android.sdkversion.min").toInt()
} else {
getCatalogVersion("android.sdkversion.compose.min").toInt()
}
}

if (androidOptions.withCompose) {
buildFeatures {
compose = true
}

composeOptions {
kotlinCompilerExtensionVersion = getCatalogVersion("compose.compiler")
}
}
}
}
18 changes: 12 additions & 6 deletions build-logic/src/main/kotlin/api.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,27 @@ import org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootExtension
import org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootPlugin
import org.jetbrains.kotlin.gradle.targets.js.npm.tasks.KotlinNpmInstallTask

class AndroidOptions(
val withCompose: Boolean
)

fun Project.apolloLibrary(
javaModuleName: String?,
namespace: String,
jvmTarget: Int? = null,
withJs: Boolean = true,
withLinux: Boolean = true,
withApple: Boolean = true,
withJvm: Boolean = true,
withWasm: Boolean = true,
androidOptions: AndroidOptions? = null,
publish: Boolean = true
) {
group = property("GROUP")!!
version = property("VERSION_NAME")!!

if (androidOptions != null) {
configureAndroid(namespace, androidOptions)
}
commonSetup()
configureJavaAndKotlinCompilers(jvmTarget)

Expand Down Expand Up @@ -54,11 +62,9 @@ fun Project.apolloLibrary(
)
}

if (javaModuleName != null) {
tasks.withType(Jar::class.java).configureEach {
manifest {
attributes(mapOf("Automatic-Module-Name" to javaModuleName))
}
tasks.withType(Jar::class.java).configureEach {
manifest {
attributes(mapOf("Automatic-Module-Name" to namespace))
}
}
}
Expand Down
6 changes: 6 additions & 0 deletions build-logic/src/main/kotlin/utils.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import org.gradle.api.Project
import org.gradle.api.artifacts.VersionCatalogsExtension

fun Project.getCatalogVersion(alias: String): String {
return extensions.findByType(VersionCatalogsExtension::class.java)!!.named("libs").findVersion(alias).get().displayName
}
1 change: 1 addition & 0 deletions gradle/libraries.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ androidx-appcompat = { group = "androidx.appcompat", name = "appcompat", version
androidx-espresso-idlingresource = { group = "androidx.test.espresso", name = "espresso-idling-resource", version = "3.5.1" }
androidx-lint-rules = "androidx.lint:lint-gradle:1.0.0-alpha01"
androidx-lint-gradle-plugin = "com.android.lint:com.android.lint.gradle.plugin:8.2.2"
androidx-paging-compose = "androidx.paging:paging-compose:1.0.0-alpha18"
androidx-profileinstaller = "androidx.profileinstaller:profileinstaller:1.3.1"
androidx-sqlite = { group = "androidx.sqlite", name = "sqlite", version.ref = "androidx-sqlite" }
androidx-sqlite-framework = { group = "androidx.sqlite", name = "sqlite-framework", version.ref = "androidx-sqlite" }
Expand Down
2 changes: 1 addition & 1 deletion libraries/apollo-adapters/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ plugins {
}

apolloLibrary(
javaModuleName = "com.apollographql.apollo3.adapter",
namespace = "com.apollographql.apollo3.adapter",
withLinux = false,
withWasm = false
)
Expand Down
2 changes: 1 addition & 1 deletion libraries/apollo-annotations/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ plugins {
}

apolloLibrary(
javaModuleName = "com.apollographql.apollo3.annotations"
namespace = "com.apollographql.apollo3.annotations"
)

kotlin {
Expand Down
2 changes: 1 addition & 1 deletion libraries/apollo-api-java/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ plugins {
}

apolloLibrary(
javaModuleName = "com.apollographql.apollo3.api.java"
namespace = "com.apollographql.apollo3.api.java"
)

dependencies {
Expand Down
2 changes: 1 addition & 1 deletion libraries/apollo-api/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ plugins {
}

apolloLibrary(
javaModuleName = "com.apollographql.apollo3.api"
namespace = "com.apollographql.apollo3.api"
)

kotlin {
Expand Down
2 changes: 1 addition & 1 deletion libraries/apollo-ast/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ plugins {
}

apolloLibrary(
javaModuleName = "com.apollographql.apollo3.ast"
namespace = "com.apollographql.apollo3.ast"
)

kotlin {
Expand Down
2 changes: 1 addition & 1 deletion libraries/apollo-cli-incubating/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ plugins {
}

apolloLibrary(
javaModuleName = "com.apollographql.apollo3.cli",
namespace = "com.apollographql.apollo3.cli",
)

dependencies {
Expand Down
2 changes: 1 addition & 1 deletion libraries/apollo-compiler/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ plugins {
}

apolloLibrary(
javaModuleName = "com.apollographql.apollo3.compiler"
namespace = "com.apollographql.apollo3.compiler"
)

dependencies {
Expand Down
40 changes: 12 additions & 28 deletions libraries/apollo-compose-paging-support-incubating/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,42 +1,26 @@
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

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

apolloLibrary(
javaModuleName = "com.apollographql.apollo3.compose.paging"
namespace = "com.apollographql.apollo3.compose.paging",
androidOptions = AndroidOptions(
withCompose = true
)
)


dependencies {
api(project(":apollo-compose-support-incubating"))
api("androidx.paging:paging-compose:1.0.0-alpha18")
api(libs.androidx.paging.compose)
}

android {
compileSdk = libs.versions.android.sdkversion.compile.get().toInt()
namespace = "com.apollographql.apollo3.compose.paging.support"

defaultConfig {
minSdk = libs.versions.android.sdkversion.compose.min.get().toInt()
}

buildFeatures {
compose = true
}

composeOptions {
kotlinCompilerExtensionVersion = libs.versions.compose.compiler.get()
}

// TODO: compiling fails only with the debug variant currently, due to using a version of Kotlin non supported by Compose.
// For now, disabling the debug variant works around the issue.
variantFilter {
ignore = name == "debug"
}
}
//android {
// // TODO: compiling fails only with the debug variant currently, due to using a version of Kotlin non supported by Compose.
// // For now, disabling the debug variant works around the issue.
// variantFilter {
// ignore = name == "debug"
// }
//}

// Uncomment when using a non supported version of Kotlin
// See https://developer.android.com/jetpack/androidx/releases/compose-kotlin
Expand Down
22 changes: 2 additions & 20 deletions libraries/apollo-compose-support-incubating/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

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

apolloLibrary(
javaModuleName = "com.apollographql.apollo3.compose"
namespace = "com.apollographql.apollo3.compose",
androidOptions = AndroidOptions(withCompose = true)
)

dependencies {
Expand All @@ -15,23 +14,6 @@ dependencies {
api(project(":apollo-normalized-cache"))
}

android {
compileSdk = libs.versions.android.sdkversion.compile.get().toInt()
namespace = "com.apollographql.apollo3.compose.support"

defaultConfig {
minSdk = libs.versions.android.sdkversion.compose.min.get().toInt()
}

buildFeatures {
compose = true
}

composeOptions {
kotlinCompilerExtensionVersion = libs.versions.compose.compiler.get()
}
}

// Uncomment when using a non supported version of Kotlin
// See https://developer.android.com/jetpack/androidx/releases/compose-kotlin
//tasks.withType(KotlinCompile::class.java).configureEach {
Expand Down
15 changes: 3 additions & 12 deletions libraries/apollo-debug-server/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
id("org.jetbrains.kotlin.multiplatform")
id("com.android.library")
alias(libs.plugins.apollo.published)
id("com.google.devtools.ksp")
}

apolloLibrary(
javaModuleName = "com.apollographql.apollo3.debugserver",
namespace = "com.apollographql.apollo3.debugserver",
withLinux = false,
withApple = false,
withJs = false,
withWasm = false
withWasm = false,
androidOptions = AndroidOptions(withCompose = false)
)

kotlin {
Expand Down Expand Up @@ -74,15 +74,6 @@ configurations.all {
}
configurations.getByName(kotlin.sourceSets.getByName("commonMain").compileOnlyConfigurationName).extendsFrom(shadow)

android {
compileSdk = libs.versions.android.sdkversion.compile.get().toInt()
namespace = "com.apollographql.apollo3.debugserver"

defaultConfig {
minSdk = libs.versions.android.sdkversion.min.get().toInt()
}
}

/**
* KSP configuration
* KMP support isn't great so we wire most of the things manually
Expand Down
2 changes: 1 addition & 1 deletion libraries/apollo-engine-ktor/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ plugins {
}

apolloLibrary(
javaModuleName = "com.apollographql.apollo3.engine.ktor",
namespace = "com.apollographql.apollo3.engine.ktor",
withLinux = false,
withWasm = false
)
Expand Down
2 changes: 1 addition & 1 deletion libraries/apollo-execution-incubating/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ plugins {
}

apolloLibrary(
javaModuleName = "com.apollographql.apollo3.execution",
namespace = "com.apollographql.apollo3.execution",
publish = false,
)

Expand Down
2 changes: 1 addition & 1 deletion libraries/apollo-gradle-plugin-external/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ plugins {
}

apolloLibrary(
javaModuleName = "com.apollographql.apollo3.gradle",
namespace = "com.apollographql.apollo3.gradle",
jvmTarget = 11 // AGP requires 11
)

Expand Down
2 changes: 1 addition & 1 deletion libraries/apollo-gradle-plugin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ plugins {
}

apolloLibrary(
javaModuleName = null,
namespace = "com.apollographql.apollo3.gradle.relocated",
jvmTarget = 11 // AGP requires 11
)

Expand Down
2 changes: 1 addition & 1 deletion libraries/apollo-http-cache/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ plugins {
}

apolloLibrary(
javaModuleName = "com.apollographql.apollo3.cache.http"
namespace = "com.apollographql.apollo3.cache.http"
)

dependencies {
Expand Down
12 changes: 2 additions & 10 deletions libraries/apollo-idling-resource/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,11 @@ plugins {
}

apolloLibrary(
javaModuleName = "com.apollographql.apollo3.idling.resource",
namespace = "com.apollographql.apollo3.idling.resource",
androidOptions = AndroidOptions(withCompose = false)
)

dependencies {
implementation(libs.androidx.espresso.idlingresource)
api(project(":apollo-runtime"))
}

android {
compileSdk = libs.versions.android.sdkversion.compile.get().toInt()
namespace = "com.apollographql.apollo3.idling.resource"

defaultConfig {
minSdk = libs.versions.android.sdkversion.min.get().toInt()
}
}
2 changes: 1 addition & 1 deletion libraries/apollo-ksp-incubating/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ plugins {
}

apolloLibrary(
javaModuleName = "com.apollographql.apollo3.ksp",
namespace = "com.apollographql.apollo3.ksp",
publish = false,
)

Expand Down
2 changes: 1 addition & 1 deletion libraries/apollo-mockserver/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ plugins {
}

apolloLibrary(
javaModuleName = "com.apollographql.apollo3.mockserver",
namespace = "com.apollographql.apollo3.mockserver",
withLinux = false,
)

Expand Down
2 changes: 1 addition & 1 deletion libraries/apollo-mpp-utils/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ plugins {
}

apolloLibrary(
javaModuleName = "com.apollographql.apollo3.mpp",
namespace = "com.apollographql.apollo3.mpp",
withLinux = false
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ plugins {
}

apolloLibrary(
javaModuleName = "com.apollographql.apollo3.cache.normalized.api",
namespace = "com.apollographql.apollo3.cache.normalized.api",
withLinux = false,
)

Expand Down

0 comments on commit 5d647d3

Please sign in to comment.