Skip to content

Commit

Permalink
Improve buildscript
Browse files Browse the repository at this point in the history
  • Loading branch information
gsantner committed Nov 18, 2017
1 parent b6b4b28 commit cd88bb6
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 41 deletions.
79 changes: 44 additions & 35 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,29 +1,22 @@
apply plugin: 'com.android.application'

ext {
version_sdk = [
compileSdk: 27,
minSdk : 14,
]
version_lib = [
appcompat: "27.0.0",
butterknife: "8.8.1",
commonmark: "0.10.0",
]
if (enable_plugin_kotlin) {
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
}

ext.version_setup_minSdk = 14

android {
compileSdkVersion version_sdk.compileSdk
compileSdkVersion version_setup_compileSdk
flavorDimensions "default"

defaultConfig {
minSdkVersion version_sdk.minSdk
targetSdkVersion version_sdk.compileSdk
minSdkVersion version_setup_minSdk
targetSdkVersion version_setup_targetSdk
buildConfigField "boolean", "IS_TEST_BUILD", "false"
buildConfigField "boolean", "IS_GPLAY_BUILD", "false"
buildConfigField("String[]", "APPLICATION_LANGUAGES", '{' + getUsedAndroidLanguages().collect {
"\"${it}\""
}.join(",") + '}')
buildConfigField "String[]", "APPLICATION_LANGUAGES", "${getUsedAndroidLanguages()}"
buildConfigField "String", "GITHASH", "\"${getGitHash()}\""

applicationId "net.gsantner.markor"
Expand All @@ -43,6 +36,12 @@ android {
}
}

sourceSets {
if (enable_plugin_kotlin) {
main.java.srcDirs += 'src/main/kotlin'
}
}

productFlavors {
flavorDefault {
}
Expand All @@ -63,33 +62,43 @@ android {
}

dependencies {
// Testing
testImplementation 'junit:junit:4.12'
testImplementation 'org.assertj:assertj-core:3.8.0'

// Android standard libs
implementation "com.android.support:appcompat-v7:${version_lib.appcompat}"
implementation "com.android.support:design:${version_lib.appcompat}"
implementation "com.android.support:support-v4:${version_lib.appcompat}"
implementation "com.android.support:recyclerview-v7:${version_lib.appcompat}"
implementation "com.android.support:palette-v7:${version_lib.appcompat}"
implementation "com.android.support:appcompat-v7:${version_library_appcompat}"
implementation "com.android.support:design:${version_library_appcompat}"
implementation "com.android.support:support-v4:${version_library_appcompat}"
implementation "com.android.support:recyclerview-v7:${version_library_appcompat}"
implementation "com.android.support:palette-v7:${version_library_appcompat}"

// UI libs
implementation 'com.mobsandgeeks:adapter-kit:0.5.3'
implementation "com.atlassian.commonmark:commonmark:${version_lib.commonmark}"
implementation "com.atlassian.commonmark:commonmark-ext-gfm-strikethrough:${version_lib.commonmark}"
implementation "com.atlassian.commonmark:commonmark-ext-gfm-tables:${version_lib.commonmark}"
implementation "com.atlassian.commonmark:commonmark-ext-autolink:${version_lib.commonmark}"
implementation "com.atlassian.commonmark:commonmark-ext-ins:${version_lib.commonmark}"
implementation "com.atlassian.commonmark:commonmark-ext-yaml-front-matter:${version_lib.commonmark}"
implementation "com.atlassian.commonmark:commonmark-ext-heading-anchor:${version_lib.commonmark}"
implementation "com.atlassian.commonmark:commonmark:${version_library_commonmark}"
implementation "com.atlassian.commonmark:commonmark-ext-gfm-strikethrough:${version_library_commonmark}"
implementation "com.atlassian.commonmark:commonmark-ext-gfm-tables:${version_library_commonmark}"
implementation "com.atlassian.commonmark:commonmark-ext-autolink:${version_library_commonmark}"
implementation "com.atlassian.commonmark:commonmark-ext-ins:${version_library_commonmark}"
implementation "com.atlassian.commonmark:commonmark-ext-yaml-front-matter:${version_library_commonmark}"
implementation "com.atlassian.commonmark:commonmark-ext-heading-anchor:${version_library_commonmark}"

implementation 'com.pixplicity.generate:library:1.1.8'

// Tool libraries
implementation "com.jakewharton:butterknife:${version_lib.butterknife}"
implementation "com.jakewharton:butterknife:${version_library_butterknife}"
implementation 'commons-io:commons-io:2.5'

// Testing
testImplementation 'junit:junit:4.12'
testImplementation 'org.assertj:assertj-core:3.8.0'
if (enable_plugin_kotlin) {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$version_plugin_kotlin"
}

// Processors
annotationProcessor "com.jakewharton:butterknife-compiler:${version_lib.butterknife}"
def anpros = ["com.jakewharton:butterknife-compiler:${version_library_butterknife}"]
for (anpro in anpros) {
if (enable_plugin_kotlin) {
kapt anpro
} else {
annotationProcessor anpro
}
}
}
34 changes: 28 additions & 6 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,13 +1,33 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
ext.version_setup_compileSdk = 27
ext.version_setup_minSdk = 17
ext.version_setup_targetSdk = ext.version_setup_compileSdk
ext.version_setup_buildTools = "27.0.1" // Specifying optional

// https://developer.android.com/topic/libraries/support-library/revisions.html
ext.version_library_appcompat = "27.0.1"
// https://github.com/JakeWharton/butterknife/releases
ext.version_library_butterknife = "8.8.1"
// https://github.com/atlassian/commonmark-java/releases
ext.version_library_commonmark = "0.10.0"
// https://github.com/guardianproject/NetCipher/releases
ext.version_library_netcipher = "2.0.0-alpha1"
// https://github.com/JetBrains/kotlin/blob/master/ReadMe.md
ext.version_plugin_kotlin = "1.1.60"
ext.enable_plugin_kotlin = false

repositories {
jcenter()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.0'
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5'
if (project.enable_plugin_kotlin) {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$version_plugin_kotlin"
}

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand All @@ -27,15 +47,17 @@ task clean(type: Delete) {
delete rootProject.buildDir
}

final String[] ROOT_TO_RAW_COPYFILES = ["README.md", "LICENSE.txt", "CHANGELOG.md", "CONTRIBUTORS.md"]
final String[] ROOT_TO_RAW_COPYFILES = ["README.md", "CHANGELOG.md", "CONTRIBUTORS.md","LICENSE.txt","LICENSE.md","LICENSE"]
task copyRepoFiles(type: Copy) {
from rootProject.files(ROOT_TO_RAW_COPYFILES)
into "app/src/main/res/raw"
rename { String fileName -> fileName.replace(fileName, fileName.toLowerCase()) }
} ; tasks.copyRepoFiles.execute()
rename { String fileName -> fileName.replace(fileName, fileName.toLowerCase()) }
}; tasks.copyRepoFiles.execute()


@SuppressWarnings(["UnnecessaryQualifiedReference", "SpellCheckingInspection", "GroovyUnusedDeclaration"])
static String[] getUsedAndroidLanguages() {
// Returns used android languages as a buildConfig array: {'de', 'it', ..}"
static String getUsedAndroidLanguages() {
Set<String> langs = new HashSet<>()
new File('.').eachFileRecurse(groovy.io.FileType.DIRECTORIES) {
final foldername = it.name
Expand All @@ -47,7 +69,7 @@ static String[] getUsedAndroidLanguages() {
}
}
}
return langs.toArray(new String[langs.size()])
return '{' + langs.collect { "\"${it}\"" }.join(",") + '}'
}

ext.getGitHash = { ->
Expand All @@ -57,4 +79,4 @@ ext.getGitHash = { ->
standardOutput = stdout
}
return stdout.toString().trim()
}
}

0 comments on commit cd88bb6

Please sign in to comment.