diff options
author | Allan Wang <me@allanwang.ca> | 2019-06-07 16:13:51 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-06-07 16:13:51 -0400 |
commit | 065f2db88e4b87b53b3216a5313d5e1e22fa2867 (patch) | |
tree | d03866b74ef8146dbd900d20994de47a0de6c705 /buildSrc | |
parent | eb9317015c6535bfa36166d254ec954f81d8df97 (diff) | |
parent | d30cdac9ca74ca5e202c681af228fa4ca3a8e389 (diff) | |
download | kau-065f2db88e4b87b53b3216a5313d5e1e22fa2867.tar.gz kau-065f2db88e4b87b53b3216a5313d5e1e22fa2867.tar.bz2 kau-065f2db88e4b87b53b3216a5313d5e1e22fa2867.zip |
Merge pull request #202 from AllanWang/plugin-object
Plugin object
Diffstat (limited to 'buildSrc')
-rw-r--r-- | buildSrc/README.md | 72 | ||||
-rw-r--r-- | buildSrc/build.gradle.kts | 11 | ||||
-rw-r--r-- | buildSrc/src/main/kotlin/ca/allanwang/kau/Dependencies.kt | 14 | ||||
-rw-r--r-- | buildSrc/src/main/kotlin/ca/allanwang/kau/KauPlugin.kt | 17 | ||||
-rw-r--r-- | buildSrc/src/main/kotlin/ca/allanwang/kau/Plugins.kt | 15 | ||||
-rw-r--r-- | buildSrc/src/main/kotlin/kau/ChangelogGenerator.kt (renamed from buildSrc/src/main/kotlin/ca/allanwang/kau/ChangelogGenerator.kt) | 10 | ||||
-rw-r--r-- | buildSrc/src/main/kotlin/kau/Dependencies.kt | 13 | ||||
-rw-r--r-- | buildSrc/src/main/kotlin/kau/Plugins.kt | 14 | ||||
-rw-r--r-- | buildSrc/src/main/kotlin/kau/Versions.kt (renamed from buildSrc/src/main/kotlin/ca/allanwang/kau/Versions.kt) | 66 |
9 files changed, 88 insertions, 144 deletions
diff --git a/buildSrc/README.md b/buildSrc/README.md index 91a60ac..14ae3d6 100644 --- a/buildSrc/README.md +++ b/buildSrc/README.md @@ -5,75 +5,47 @@ KAU holds quite a big collection of projects, with the intent on making it easy to reuse complex features, and also to update. This plugin aims to help maintain version updates straight from the source, and also adds on a few nice functions. -As a note, this is located under `buildSrc` as it is automatically included when building KAU. +As a note, this is located under `buildSrc` as it is automatically included when building Everything here is used when generating the library, so it's always tested. ## Contents -* [Versions](#versions) -* [Plugins](#plugins) -* [Dependencies](#dependencies) +* [Usage](#usage) +* [Constants](#constants) * [Changelog Generator](#changelog-generator) ## Usage -Firstly, add KAU to the buildscript: +The easiest way to use this is to create your own `buildSrc` folder, and include `ca.allanwang.kau:gradle-plugin:${KAU}` as a dependency. +This way, you can also use items in your buildscript. +You can also add your own classes to manage versions in your app. -```gradle -buildscript { - repositories { - ... - maven { url "https://jitpack.io" } - } - - dependencies { - ... - classpath "ca.allanwang:kau:${KAU}" - } -} -``` - -Then where necessary, apply the plugin using - -```gradle -apply plugin: 'ca.allanwang.kau' -``` - -# Versions - -> [Versions.groovy](/buildSrc/src/main/groovy/ca/allanwang/kau/Versions.groovy) - -Contains the version code for any external library used in KAU. -You are free to use the values through `kau.[tagName]`. - -As an example, AppCompat is imported in KAU using +When making your own `buildSrc`, make sure you add the jitpack repository: ```gradle -api "androidx.appcompat:appcompat:${kau.appcompat}" +repositories { + ... + maven { url "https://jitpack.io" } +} ``` -# Plugins +--- -> [Plugins.groovy](/buildSrc/src/main/groovy/ca/allanwang/kau/Plugins.groovy) +Currently, the plugin is a collection of simple classes. -Unfortunately, it seems like you can't use the plugin directly in the buildscript, so this is mainly internal. +## Constants -The plugins data, found using `kauPlugins.[tagName]` contains a collection of useful plugin classpaths. -The versions are taken from `Versions.groovy`, so it is always in sync. +`Versions`, `Plugins`, and `Dependencies` supply constants you can use for your classpath and dependencies -# Dependencies - -> [Dependencies.groovy](/buildSrc/src/main/groovy/ca/allanwang/kau/Dependencies.groovy) - -Contains the dependency string for common libraries. -You are free to use the values through `kauDependency.[tagName]`. - -As an example, adding junit can be done through +Eg ```gradle -testImplementation kauDependency.junit +dependencies { + ... + implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:${kau.Versions.coroutines}" +} ``` -# Changelog Generator +## Changelog Generator In conjunction with [core](/core#changelog-xml), the xml changelog can be converted to markdown. @@ -82,7 +54,7 @@ To allow for compilation per build, add your own task: ```gradle task generateChangelogMd() { - kauChangelog.generate([inputPath], [outputPath]) + kau.ChangelogGenerator.generate([inputPath], [outputPath]) } ``` diff --git a/buildSrc/build.gradle.kts b/buildSrc/build.gradle.kts index 83a3370..89cba29 100644 --- a/buildSrc/build.gradle.kts +++ b/buildSrc/build.gradle.kts @@ -5,15 +5,6 @@ plugins { group = "ca.allanwang" -gradlePlugin { - plugins { - register("kau-plugin") { - id = "ca.allanwang.kau" - implementationClass = "ca.allanwang.kau.KauPlugin" - } - } -} - repositories { - mavenCentral() + jcenter() }
\ No newline at end of file diff --git a/buildSrc/src/main/kotlin/ca/allanwang/kau/Dependencies.kt b/buildSrc/src/main/kotlin/ca/allanwang/kau/Dependencies.kt deleted file mode 100644 index 9e23ac4..0000000 --- a/buildSrc/src/main/kotlin/ca/allanwang/kau/Dependencies.kt +++ /dev/null @@ -1,14 +0,0 @@ -package ca.allanwang.kau - -/** - * Some common dependencies, backed by the supplied versions - */ -open class Dependencies { - private val v = Versions() - val kotlin = "org.jetbrains.kotlin:kotlin-stdlib:${v.kotlin}" - val kotlinTest = "org.jetbrains.kotlin:kotlin-test-junit:${v.kotlin}" - val junit = "junit:junit:${v.junit}" - val espresso = "androidx.test.espresso:espresso-core:${v.espresso}" - val testRunner = "androidx.test.ext:junit:${v.testRunner}" - val testRules = "androidx.test:rules:${v.testRules}" -}
\ No newline at end of file diff --git a/buildSrc/src/main/kotlin/ca/allanwang/kau/KauPlugin.kt b/buildSrc/src/main/kotlin/ca/allanwang/kau/KauPlugin.kt deleted file mode 100644 index 6be15e5..0000000 --- a/buildSrc/src/main/kotlin/ca/allanwang/kau/KauPlugin.kt +++ /dev/null @@ -1,17 +0,0 @@ -package ca.allanwang.kau - -import org.gradle.api.Plugin -import org.gradle.api.Project -import org.gradle.kotlin.dsl.create - -class KauPlugin : Plugin<Project> { - - override fun apply(project: Project) { - project.extensions.run { - create<Versions>("kau") - create<Dependencies>("kauDependency") - create<Plugins>("kauPlugin") - create<ChangelogGenerator>("kauChangelog", project) - } - } -}
\ No newline at end of file diff --git a/buildSrc/src/main/kotlin/ca/allanwang/kau/Plugins.kt b/buildSrc/src/main/kotlin/ca/allanwang/kau/Plugins.kt deleted file mode 100644 index 30caad7..0000000 --- a/buildSrc/src/main/kotlin/ca/allanwang/kau/Plugins.kt +++ /dev/null @@ -1,15 +0,0 @@ -package ca.allanwang.kau - -/** - * Some common buildscript plugins, backed by the supplied versions - */ -open class Plugins { - private val v = Versions() - val android = "com.android.tools.build:gradle:${v.gradlePlugin}" - val kotlin = "org.jetbrains.kotlin:kotlin-gradle-plugin:${v.kotlin}" - val androidMaven = "com.github.dcendents:android-maven-gradle-plugin:${v.mavenPlugin}" - val playPublisher = "com.github.triplet.gradle:play-publisher:${v.playPublishPlugin}" - val dexCount = "com.getkeepsafe.dexcount:dexcount-gradle-plugin:${v.dexCountPlugin}" - val gitVersion = "com.gladed.androidgitversion:gradle-android-git-version:${v.gitVersionPlugin}" - val spotless = "com.diffplug.spotless:spotless-plugin-gradle:${v.spotless}" -}
\ No newline at end of file diff --git a/buildSrc/src/main/kotlin/ca/allanwang/kau/ChangelogGenerator.kt b/buildSrc/src/main/kotlin/kau/ChangelogGenerator.kt index 5e21b7e..20e8eef 100644 --- a/buildSrc/src/main/kotlin/ca/allanwang/kau/ChangelogGenerator.kt +++ b/buildSrc/src/main/kotlin/kau/ChangelogGenerator.kt @@ -1,9 +1,8 @@ -package ca.allanwang.kau +package kau import groovy.util.Node import groovy.util.XmlParser import org.gradle.api.GradleException -import org.gradle.api.Project import java.io.File /** @@ -20,7 +19,7 @@ import java.io.File * * Outputs a changelog in markdown format */ -open class ChangelogGenerator(private val project: Project) { +object ChangelogGenerator { class ChangelogException(message: String) : GradleException(message) @@ -35,6 +34,7 @@ open class ChangelogGenerator(private val project: Project) { } } + @JvmStatic fun read(inputUri: String): List<ChangelogEntry> { val input = File(inputUri) if (!input.exists()) { @@ -71,8 +71,8 @@ open class ChangelogGenerator(private val project: Project) { return entries } - @JvmOverloads - fun generate(inputUri: String, outputUri: String = "${project.rootDir}/docs/Changelog.md"): List<ChangelogEntry> { + @JvmStatic + fun generate(inputUri: String, outputUri: String): List<ChangelogEntry> { val entries = read(inputUri) val output = File(outputUri) if (output.exists()) { diff --git a/buildSrc/src/main/kotlin/kau/Dependencies.kt b/buildSrc/src/main/kotlin/kau/Dependencies.kt new file mode 100644 index 0000000..62c938c --- /dev/null +++ b/buildSrc/src/main/kotlin/kau/Dependencies.kt @@ -0,0 +1,13 @@ +package kau + +/** + * Some common dependencies, backed by the supplied versions + */ +object Dependencies { + const val kotlin = "org.jetbrains.kotlin:kotlin-stdlib:${Versions.kotlin}" + const val kotlinTest = "org.jetbrains.kotlin:kotlin-test-junit:${Versions.kotlin}" + const val junit = "junit:junit:${Versions.junit}" + const val espresso = "androidx.test.espresso:espresso-core:${Versions.espresso}" + const val testRunner = "androidx.test.ext:junit:${Versions.testRunner}" + const val testRules = "androidx.test:rules:${Versions.testRules}" +}
\ No newline at end of file diff --git a/buildSrc/src/main/kotlin/kau/Plugins.kt b/buildSrc/src/main/kotlin/kau/Plugins.kt new file mode 100644 index 0000000..cdee364 --- /dev/null +++ b/buildSrc/src/main/kotlin/kau/Plugins.kt @@ -0,0 +1,14 @@ +package kau + +/** + * Some common buildscript plugins, backed by the supplied versions + */ +object Plugins { + const val android = "com.android.tools.build:gradle:${Versions.gradlePlugin}" + const val kotlin = "org.jetbrains.kotlin:kotlin-gradle-plugin:${Versions.kotlin}" + const val androidMaven = "com.github.dcendents:android-maven-gradle-plugin:${Versions.mavenPlugin}" + const val playPublisher = "com.github.triplet.gradle:play-publisher:${Versions.playPublishPlugin}" + const val dexCount = "com.getkeepsafe.dexcount:dexcount-gradle-plugin:${Versions.dexCountPlugin}" + const val gitVersion = "com.gladed.androidgitversion:gradle-android-git-version:${Versions.gitVersionPlugin}" + const val spotless = "com.diffplug.spotless:spotless-plugin-gradle:${Versions.spotless}" +}
\ No newline at end of file diff --git a/buildSrc/src/main/kotlin/ca/allanwang/kau/Versions.kt b/buildSrc/src/main/kotlin/kau/Versions.kt index d48e236..32db3a5 100644 --- a/buildSrc/src/main/kotlin/ca/allanwang/kau/Versions.kt +++ b/buildSrc/src/main/kotlin/kau/Versions.kt @@ -1,80 +1,80 @@ -package ca.allanwang.kau +package kau -open class Versions { - val coreMinSdk = 19 - val minSdk = 21 - val targetSdk = 28 +object Versions { + const val coreMinSdk = 19 + const val minSdk = 21 + const val targetSdk = 28 // https://developer.android.com/studio/releases/build-tools - val buildTools = "28.0.3" + const val buildTools = "28.0.3" // https://mvnrepository.com/artifact/androidx.appcompat/appcompat?repo=google - val appcompat = "1.0.2" + const val appcompat = "1.0.2" // https://mvnrepository.com/artifact/com.google.android.material/material - val googleMaterial = "1.0.0" + const val googleMaterial = "1.0.0" // https://mvnrepository.com/artifact/androidx.recyclerview/recyclerview - val recyclerView = "1.0.0" + const val recyclerView = "1.0.0" // https://mvnrepository.com/artifact/androidx.cardview/cardview - val cardView = "1.0.0" + const val cardView = "1.0.0" // https://mvnrepository.com/artifact/androidx.constraintlayout/constraintlayout - val constraintLayout = "1.1.3" + const val constraintLayout = "1.1.3" // https://kotlinlang.org/docs/reference/using-gradle.html - val kotlin = "1.3.31" + const val kotlin = "1.3.31" // https://github.com/Kotlin/kotlinx.coroutines/releases - val coroutines = "1.3.0-M1" + const val coroutines = "1.3.0-M1" // https://github.com/mikepenz/AboutLibraries/releases - val aboutLibraries = "6.2.3" + const val aboutLibraries = "6.2.3" // https://github.com/wasabeef/Blurry/releases - val blurry = "3.0.0" + const val blurry = "3.0.0" // https://github.com/mikepenz/FastAdapter#using-maven - val fastAdapter = "3.3.1" - val fastAdapterCommons = fastAdapter + const val fastAdapter = "3.3.1" + const val fastAdapterCommons = fastAdapter // https://github.com/bumptech/glide/releases - val glide = "4.9.0" + const val glide = "4.9.0" // https://github.com/mikepenz/Android-Iconics#1-provide-the-gradle-dependency - val iconics = "3.2.5" - val iconicsGoogle = "3.0.1.3" - val iconicsMaterial = "2.2.0.5" - val iconicsCommunity = "3.5.95.1" + const val iconics = "3.2.5" + const val iconicsGoogle = "3.0.1.3" + const val iconicsMaterial = "2.2.0.5" + const val iconicsCommunity = "3.5.95.1" // https://github.com/afollestad/material-dialogs/releases - val materialDialog = "3.0.0-rc2" + const val materialDialog = "3.0.0-rc2" // https://mvnrepository.com/artifact/androidx.test.espresso/espresso-core?repo=google - val espresso = "3.1.1" + const val espresso = "3.1.1" // https://mvnrepository.com/artifact/org.junit.jupiter/junit-jupiter-api - val junit = "4.12" + const val junit = "4.12" - val testRunner = "1.1.0" + const val testRunner = "1.1.0" // https://mvnrepository.com/artifact/androidx.test/rules?repo=google - val testRules = "1.1.1" + const val testRules = "1.1.1" // https://github.com/diffplug/spotless/blob/master/plugin-gradle/CHANGES.md - val spotless = "3.18.0" + const val spotless = "3.18.0" // https://mvnrepository.com/artifact/com.android.tools.build/gradle?repo=google - val gradlePlugin = "3.4.1" + const val gradlePlugin = "3.4.1" // https://github.com/dcendents/android-maven-gradle-plugin/releases - val mavenPlugin = "2.1" + const val mavenPlugin = "2.1" // https://github.com/Triple-T/gradle-play-publisher/releases - val playPublishPlugin = "2.2.1" + const val playPublishPlugin = "2.2.1" // https://github.com/KeepSafe/dexcount-gradle-plugin/releases - val dexCountPlugin = "0.8.6" + const val dexCountPlugin = "0.8.6" // https://github.com/gladed/gradle-android-git-version/releases - val gitVersionPlugin = "0.4.9" + const val gitVersionPlugin = "0.4.9" }
\ No newline at end of file |