Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade dependencies and tidy up build logic #100

27 changes: 27 additions & 0 deletions build-logic/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
plugins {
id("java-gradle-plugin")
alias(libs.plugins.kotlinJvm)
alias(libs.plugins.kotlinSam)
}

samWithReceiver {
annotation("org.gradle.api.HasImplicitReceiver")
}

gradlePlugin {
plugins.register("buildPlugin") {
id = "com.deliveryhero.whetstone.build"
implementationClass = "com.deliveryhero.whetstone.build.BuildPlugin"
}
}

kotlin.compilerOptions {
optIn.add("kotlin.ExperimentalStdlibApi")
freeCompilerArgs.add("-Xjvm-default=all")
}

dependencies {
implementation(gradleKotlinDsl())
compileOnly(libs.kotlinGradle)
compileOnly(libs.androidGradle)
}
1 change: 1 addition & 0 deletions build-logic/gradle
19 changes: 19 additions & 0 deletions build-logic/settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
@file:Suppress("UnstableApiUsage")

rootProject.name = "build-logic"

pluginManagement {
repositories {
gradlePluginPortal()
google()
mavenCentral()
}
}

dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
google()
mavenCentral()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package com.deliveryhero.whetstone.build

import com.android.build.api.dsl.CommonExtension
import org.gradle.api.JavaVersion
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.plugins.JavaPluginExtension
import org.gradle.kotlin.dsl.configure
import org.jetbrains.kotlin.gradle.dsl.*

class BuildPlugin : Plugin<Project> {

override fun apply(target: Project) {
target.configureJava()
target.configureKotlin()
target.configureAndroid()
}

private fun Project.configureJava() = configure<JavaPluginExtension> {
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
}

private fun Project.configureKotlin() = configure<KotlinProjectExtension> {
val config: KotlinJvmCompilerOptions.() -> Unit = {
optIn.add("com.squareup.anvil.annotations.ExperimentalAnvilApi")
freeCompilerArgs.addAll("-Xjvm-default=all", "-Xassertions=jvm")
jvmTarget.set(JvmTarget.JVM_11)
}
when (this) {
is KotlinJvmProjectExtension -> compilerOptions(config)
is KotlinAndroidProjectExtension -> compilerOptions(config)
}
if (project.name != "sample") explicitApi()
jvmToolchain(17)
}

private fun Project.configureAndroid() = plugins.withId("com.android.base") {
extensions.configure(CommonExtension::class) {
compileSdk = 35
defaultConfig.minSdk = 21
compileOptions {
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
}
}
}
}
68 changes: 9 additions & 59 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,68 +1,18 @@
import com.android.build.gradle.BaseExtension
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

buildscript {
repositories {
gradlePluginPortal()
google()
}

dependencies {
classpath(libs.androidGradle)
classpath(libs.kotlinGradle)
classpath(libs.anvilGradle)
classpath(libs.mavenPublishGradle)
}
}

subprojects {
afterEvaluate {
tasks.withType<KotlinCompile> {
configureTask()
}
extensions.findByType<BaseExtension>()?.apply {
configureExtension()
}
}
}

fun KotlinCompile.configureTask() {
kotlinOptions {
jvmTarget = JavaVersion.VERSION_11.toString()

val compilerArgs = mutableListOf(
"-Xassertions=jvm",
"-opt-in=kotlin.RequiresOptIn",
"-opt-in=com.squareup.anvil.annotations.ExperimentalAnvilApi",
)
if (project.name != "sample") compilerArgs += "-Xexplicit-api=strict"
freeCompilerArgs = freeCompilerArgs + compilerArgs
}
}

fun BaseExtension.configureExtension() {
compileSdkVersion(34)

defaultConfig {
minSdk = 21
targetSdk = 33
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
}
}


plugins {
id("org.jetbrains.kotlinx.binary-compatibility-validator") version "0.13.2"
alias(libs.plugins.kotlinCompose).apply(false)
alias(libs.plugins.androidApp).apply(false)
alias(libs.plugins.androidLib).apply(false)
alias(libs.plugins.kotlinJvm).apply(false)
alias(libs.plugins.kotlinKapt).apply(false)
alias(libs.plugins.anvil).apply(false)
alias(libs.plugins.mavenPublish).apply(false)
alias(libs.plugins.binaryValidator)
}

apiValidation {
ignoredProjects.addAll(listOf("sample", "whetstone-compiler"))
}

tasks.register("clean", Delete::class) {
tasks.register<Delete>("clean") {
delete(rootProject.layout.buildDirectory)
}
40 changes: 20 additions & 20 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,28 +1,31 @@
[versions]
androidGradle = "8.2.2"
androidxActivity = "1.5.0"
androidxAppCompat = "1.3.1"
androidxCompose = "1.6.1"
androidxComposeCompiler = "1.5.9"
androidxCore = "1.7.0"
androidxFragment = "1.5.0"
androidxLifecycle = "2.5.0"
androidxWork = "2.7.0"
anvil = "2.5.0-beta01"
dagger = "2.51.1"
kotlin = "1.9.22"
kotlinxCoroutines = "1.6.4"
mavenPublish = "0.25.3"
truth = "1.1.3"
agp = "8.8.0"
androidxActivity = "1.9.0"
androidxAppCompat = "1.7.0"
androidxCompose = "1.7.0"
androidxCore = "1.15.0"
androidxFragment = "1.6.0"
androidxLifecycle = "2.7.0"
androidxWork = "2.9.0"
anvil = "2.5.1"
dagger = "2.53"
kotlin = "2.0.0"
mavenPublish = "0.30.0"
autoService = "1.1.1"

[plugins]
androidApp = { id = "com.android.application", version.ref = "agp" }
androidLib = { id = "com.android.library", version.ref = "agp" }
anvil = { id = "com.squareup.anvil", version.ref = "anvil" }
binaryValidator = { id = "org.jetbrains.kotlinx.binary-compatibility-validator", version = "0.17.0" }
kotlinCompose = { id = "org.jetbrains.kotlin.plugin.compose", version.ref = "kotlin" }
kotlinJvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" }
kotlinKapt = { id = "org.jetbrains.kotlin.kapt", version.ref = "kotlin" }
mavenPublish = { id = "com.vanniktech.maven.publish", version.ref = "mavenPublish"}
kotlinSam = { id = "org.jetbrains.kotlin.plugin.sam.with.receiver", version.ref = "kotlin" }
mavenPublish = { id = "com.vanniktech.maven.publish", version.ref = "mavenPublish" }

[libraries]
androidGradle = { module = "com.android.tools.build:gradle", version.ref = "androidGradle" }
androidGradle = { module = "com.android.tools.build:gradle", version.ref = "agp" }
androidxActivity = { module = "androidx.activity:activity-ktx", version.ref = "androidxActivity" }
androidxAppCompat = { module = "androidx.appcompat:appcompat", version.ref = "androidxAppCompat" }
androidxComposeMaterial = { module = "androidx.compose.material:material", version.ref = "androidxCompose" }
Expand All @@ -41,9 +44,6 @@ anvilCompiler = { module = "com.squareup.anvil:compiler-api", version.ref = "anv
anvilCompilerUtils = { module = "com.squareup.anvil:compiler-utils", version.ref = "anvil" }
anvilGradle = { module = "com.squareup.anvil:gradle-plugin", version.ref = "anvil" }
dagger = { module = "com.google.dagger:dagger", version.ref = "dagger" }
daggerCompiler = { module = "com.google.dagger:dagger-compiler", version.ref = "dagger" }
kotlinGradle = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin", version.ref = "kotlin" }
mavenPublishGradle = { module = "com.vanniktech:gradle-maven-publish-plugin", version.ref = "mavenPublish" }
truth = { module = "com.google.truth:truth", version.ref = "truth" }
autoServiceAnnotations = { module = "com.google.auto.service:auto-service-annotations", version.ref = "autoService" }
autoServiceCompiler = { module = "com.google.auto.service:auto-service", version.ref = "autoService" }
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.12.1-all.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
12 changes: 7 additions & 5 deletions sample/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
plugins {
id("com.android.application")
id("org.jetbrains.kotlin.android")
id("org.jetbrains.kotlin.plugin.compose")
id("com.deliveryhero.whetstone.build")
id("com.deliveryhero.whetstone")
}

Expand All @@ -15,12 +17,12 @@ android {
versionCode = 1
versionName = "1.0"
applicationId = "com.deliveryhero.whetstone.sample"
targetSdk = 35
}
buildFeatures {
compose = true
viewBinding = true
}
composeOptions.kotlinCompilerExtensionVersion = libs.versions.androidxComposeCompiler.get()
}

dependencies {
Expand All @@ -29,9 +31,9 @@ dependencies {
implementation(libs.androidxAppCompat)
implementation(libs.androidxComposeMaterial)
implementation(libs.androidxComposeUi)
implementation("com.google.android.material:material:1.8.0")
implementation("androidx.constraintlayout:constraintlayout:2.1.4")
implementation("com.google.android.material:material:1.12.0")
implementation("androidx.constraintlayout:constraintlayout:2.2.0")
testImplementation("junit:junit:4.13.2")
androidTestImplementation("androidx.test.ext:junit:1.1.5")
androidTestImplementation("androidx.test.espresso:espresso-core:3.5.1")
androidTestImplementation("androidx.test.ext:junit:1.2.1")
androidTestImplementation("androidx.test.espresso:espresso-core:3.6.1")
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ import com.deliveryhero.whetstone.sample.databinding.ActivityMainBinding
import com.deliveryhero.whetstone.viewmodel.injectedViewModel

class MainActivity : AppCompatActivity() {

private val viewModel by injectedViewModel<MainViewModel>()
private val serviceIntent by lazy { Intent(this, MainService::class.java) }

override fun onCreate(savedInstanceState: Bundle?) {
Expand All @@ -36,7 +34,6 @@ class MainActivity : AppCompatActivity() {
)
}

Toast.makeText(this, viewModel.getHelloWorld(), Toast.LENGTH_SHORT).show()
startService(serviceIntent)
val request = OneTimeWorkRequest.from(MainWorker::class.java)
WorkManager.getInstance(this).enqueue(request)
Expand Down
1 change: 1 addition & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ rootProject.name = "pd-whetstone"

pluginManagement {
includeBuild("whetstone-gradle-plugin")
includeBuild("build-logic")
repositories {
gradlePluginPortal()
google()
Expand Down
17 changes: 8 additions & 9 deletions whetstone-compiler/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
plugins {
kotlin("jvm")
kotlin("kapt")
id("com.deliveryhero.whetstone.build")
id("com.vanniktech.maven.publish")
}

java {
toolchain {
languageVersion.set(JavaLanguageVersion.of("11"))
}
kotlin {
jvmToolchain(17)
}

dependencies {
implementation(libs.anvilCompiler)
implementation(libs.anvilCompilerUtils)
implementation(libs.anvilAnnotations)
implementation(libs.dagger)
implementation(libs.autoServiceAnnotations)
compileOnly(libs.anvilCompiler)
compileOnly(libs.anvilCompilerUtils)
compileOnly(libs.anvilAnnotations)
compileOnly(libs.dagger)
compileOnly(libs.autoServiceAnnotations)
kapt(libs.autoServiceCompiler)
}
3 changes: 2 additions & 1 deletion whetstone-compose/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
plugins {
id("com.android.library")
id("org.jetbrains.kotlin.android")
id("org.jetbrains.kotlin.plugin.compose")
id("com.deliveryhero.whetstone.build")
id("com.vanniktech.maven.publish")
}

android {
buildFeatures.compose = true
composeOptions.kotlinCompilerExtensionVersion = libs.versions.androidxComposeCompiler.get()
namespace = "com.deliveryhero.whetstone.compose"
}

Expand Down
23 changes: 12 additions & 11 deletions whetstone-gradle-plugin/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,27 +1,30 @@
import java.util.*
import com.vanniktech.maven.publish.MavenPublishPlugin
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
import java.util.Properties

@Suppress("DSL_SCOPE_VIOLATION") // TODO: Remove once KTIJ-19369 is fixed
plugins {
id("java-library")
id("java-gradle-plugin")
alias(libs.plugins.kotlinJvm)
alias(libs.plugins.kotlinKapt)
alias(libs.plugins.mavenPublish).apply(false)
}

loadParentProperties()
pluginManager.apply(com.vanniktech.maven.publish.MavenPublishPlugin::class)
pluginManager.apply(MavenPublishPlugin::class)

kotlin {
jvmToolchain(17)
explicitApi()
compilerOptions.jvmTarget.set(JvmTarget.JVM_11)
}

java {
toolchain {
languageVersion.set(JavaLanguageVersion.of("11"))
}
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
}

tasks.compileKotlin {
dependsOn(generateBuildConfig)
kotlinOptions.jvmTarget = JavaVersion.VERSION_11.toString()
kotlinOptions.freeCompilerArgs += "-Xexplicit-api=strict"
}

gradlePlugin {
Expand All @@ -37,8 +40,6 @@ dependencies {
implementation(gradleKotlinDsl())
implementation(libs.anvilGradle)
compileOnly(libs.androidGradle)
compileOnly(libs.autoServiceAnnotations)
kapt(libs.autoServiceCompiler)
}

val generateBuildConfig by tasks.registering(GenerateBuildConfigTask::class) {
Expand Down
Loading
Loading