1
0
Fork 0
mirror of https://github.com/gsantner/dandelion synced 2024-11-16 09:22:08 +01:00
dandelion/build.gradle
Gregor Santner d3a2c20515
.
2018-03-05 17:22:06 +01:00

121 lines
4.4 KiB
Groovy

// 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.3" // Specifying optional
// https://developer.android.com/studio/releases/gradle-plugin.html
ext.version_gradle_tools = "3.0.1"
// https://developer.android.com/topic/libraries/support-library/revisions.html
ext.version_library_appcompat = "27.1.0"
// 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://mvnrepository.com/artifact/org.jetbrains.kotlin/kotlin-gradle-plugin#LookAtCentral
ext.version_plugin_kotlin = "1.2.21"
ext.enable_plugin_kotlin = false
repositories {
jcenter()
google()
}
dependencies {
classpath "com.android.tools.build:gradle:$version_gradle_tools"
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
}
}
allprojects {
repositories {
jcenter()
google()
mavenCentral()
maven { url "https://jitpack.io" }
}
tasks.matching { task -> task.name.matches('.*generate.*Resources') }.all {
task -> task.dependsOn copyRepoFiles
}
tasks.matching { task -> task.name.matches('.*generate.*Resources') }.all {
task -> task.doLast { markUntranslatableBuildFields() }
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
def markUntranslatableBuildFields() {
Set<Project> proc_projects = new HashSet<>(subprojects)
proc_projects.add(rootProject)
proc_projects.each { proc_project ->
File mergeDir = new File("${proc_project.buildDir}/intermediates/res/merged")
if (!mergeDir.exists()) return
mergeDir.eachDir { dir ->
println("Resources" + dir)
dir.eachFileRecurse { file ->
if (file.name.endsWith(".xml")) {
println(file)
String content = file.getText('UTF-8')
if (content != null && content.contains('<string name="bc_notr__')) {
println("Replacing app name in " + file)
content = content.replace('<string name="bc_notr__', '<string translatable="false" name="bc_notr__')
file.write(content, 'UTF-8')
}
}
}
}
}
}
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()) }
}
@SuppressWarnings(["UnnecessaryQualifiedReference", "SpellCheckingInspection", "GroovyUnusedDeclaration"])
// 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
if (foldername.startsWith('values-') && !it.canonicalPath.contains("build" + File.separator + "intermediates")) {
new File(it.toString()).eachFileRecurse(groovy.io.FileType.FILES) {
if (it.name.toLowerCase().endsWith(".xml") && it.getCanonicalFile().getText('UTF-8').contains("<string")) {
langs.add(foldername.replace("values-", ""))
}
}
}
}
return '{' + langs.collect { "\"${it}\"" }.join(",") + '}'
}
ext.getGitHash = { ->
try {
def stdout = new ByteArrayOutputStream() exec {
commandLine 'git', 'rev-parse', 'HEAD'
standardOutput = stdout
}
return stdout.toString().trim()
} catch (Exception e) {
return '???'
}
}