diff options
author | Allan Wang <me@allanwang.ca> | 2018-01-24 23:44:49 -0500 |
---|---|---|
committer | Allan Wang <me@allanwang.ca> | 2018-01-24 23:44:49 -0500 |
commit | 3a92363e65a29b6106cdfa98d6bcf297b0eda5ad (patch) | |
tree | 9c61fbce5d486374aad1e7767ebc2ee6f67348cc /buildSrc | |
parent | 9c00231884c69456c2deb2918cd0ecd50f3ac0a0 (diff) | |
download | kau-3a92363e65a29b6106cdfa98d6bcf297b0eda5ad.tar.gz kau-3a92363e65a29b6106cdfa98d6bcf297b0eda5ad.tar.bz2 kau-3a92363e65a29b6106cdfa98d6bcf297b0eda5ad.zip |
Create buildSrc
Diffstat (limited to 'buildSrc')
-rw-r--r-- | buildSrc/.gitignore | 2 | ||||
-rw-r--r-- | buildSrc/README.md | 92 | ||||
-rw-r--r-- | buildSrc/build.gradle | 9 | ||||
-rw-r--r-- | buildSrc/src/main/groovy/ca/allanwang/kau/ChangelogGenerator.groovy | 76 | ||||
-rw-r--r-- | buildSrc/src/main/groovy/ca/allanwang/kau/Dependencies.groovy | 10 | ||||
-rw-r--r-- | buildSrc/src/main/groovy/ca/allanwang/kau/KauPlugin.groovy | 16 | ||||
-rw-r--r-- | buildSrc/src/main/groovy/ca/allanwang/kau/Plugins.groovy | 13 | ||||
-rw-r--r-- | buildSrc/src/main/groovy/ca/allanwang/kau/Versions.groovy | 37 | ||||
-rw-r--r-- | buildSrc/src/main/resources/META-INF/gradle-plugins/ca.allanwang.kau.properties | 1 |
9 files changed, 256 insertions, 0 deletions
diff --git a/buildSrc/.gitignore b/buildSrc/.gitignore new file mode 100644 index 0000000..192221b --- /dev/null +++ b/buildSrc/.gitignore @@ -0,0 +1,2 @@ +.gradle/ +build/
\ No newline at end of file diff --git a/buildSrc/README.md b/buildSrc/README.md new file mode 100644 index 0000000..60d2dfc --- /dev/null +++ b/buildSrc/README.md @@ -0,0 +1,92 @@ +# KAU :gradle-plugin + +> Plugin helper for KAU + +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. +Everything here is used when generating the library, so it's always tested. + +## Contents +* [Versions](#versions) +* [Plugins](#plugins) +* [Dependencies](#dependencies) +* [Changelog Generator](#changelog-generator) + +## Usage + +Firstly, add KAU to the buildscript: + +```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 + +```gradle +api "com.android.support:appcompat-v7:${kau.supportLibs}" +``` + +# Plugins + +> [Plugins.groovy](/buildSrc/src/main/groovy/ca/allanwang/kau/Plugins.groovy) + +Unfortunately, it seems like you can't use the plugin directly in the buildscript, so this is mainly internal. + +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. + +# 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 + +```gradle +testImplementation kauDependency.junit +``` + +# Changelog Generator + +In conjunction with [core](/core#changelog-xml), +the xml changelog can be converted to markdown. + +To allow for compilation per build, add your own task: + +```gradle +task generateChangelogMd() { + kauChangelog.generate([inputPath], [outputPath]) +} +``` + +The wrapper allows for the generator to be called automatically with each build. + + + diff --git a/buildSrc/build.gradle b/buildSrc/build.gradle new file mode 100644 index 0000000..a51e9ae --- /dev/null +++ b/buildSrc/build.gradle @@ -0,0 +1,9 @@ +apply plugin: 'groovy' +apply plugin: 'maven' + +group = "ca.allanwang" + +dependencies { + compile gradleApi() + compile localGroovy() +}
\ No newline at end of file diff --git a/buildSrc/src/main/groovy/ca/allanwang/kau/ChangelogGenerator.groovy b/buildSrc/src/main/groovy/ca/allanwang/kau/ChangelogGenerator.groovy new file mode 100644 index 0000000..bb56fa2 --- /dev/null +++ b/buildSrc/src/main/groovy/ca/allanwang/kau/ChangelogGenerator.groovy @@ -0,0 +1,76 @@ +package ca.allanwang.kau + +import org.gradle.api.GradleException +import org.gradle.api.Project + +/** + * Given an xml of the format + * + * <?xml version="1.0" encoding="utf-8"?> + * <resources> + * <version title="v0.1" /> + * <item text="Initial Changelog" /> + * <item text="Bullet point here" /> + * <item text="More points" /> + * <item text="" /> <!-- this one is empty and therefore ignored --> + * </resources> + * + * Outputs a changelog in markdown format + */ +class ChangelogGenerator { + + static class ChangelogException extends GradleException { + ChangelogException(String message) { + super(message) + } + } + + private Project project + + ChangelogGenerator(Project project) { + this.project = project + } + + private static void fail(String message) { + throw new ChangelogException(message) + } + + final void generate(String inputUri, String outputUri = "$project.rootDir/docs/Changelog.md") { + def input = new File(inputUri) + if (!input.exists()) + fail("Could not generate changelog from ${input.absolutePath}") + + def output = new File(outputUri) + + if (output.exists()) { + if (output.isDirectory()) + fail("Cannot save changelog at directory ${output.absolutePath}") + + + if (output.isFile() && !output.delete()) + fail("Could not delete changelog at ${output.absolutePath}") + } else { + output.parentFile.mkdirs() + } + + if (!output.createNewFile()) + fail("Could not create changelog file at ${output.absolutePath}") + + def parsedProjectXml = (new XmlParser()).parse(inputUri) + def sw = new StringWriter() + sw.append("# Changelog\n") + parsedProjectXml.depthFirst().each { + switch (it.name()) { + case "version": + sw.append("\n## ${it.@title}\n") + break + case "item": + if (it.@text?.trim()) + sw.append("* ${it.@text}\n") + } + } + output.write(sw.toString()) + println("Generated changelog at ${output.absolutePath}") + } + +}
\ No newline at end of file diff --git a/buildSrc/src/main/groovy/ca/allanwang/kau/Dependencies.groovy b/buildSrc/src/main/groovy/ca/allanwang/kau/Dependencies.groovy new file mode 100644 index 0000000..368b0a8 --- /dev/null +++ b/buildSrc/src/main/groovy/ca/allanwang/kau/Dependencies.groovy @@ -0,0 +1,10 @@ +package ca.allanwang.kau + +/** + * Some common dependencies, backed by the supplied versions + */ +class Dependencies { + static def kotlin = "org.jetbrains.kotlin:kotlin-stdlib:${Versions.kotlin}" + static def kotlinTest = "org.jetbrains.kotlin:kotlin-test-junit:${Versions.kotlin}" + static def junit = "junit:junit:${Versions.junit}" +}
\ No newline at end of file diff --git a/buildSrc/src/main/groovy/ca/allanwang/kau/KauPlugin.groovy b/buildSrc/src/main/groovy/ca/allanwang/kau/KauPlugin.groovy new file mode 100644 index 0000000..e73564c --- /dev/null +++ b/buildSrc/src/main/groovy/ca/allanwang/kau/KauPlugin.groovy @@ -0,0 +1,16 @@ +package ca.allanwang.kau + +import org.gradle.api.Plugin +import org.gradle.api.Project + +class KauPlugin implements Plugin<Project> { + + @Override + void apply(Project project) { + project.extensions.create("kau", Versions) + project.extensions.create("kauPlugin", Plugins) + project.extensions.create("kauDependency", Dependencies) + project.extensions.create("kauChangelog", ChangelogGenerator, project) + } + +}
\ No newline at end of file diff --git a/buildSrc/src/main/groovy/ca/allanwang/kau/Plugins.groovy b/buildSrc/src/main/groovy/ca/allanwang/kau/Plugins.groovy new file mode 100644 index 0000000..040e2a2 --- /dev/null +++ b/buildSrc/src/main/groovy/ca/allanwang/kau/Plugins.groovy @@ -0,0 +1,13 @@ +package ca.allanwang.kau + +/** + * Some common buildscript plugins, backed by the supplied versions + */ +class Plugins { + static def android = "com.android.tools.build:gradle:${Versions.gradlePlugin}" + static def kotlin = "org.jetbrains.kotlin:kotlin-gradle-plugin:${Versions.kotlin}" + static def androidMaven = "com.github.dcendents:android-maven-gradle-plugin:${Versions.mavenPlugin}" + static def playPublisher = "com.github.triplet.gradle:play-publisher:${Versions.playPublishPlugin}" + static def dexCount = "com.getkeepsafe.dexcount:dexcount-gradle-plugin:${Versions.dexCountPlugin}" + static def gitVersion = "gradle.plugin.com.gladed.gradle.androidgitversion:gradle-android-git-version:${Versions.gitVersionPlugin}" +}
\ No newline at end of file diff --git a/buildSrc/src/main/groovy/ca/allanwang/kau/Versions.groovy b/buildSrc/src/main/groovy/ca/allanwang/kau/Versions.groovy new file mode 100644 index 0000000..4633a4d --- /dev/null +++ b/buildSrc/src/main/groovy/ca/allanwang/kau/Versions.groovy @@ -0,0 +1,37 @@ +package ca.allanwang.kau + +class Versions { + static def coreMinSdk = 19 + static def minSdk = 21 + static def targetSdk = 27 + + static def buildTools = '27.0.2' + static def supportLibs = '27.0.2' + + static def kotlin = '1.2.21' + + static def aboutLibraries = '6.0.1' + static def anko = '0.10.4' + static def blurry = '2.1.1' + static def constraintLayout = '1.1.0-beta4' + static def fastAdapter = '3.1.2' + static def fastAdapterCommons = '3.1.2' + static def glide = '4.5.0' + + static def iconics = '3.0.2' + static def iconicsGoogle = '3.0.1.2' + static def iconicsMaterial = '2.2.0.4' + static def iconicsCommunity = '2.0.46.1' + + static def materialDialog = '0.9.6.0' + + static def espresso = '3.0.0' + static def junit = '4.12' + static def testRunner = '1.0.0' + + static def gradlePlugin = '3.0.1' + static def mavenPlugin = '2.0' + static def playPublishPlugin = '1.2.0' + static def dexCountPlugin = '0.8.2' + static def gitVersionPlugin = '0.4.3' +}
\ No newline at end of file diff --git a/buildSrc/src/main/resources/META-INF/gradle-plugins/ca.allanwang.kau.properties b/buildSrc/src/main/resources/META-INF/gradle-plugins/ca.allanwang.kau.properties new file mode 100644 index 0000000..ba824cd --- /dev/null +++ b/buildSrc/src/main/resources/META-INF/gradle-plugins/ca.allanwang.kau.properties @@ -0,0 +1 @@ +implementation-class=ca.allanwang.kau.KauPlugin
\ No newline at end of file |