Skip to content

Commit

Permalink
Adds android app and lib conventions (#9)
Browse files Browse the repository at this point in the history
* Creates initial app convention

* Creates initial lib convention

* Adds plugin accessors
  • Loading branch information
kyhule authored Jun 7, 2023
1 parent 8512ad6 commit 7b0022c
Show file tree
Hide file tree
Showing 8 changed files with 455 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ modules.xml
### Gradle ###
.gradle
**/build/
!src/**/build/
!**/src/**/build/

# Ignore Gradle GUI config
gradle-app.setting
Expand Down
28 changes: 28 additions & 0 deletions conventions/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,37 @@ publishing {

dependencies {
compileOnly(gradleApi())
implementation(libs.gradlePlugin.android)
implementation(libs.gradlePlugin.dependencyAnalysis)
implementation(libs.gradlePlugin.doctor)
implementation(libs.gradlePlugin.githubRelease)
implementation(libs.gradlePlugin.kotlin)
implementation(libs.gradlePlugin.mavenPublish)
implementation(libs.gradlePlugin.reckon)
}

// Add a source set for the functional test suite
val functionalTestSourceSet = sourceSets.create("functionalTest") {
}

configurations["functionalTestImplementation"].extendsFrom(configurations["testImplementation"])

// Add a task to run the functional tests
val functionalTest by tasks.registering(Test::class) {
testClassesDirs = functionalTestSourceSet.output.classesDirs
classpath = functionalTestSourceSet.runtimeClasspath
useJUnitPlatform()
}

gradlePlugin.testSourceSets.add(functionalTestSourceSet)

tasks.named<Task>("check") {
// Run the functional tests as part of `check`
dependsOn(functionalTest)
}

tasks.named<Test>("test") {
// Use JUnit Jupiter for unit tests.
useJUnitPlatform()
}

8 changes: 8 additions & 0 deletions conventions/src/main/kotlin/PluginAccessors.kt
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
@file:Suppress("unused")

import org.gradle.plugin.use.PluginDependenciesSpec
import org.gradle.plugin.use.PluginDependencySpec

val PluginDependenciesSpec.`polyworld-android-app`: PluginDependencySpec
get() = polyworld("android-app")

val PluginDependenciesSpec.`polyworld-android-lib`: PluginDependencySpec
get() = polyworld("android-lib")
val PluginDependenciesSpec.`polyworld-root`: PluginDependencySpec
get() = polyworld("root")

internal fun PluginDependenciesSpec.polyworld(
name: String,
version: String? = null
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import com.github.kyhule.polyworld.build.jdkVersion
import com.github.kyhule.polyworld.build.compileSdkVersion as polyCompileSdkVersion
import com.github.kyhule.polyworld.build.minSdkVersion
import com.github.kyhule.polyworld.build.targetSdkVersion

plugins {
id("com.android.application")
id("kotlin-android")
}

android {
compileSdk = polyCompileSdkVersion

defaultConfig {
minSdk = minSdkVersion
targetSdk = targetSdkVersion
}

buildTypes {
debug {
matchingFallbacks.add("release")
}
}

compileOptions {
sourceCompatibility = JavaVersion.toVersion(jdkVersion)
targetCompatibility = JavaVersion.toVersion(jdkVersion)
}

kotlinOptions {
jvmTarget = jdkVersion.toString()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import com.github.kyhule.polyworld.build.jdkVersion
import com.github.kyhule.polyworld.build.compileSdkVersion as polyCompileSdkVersion
import com.github.kyhule.polyworld.build.minSdkVersion
import com.github.kyhule.polyworld.build.targetSdkVersion

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

android {
compileSdk = polyCompileSdkVersion

defaultConfig {
minSdk = minSdkVersion
targetSdk = targetSdkVersion
}

buildTypes {
debug {
matchingFallbacks.add("release")
}
}

compileOptions {
sourceCompatibility = JavaVersion.toVersion(jdkVersion)
targetCompatibility = JavaVersion.toVersion(jdkVersion)
}

kotlinOptions {
jvmTarget = jdkVersion.toString()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.github.kyhule.polyworld.build

import com.github.kyhule.polyworld.build.util.*
import com.github.kyhule.polyworld.build.util.booleanProperty
import com.github.kyhule.polyworld.build.util.longProperty
import org.gradle.api.Project


val Project.compileSdkVersion: Int
get() = intProperty("polyworld.compileSdkVersion", defaultValue = 33)

val Project.minSdkVersion: Int
get() = intProperty("polyworld.minSdkVersion", defaultValue = 24)

val Project.targetSdkVersion: Int
get() = intProperty("polyworld.targetSdkVersion", defaultValue = 33)

val Project.jdkVersion: Int
get() = intProperty("polyworld.jdkVersion", defaultValue = 17)

/** Flag to enable verbose logging in unit tests. */
val Project.testVerboseLogging: Boolean
get() = booleanProperty("polyworld.test.verboseLogging")

/**
* Property corresponding to the number unit tests to run on a fork before it is disposed.
* This helps when tests leak memory.
*
* **See Also:** [Forking options](https://docs.gradle.org/current/userguide/performance.html#forking_options)
*/
val Project.testForkEvery: Long
get() = longProperty("polyworld.test.forkEvery", defaultValue = 100L)
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package com.github.kyhule.polyworld.build.util

import org.gradle.api.file.ConfigurableFileCollection
import org.gradle.api.provider.ListProperty
import org.gradle.api.provider.MapProperty
import org.gradle.api.provider.Property
import org.gradle.api.provider.Provider
import org.gradle.api.provider.SetProperty

/*
* APIs adapted from `HasConfigurableValues.kt` in AGP. Copied for binary safety.
*/

internal fun ConfigurableFileCollection.fromDisallowChanges(vararg arg: Any) {
from(*arg)
disallowChanges()
}

internal fun <T> Property<T>.setDisallowChanges(value: T?) {
set(value)
disallowChanges()
}

internal fun <T> Property<T>.setDisallowChanges(value: Provider<out T>) {
set(value)
disallowChanges()
}

internal fun <T> ListProperty<T>.setDisallowChanges(value: Provider<out Iterable<T>>) {
set(value)
disallowChanges()
}

internal fun <T> ListProperty<T>.setDisallowChanges(value: Iterable<T>?) {
set(value)
disallowChanges()
}

internal fun <K, V> MapProperty<K, V>.setDisallowChanges(map: Provider<Map<K, V>>) {
set(map)
disallowChanges()
}

internal fun <K, V> MapProperty<K, V>.setDisallowChanges(map: Map<K, V>?) {
set(map)
disallowChanges()
}

internal fun <T> SetProperty<T>.setDisallowChanges(value: Provider<out Iterable<T>>) {
set(value)
disallowChanges()
}

internal fun <T> SetProperty<T>.setDisallowChanges(value: Iterable<T>?) {
set(value)
disallowChanges()
}

internal fun <T> ListProperty<T>.setDisallowChanges(
value: Provider<out Iterable<T>>?,
handleNullable: ListProperty<T>.() -> Unit
) {
value?.let { set(value) } ?: handleNullable()
disallowChanges()
}

internal fun <K, V> MapProperty<K, V>.setDisallowChanges(
map: Provider<Map<K, V>>?,
handleNullable: MapProperty<K, V>.() -> Unit
) {
map?.let { set(map) } ?: handleNullable()
disallowChanges()
}
Loading

0 comments on commit 7b0022c

Please sign in to comment.