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

Commonize Gradle build logic with convention plugins #2021

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
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
33 changes: 33 additions & 0 deletions build-logic/convention/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
`kotlin-dsl`
}

group = "dev.mobile.maestro"

dependencies {
compileOnly(libs.kotlin.gradlePlugin)
}

// Configure the build-logic plugins to target JDK 17
// This matches the JDK used to build the project, and is not related to what is running on device.
// java {
// sourceCompatibility = JavaVersion.VERSION_17
// targetCompatibility = JavaVersion.VERSION_17
// }

// kotlin {
// compilerOptions {
// jvmTarget = JvmTarget.JVM_17
// }
// }

gradlePlugin {
plugins {
register("jvmLibrary") {
id = "maestro.jvm.library"
implementationClass = "dev.mobile.maestro.JvmLibraryConventionPlugin"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package dev.mobile.maestro

import org.gradle.api.JavaVersion
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.plugins.JavaPluginExtension
import org.gradle.api.tasks.compile.JavaCompile
import org.gradle.kotlin.dsl.configure
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

class JvmLibraryConventionPlugin : Plugin<Project> {
override fun apply(target: Project) {
with(target) {
with(pluginManager) {
apply("org.jetbrains.kotlin.jvm")
libs.plugins.mavenPublish
}

extensions.configure<JavaPluginExtension> {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}

tasks.withType(JavaCompile::class.java).configureEach {
options.release.set(8)
}

tasks.withType(KotlinCompile::class.java).configureEach {
compilerOptions {
jvmTarget.set(JvmTarget.JVM_1_8)
freeCompilerArgs.addAll("-Xjdk-release=1.8")
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package dev.mobile.maestro

import org.gradle.api.Project
import org.gradle.api.artifacts.VersionCatalog
import org.gradle.api.artifacts.VersionCatalogsExtension
import org.gradle.kotlin.dsl.getByType

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

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

rootProject.name = "build-logic"
include(":convention")
12 changes: 9 additions & 3 deletions example/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import org.jetbrains.kotlin.gradle.tasks.KotlinCompilationTask
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
application
Expand All @@ -10,8 +11,14 @@ application {
mainClass.set("MainKt")
}

tasks.named("compileKotlin", KotlinCompilationTask::class.java) {
java {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}

tasks.withType(KotlinCompile::class.java).configureEach {
compilerOptions {
jvmTarget = JvmTarget.JVM_1_8
freeCompilerArgs.addAll("-Xjdk-release=1.8")
}
}
Expand All @@ -21,4 +28,3 @@ dependencies {
implementation("dev.mobile:maestro-orchestra:1.38.1")
implementation("dev.mobile:maestro-ios:1.38.1")
}

11 changes: 9 additions & 2 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# https://blog.gradle.org/best-practices-naming-version-catalog-entries

[versions]
androidPlugin = "7.4.2"
androidPlugin = "8.2.2"
androidxEspresso = "3.6.1"
androidxTestJunit = "1.2.1"
androidxUiautomator = "2.3.0"
Expand Down Expand Up @@ -112,6 +112,10 @@ square-mock-server = { module = "com.squareup.okhttp3:mockwebserver", version.re
wiremock-jre8 = { module = "com.github.tomakehurst:wiremock-jre8", version.ref = "wiremock" }
logback = { module = "ch.qos.logback:logback-classic", version.ref = "logback" }

# Dependencies of the included build-logic
kotlin-gradlePlugin = { group = "org.jetbrains.kotlin", name = "kotlin-gradle-plugin", version.ref = "kotlin" }
mavenPublish = { id = "com.vanniktech.maven.publish", version = "0.19.0" }

[bundles]

[plugins]
Expand All @@ -121,6 +125,9 @@ protobuf = { id = "com.google.protobuf", version.ref = "googleProtobufPlugin" }
kotlin-jvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" }
kotlin-android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" }
kotlin-serialization = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "kotlin" }
mavenPublish = { id = "com.vanniktech.maven.publish", version = "0.19.0" }
mavenPublish = { id = "com.vanniktech.maven.publish", version = "0.19.0" } # TODO: Delete from here
jreleaser = { id = "org.jreleaser", version = "1.13.1" }
shadow = { id = "com.github.johnrengelman.shadow", version = "7.1.2" }

# Plugins defined by this project
maestro-jvm-library = { id = "maestro.jvm.library", version = "unspecified" }
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionSha256Sum=bed1da33cca0f557ab13691c77f38bb67388119e4794d113e051039b80af9bb1
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.4-bin.zip
distributionSha256Sum=5b9c5eb3f9fc2c94abaea57d90bd78747ca117ddbbf96c859d3741181a12bf2a
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10-bin.zip
networkTimeout=10000
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
3 changes: 1 addition & 2 deletions maestro-ai/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinCompilationTask
plugins {
application
id("maven-publish")
alias(libs.plugins.kotlin.jvm)
alias(libs.plugins.maestro.jvm.library)
alias(libs.plugins.kotlin.serialization)
alias(libs.plugins.mavenPublish)
}

application {
Expand Down
Binary file modified maestro-client/src/main/resources/maestro-app.apk
Binary file not shown.
2 changes: 1 addition & 1 deletion maestro-orchestra/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinCompilationTask

plugins {
id("maven-publish")
alias(libs.plugins.kotlin.jvm)
alias(libs.plugins.maestro.jvm.library)
alias(libs.plugins.kotlin.serialization)
alias(libs.plugins.mavenPublish)
}
Expand Down
1 change: 1 addition & 0 deletions maestro-utils/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import com.vanniktech.maven.publish.SonatypeHost
plugins {
id("maven-publish")
alias(libs.plugins.kotlin.jvm)
alias(libs.plugins.maestro.jvm.library)
alias(libs.plugins.mavenPublish)
}

Expand Down
1 change: 1 addition & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
rootProject.name = "maestro"

pluginManagement {
includeBuild("build-logic")
repositories {
google()
mavenCentral()
Expand Down
Loading