Skip to content

Commit

Permalink
Merge branch 'jsoberg/example/compose-compiler-gradle-and-compileonly…
Browse files Browse the repository at this point in the history
…-buildlogic' into renovate/major-kotlin-dependencies-patch
  • Loading branch information
jsoberg committed May 27, 2024
2 parents 9d78095 + 36aa878 commit 096fd6e
Show file tree
Hide file tree
Showing 13 changed files with 63 additions and 60 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,7 @@ lint/outputs/
lint/tmp/

# Android Profiling
*.hprof
*.hprof

# Kotlin 2.0+
.kotlin/
4 changes: 4 additions & 0 deletions build-logic/gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Gradle properties are not passed to included builds https://github.com/gradle/gradle/issues/2534
org.gradle.parallel=true
org.gradle.caching=true
org.gradle.configureondemand=false
20 changes: 9 additions & 11 deletions build-logic/plugins/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@ plugins {
`kotlin-dsl`
}

dependencies {
implementation(libs.android.gradlePlugin)
implementation(libs.composeCompiler.gradlePlugin)
implementation(libs.kotlin.gradlePlugin)

// TODO: Fixes dependency conflict issues with Dagger/Hilt, re: https://github.com/google/dagger/issues/3068. Once this issues is resolved and we upgrade dagger/hilt, remove this dependency.
implementation(libs.javapoet)
}

gradlePlugin {
plugins {
register("local.android.compose") {
Expand Down Expand Up @@ -29,15 +38,4 @@ gradlePlugin {
implementationClass = "com.soberg.gradle.plugin.RootSettingsPlugin"
}
}
}

dependencies {
// Give plugin code access to the libs version catalog.
implementation(files(libs.javaClass.superclass.protectionDomain.codeSource.location))

implementation(libs.android.gradlePlugin)
implementation(libs.kotlin.gradlePlugin)

// TODO: Fixes dependency conflict issues with Dagger/Hilt, re: https://github.com/google/dagger/issues/3068. Once this issues is resolved and we upgrade dagger/hilt, remove this dependency.
implementation(libs.javapoet)
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ object Versions {
// See https://kotlinlang.org/docs/gradle-compiler-options.html#types-for-compiler-options
object Kotlin {
val jvmTarget = JvmTarget.JVM_17
val languageVersion = KotlinVersion.KOTLIN_1_9
val languageVersion = KotlinVersion.KOTLIN_2_0
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,56 +2,49 @@ package com.soberg.gradle.plugin

import com.soberg.gradle.plugin.ext.android
import com.soberg.gradle.plugin.ext.androidTestImplementation
import com.soberg.gradle.plugin.ext.composeCompiler
import com.soberg.gradle.plugin.ext.implementation
import com.soberg.gradle.plugin.ext.libs
import com.soberg.gradle.plugin.ext.plugins
import com.soberg.gradle.plugin.ext.testImplementation
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.kotlin.dsl.dependencies
import org.gradle.kotlin.dsl.withType
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile


class AndroidComposeConventionPlugin : Plugin<Project> {

private companion object {
private const val ComposeCompilerPluginPrepend =
"plugin:androidx.compose.compiler.plugins.kotlin"
}

override fun apply(project: Project) = with(project) {
plugins {
apply("org.jetbrains.kotlin.plugin.compose")
}
configureCompose()
configureComposeMetrics()
}

private fun Project.configureCompose() {
android {
buildFeatures.compose = true
composeOptions.kotlinCompilerExtensionVersion = libs.versions.composeCompiler.get()
}

dependencies {
val bom = platform(libs.compose.bom)
val bom = platform(libs.findLibrary("compose-bom").get())
implementation(bom)
androidTestImplementation(bom)
testImplementation(bom)
}
}

private fun Project.configureComposeMetrics() {
val composeMetricsDir = layout.buildDirectory.dir("compose-metrics").get().asFile
val composeReportsDir = layout.buildDirectory.dir("compose-reports").get().asFile

tasks.withType<KotlinCompile>().configureEach {
kotlinOptions {
freeCompilerArgs = freeCompilerArgs + listOf(
"-P",
"$ComposeCompilerPluginPrepend:metricsDestination=${composeMetricsDir.absolutePath}",

"-P",
"$ComposeCompilerPluginPrepend:reportsDestination=${composeReportsDir.absolutePath}",
)
}
composeCompiler {
enableStrongSkippingMode.set(true)

// TODO Enable config/reports
/* stabilityConfigurationFile.set(
layout.buildDirectory.dir("compose_compiler").get().asFile
)
reportsDestination.set(
rootProject.layout.projectDirectory.file("stability_config.conf").asFile
)*/
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,19 @@ class RootProjectPlugin : Plugin<Project> {
configureSubProjects()
}

private fun Project.applyTestOptions() {
tasks.withType<Test> {
useJUnitPlatform()
}
}

private fun Project.configureSubProjects() {
subprojects {
applyTestOptions()
applyKotlinCompileOptions()
}
}

private fun Project.applyTestOptions() {
tasks.withType<Test> {
useJUnitPlatform()
}
}

private fun Project.applyKotlinCompileOptions() {
tasks.withType<KotlinCompile>().configureEach {
kotlinOptions {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,19 @@ import com.android.build.gradle.BaseExtension
import org.gradle.api.Project
import org.gradle.api.plugins.ExtensionAware
import org.gradle.api.plugins.ExtensionContainer
import org.jetbrains.kotlin.compose.compiler.gradle.ComposeCompilerGradlePluginExtension
import org.jetbrains.kotlin.gradle.dsl.KotlinJvmOptions

fun Project.android(configure: BaseExtension.() -> Unit) {
val android = extensions.findByName("android") as BaseExtension
configure(android)
}

fun Project.composeCompiler(configure: ComposeCompilerGradlePluginExtension.() -> Unit) {
val android = extensions.findByName("composeCompiler") as ComposeCompilerGradlePluginExtension
configure(android)
}

fun BaseExtension.kotlinOptions(configure: KotlinJvmOptions.() -> Unit) =
androidExtensions.configure("kotlinOptions", configure)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package com.soberg.gradle.plugin.ext

import org.gradle.accessors.dm.LibrariesForLibs
import org.gradle.api.Project
import org.gradle.api.artifacts.VersionCatalog
import org.gradle.api.artifacts.VersionCatalogsExtension
import org.gradle.api.plugins.PluginContainer
import org.gradle.kotlin.dsl.the
import org.gradle.kotlin.dsl.getByType
import org.jetbrains.kotlin.gradle.dsl.KotlinJvmProjectExtension

internal fun Project.kotlin(configure: KotlinJvmProjectExtension.() -> Unit) =
Expand All @@ -13,5 +14,5 @@ internal fun Project.plugins(configure: PluginContainer.() -> Unit) {
configure(plugins)
}

internal val Project.libs: LibrariesForLibs
get() = project.the()
internal val Project.libs
get(): VersionCatalog = extensions.getByType<VersionCatalogsExtension>().named("libs")
10 changes: 5 additions & 5 deletions build-logic/settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
dependencyResolutionManagement {
repositories {
google()
mavenCentral()
}

versionCatalogs {
create("libs") {
from(files("../gradle/libs.versions.toml"))
}
}

repositories {
gradlePluginPortal()
google()
}
}

rootProject.name = "build-logic"
Expand Down
3 changes: 2 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
plugins {
id("local.root.project")
alias(libs.plugins.dependencyAnalysis)
alias(libs.plugins.hilt) apply false
alias(libs.plugins.kover) apply false
alias(libs.plugins.ksp) apply false

id("local.root.project")
}

buildscript {
Expand Down
5 changes: 3 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@
# The setting is particularly useful for tweaking memory settings.
# Note: Increased metaspace size is useful for metaspace-heavy tasks like lint
org.gradle.jvmargs=-Xmx12g -XX:MaxMetaspaceSize=4g -XX:+UseParallelGC
# Turn on parallel compilation, caching and on-demand configuration
org.gradle.configureondemand=true
# Turn on parallel compilation and caching
org.gradle.caching=true
org.gradle.parallel=true
# Not encouraged by Gradle and can produce weird results. Wait for isolated projects instead.
org.gradle.configureondemand=false
# Turn on the configuration cache
org.gradle.configuration-cache=true
org.gradle.configuration-cache.problems=warn
Expand Down
6 changes: 2 additions & 4 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ androidxLifecycle = "2.8.0"
androidxCoreTest = "1.5.0"
assertk = "0.28.1"
composeBom = "2024.05.00"
composeCompiler = "1.5.14"
composeNavigation = "2.7.7"
dagger = "2.51.1"
dependencyAnalysis = "1.31.0"
Expand All @@ -32,8 +31,6 @@ turbine = "1.1.0"

# AndroidX
androidX-activityCompose = { module = "androidx.activity:activity-compose", version.ref = "androidxActivity" }
## This is only present in the TOML so that Renovate will pickup the version.
android-composeCompiler = { module = "androidx.compose.compiler:compiler", version.ref = "composeCompiler" }
androidX-navigationCompose = { module = "androidx.navigation:navigation-compose", version.ref = "composeNavigation" }
androidX-lifecycle-composeRuntime = { module = "androidx.lifecycle:lifecycle-runtime-compose", version.ref = "androidxLifecycle" }
androidX-lifecycle-composeViewModelUtilities = { module = "androidx.lifecycle:lifecycle-viewmodel-compose", version.ref = "androidxLifecycle" }
Expand Down Expand Up @@ -97,10 +94,10 @@ test-turbine = { module = "app.cash.turbine:turbine", version.ref = "turbine" }

# Plugins
android-gradlePlugin = { module = "com.android.tools.build:gradle", version.ref = "androidGradlePlugin" }
composeCompiler-gradlePlugin = { module = "org.jetbrains.kotlin:compose-compiler-gradle-plugin", version.ref = "kotlin" }
hilt-agp = { module = "com.google.dagger:hilt-android-gradle-plugin", version.ref = "dagger" }
kotlin-gradlePlugin = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin", version.ref = "kotlin" }


[bundles]
compose-core = ["compose-ui", "compose-material3", "compose-ui-tooling"]
ktor-client = ["ktor-client-contentNegotiation", "ktor-client-core", "ktor-client-json", "ktor-client-logging", "ktor-client-okhttp", "ktor-client-serialization"]
Expand All @@ -109,6 +106,7 @@ robolectricTest = ["test-androidx-coreKtx", "test-junitJupiter", "test-junit4",


[plugins]
compose-compiler = { id = "org.jetbrains.kotlin.plugin.compose", version.ref = "kotlin" }
dependencyAnalysis = { id = "com.autonomousapps.dependency-analysis", version.ref = "dependencyAnalysis" }
hilt = { id = "com.google.dagger.hilt.android", version.ref = "dagger" }
kotlin-serialization = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "kotlin" }
Expand Down
2 changes: 0 additions & 2 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ plugins {
id("local.root.settings")
}

rootProject.name = "android-net-info"

include(":app")
include(":base:annotations")
include(":base:logging")
Expand Down

0 comments on commit 096fd6e

Please sign in to comment.