-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactors BuildSrc to Version Catalog
Adds Gradle Convention Plugins
- Loading branch information
Showing
28 changed files
with
780 additions
and
204 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile | ||
|
||
plugins { | ||
`kotlin-dsl` | ||
} | ||
|
||
group = "ir.zinutech.android.flickrSearch.buildlogic" | ||
|
||
java { | ||
sourceCompatibility = JavaVersion.VERSION_17 | ||
targetCompatibility = JavaVersion.VERSION_17 | ||
} | ||
tasks.withType<KotlinCompile>().configureEach { | ||
kotlinOptions { | ||
jvmTarget = JavaVersion.VERSION_17.toString() | ||
} | ||
} | ||
|
||
dependencies { | ||
compileOnly(libs.android.gradlePlugin) | ||
compileOnly(libs.android.tools.common) | ||
compileOnly(libs.kotlin.gradlePlugin) | ||
} | ||
|
||
tasks { | ||
validatePlugins { | ||
enableStricterValidation = true | ||
failOnWarning = true | ||
} | ||
} | ||
|
||
gradlePlugin { | ||
plugins { | ||
register("androidApplication") { | ||
id = "flickrsearch.android.application" | ||
implementationClass = "AndroidApplicationConventionPlugin" | ||
} | ||
register("androidLibrary") { | ||
id = "flickrsearch.android.library" | ||
implementationClass = "AndroidLibraryConventionPlugin" | ||
} | ||
register("androidHilt") { | ||
id = "flickrsearch.android.hilt" | ||
implementationClass = "AndroidHiltConventionPlugin" | ||
} | ||
register("jvmLibrary") { | ||
id = "flickrsearch.jvm.library" | ||
implementationClass = "JvmLibraryConventionPlugin" | ||
} | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
build-logic/convention/src/main/kotlin/AndroidApplicationConventionPlugin.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import com.android.build.api.dsl.ApplicationExtension | ||
import ir.zinutech.android.flickrSearch.configureKotlinAndroid | ||
import org.gradle.api.Plugin | ||
import org.gradle.api.Project | ||
import org.gradle.kotlin.dsl.configure | ||
|
||
class AndroidApplicationConventionPlugin : Plugin<Project> { | ||
override fun apply(target: Project) { | ||
with(target) { | ||
with(pluginManager) { | ||
apply("com.android.application") | ||
apply("org.jetbrains.kotlin.android") | ||
} | ||
|
||
extensions.configure<ApplicationExtension> { | ||
configureKotlinAndroid(this) | ||
defaultConfig.targetSdk = 34 | ||
} | ||
} | ||
} | ||
|
||
} |
22 changes: 22 additions & 0 deletions
22
build-logic/convention/src/main/kotlin/AndroidHiltConventionPlugin.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import ir.zinutech.android.flickrSearch.libs | ||
import org.gradle.api.Plugin | ||
import org.gradle.api.Project | ||
import org.gradle.kotlin.dsl.dependencies | ||
|
||
class AndroidHiltConventionPlugin : Plugin<Project> { | ||
override fun apply(target: Project) { | ||
with(target) { | ||
with(pluginManager) { | ||
apply("com.google.devtools.ksp") | ||
apply("dagger.hilt.android.plugin") | ||
} | ||
|
||
dependencies { | ||
"implementation"(libs.findLibrary("hilt.android").get()) | ||
"ksp"(libs.findLibrary("hilt.compiler").get()) | ||
} | ||
|
||
} | ||
} | ||
|
||
} |
32 changes: 32 additions & 0 deletions
32
build-logic/convention/src/main/kotlin/AndroidLibraryConventionPlugin.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import com.android.build.api.variant.LibraryAndroidComponentsExtension | ||
import com.android.build.gradle.LibraryExtension | ||
import ir.zinutech.android.flickrSearch.configureKotlinAndroid | ||
import ir.zinutech.android.flickrSearch.disableUnnecessaryAndroidTests | ||
import ir.zinutech.android.flickrSearch.libs | ||
import org.gradle.api.Plugin | ||
import org.gradle.api.Project | ||
import org.gradle.kotlin.dsl.configure | ||
import org.gradle.kotlin.dsl.dependencies | ||
import org.gradle.kotlin.dsl.kotlin | ||
|
||
class AndroidLibraryConventionPlugin : Plugin<Project> { | ||
override fun apply(target: Project) { | ||
with(target) { | ||
with(pluginManager) { | ||
apply("com.android.library") | ||
apply("org.jetbrains.kotlin.android") | ||
} | ||
|
||
extensions.configure<LibraryExtension> { | ||
configureKotlinAndroid(this) | ||
defaultConfig.targetSdk = 34 | ||
} | ||
extensions.configure<LibraryAndroidComponentsExtension> { | ||
disableUnnecessaryAndroidTests(target) | ||
} | ||
dependencies { | ||
add("testImplementation", kotlin("test")) | ||
} | ||
} | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
build-logic/convention/src/main/kotlin/JvmLibraryConventionPlugin.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import ir.zinutech.android.flickrSearch.configureKotlinJvm | ||
import org.gradle.api.Plugin | ||
import org.gradle.api.Project | ||
|
||
class JvmLibraryConventionPlugin : Plugin<Project> { | ||
override fun apply(target: Project) { | ||
with(target) { | ||
with(pluginManager) { | ||
apply("org.jetbrains.kotlin.jvm") | ||
} | ||
configureKotlinJvm() | ||
} | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
...c/convention/src/main/kotlin/ir/zinutech/android/flickrSearch/AndroidInstrumentedTests.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package ir.zinutech.android.flickrSearch | ||
|
||
import com.android.build.api.variant.LibraryAndroidComponentsExtension | ||
import org.gradle.api.Project | ||
|
||
/** | ||
* Disable unnecessary Android instrumented tests for the [project] if there is no `androidTest` folder. | ||
* Otherwise, these projects would be compiled, packaged, installed and ran only to end-up with the following message: | ||
* | ||
* > Starting 0 tests on AVD | ||
* | ||
* Note: this could be improved by checking other potential sourceSets based on buildTypes and flavors. | ||
*/ | ||
internal fun LibraryAndroidComponentsExtension.disableUnnecessaryAndroidTests( | ||
project: Project, | ||
) = beforeVariants { | ||
it.enableAndroidTest = it.enableAndroidTest | ||
&& project.projectDir.resolve("src/androidTest").exists() | ||
} |
70 changes: 70 additions & 0 deletions
70
build-logic/convention/src/main/kotlin/ir/zinutech/android/flickrSearch/KotlinAndroid.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package ir.zinutech.android.flickrSearch | ||
|
||
import com.android.build.api.dsl.CommonExtension | ||
import org.gradle.api.JavaVersion | ||
import org.gradle.api.Project | ||
import org.gradle.api.plugins.JavaPluginExtension | ||
import org.gradle.kotlin.dsl.configure | ||
import org.gradle.kotlin.dsl.dependencies | ||
import org.gradle.kotlin.dsl.provideDelegate | ||
import org.gradle.kotlin.dsl.withType | ||
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile | ||
|
||
/** | ||
* Configure base Kotlin with Android options | ||
*/ | ||
internal fun Project.configureKotlinAndroid( | ||
commonExtension: CommonExtension<*, *, *, *, *, *>, | ||
) { | ||
commonExtension.apply { | ||
compileSdk = 34 | ||
|
||
defaultConfig { | ||
minSdk = 21 | ||
} | ||
|
||
compileOptions { | ||
sourceCompatibility = JavaVersion.VERSION_17 | ||
targetCompatibility = JavaVersion.VERSION_17 | ||
} | ||
} | ||
|
||
configureKotlin() | ||
|
||
dependencies { | ||
// add("coreLibraryDesugaring", libs.findLibrary("android.desugarJdkLibs").get()) | ||
} | ||
} | ||
|
||
/** | ||
* Configure base Kotlin options for JVM (non-Android) | ||
*/ | ||
internal fun Project.configureKotlinJvm() { | ||
extensions.configure<JavaPluginExtension> { | ||
sourceCompatibility = JavaVersion.VERSION_17 | ||
targetCompatibility = JavaVersion.VERSION_17 | ||
} | ||
|
||
configureKotlin() | ||
} | ||
|
||
/** | ||
* Configure base Kotlin options | ||
*/ | ||
private fun Project.configureKotlin() { | ||
// Use withType to workaround https://youtrack.jetbrains.com/issue/KT-55947 | ||
tasks.withType<KotlinCompile>().configureEach { | ||
kotlinOptions { | ||
// Set JVM target to 11 | ||
jvmTarget = JavaVersion.VERSION_17.toString() | ||
// Treat all Kotlin warnings as errors (disabled by default) | ||
// Override by setting warningsAsErrors=true in your ~/.gradle/gradle.properties | ||
val warningsAsErrors: String? by project | ||
allWarningsAsErrors = warningsAsErrors.toBoolean() | ||
freeCompilerArgs = freeCompilerArgs + listOf( | ||
// Enable experimental coroutines APIs, including Flow | ||
"-opt-in=kotlinx.coroutines.ExperimentalCoroutinesApi", | ||
) | ||
} | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
build-logic/convention/src/main/kotlin/ir/zinutech/android/flickrSearch/ProjectExtensions.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package ir.zinutech.android.flickrSearch | ||
|
||
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") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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=true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
dependencyResolutionManagement { | ||
repositories { | ||
google() | ||
mavenCentral() | ||
} | ||
versionCatalogs { | ||
create("libs") { | ||
from(files("../gradle/libs.versions.toml")) | ||
} | ||
} | ||
} | ||
|
||
rootProject.name = "build-logic" | ||
include(":convention") |
Oops, something went wrong.