Skip to content

Instantly share code, notes, and snippets.

@jmfayard
Last active September 22, 2020 13:15
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jmfayard/448cc931bbb2700b99878370728c5251 to your computer and use it in GitHub Desktop.
Save jmfayard/448cc931bbb2700b99878370728c5251 to your computer and use it in GitHub Desktop.
Gists Gradle-Kotlin-DSL
plugins {
id("com.android.application")
id("kotlin-android")
id("kotlin-android-extensions")
}
android {
compileSdkVersion(Config.SdkVersions.compile)
defaultConfig {
minSdkVersion(Config.SdkVersions.min)
targetSdkVersion(Config.SdkVersions.target)
testInstrumentationRunner = "android.support.test.runner.AndroidJUnitRunner"
multiDexEnabled = true
proguardFiles(getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro")
signingConfigs {
named("debug").configure {
storeFile = file("debug.keystore")
}
register("release") {
storeFile = file("debug.keystore")
}
}
buildTypes {
named("debug").configure {
applicationIdSuffix = ".debug"
isMinifyEnabled = false
}
named("release").configure {
isMinifyEnabled = tue
signingConfig = if (mautinoa.enableSigning())
signingConfigs.getByName("release") else
signingConfigs.getByName("debug")
}
}
lintOptions {
isAbortOnError = false
}
}
}
// root build.gradle.kts
buildscript {
repositories {
google()
mavenLocal()
mavenCentral()
jcenter()
maven("https://maven.fabric.io/public")
}
dependencies {
classpath(Config.Plugins.kotlin)
classpath(Config.Plugins.android)
classpath(Config.Plugins.dexcount)
classpath(Config.Plugins.googleplay_publisher)
classpath(Config.Plugins.git)
classpath(Config.Plugins.fabric)
}
}
plugins {
id("com.gradle.build-scan") version "1.15.1"
id("com.github.ben-manes.versions") version "0.20.0"
id("jmfayard.github.io.gradle-kotlin-dsl-libs") version "0.2.3" // $ gw syncLibs
id("com.jfrog.artifactory") version "4.7.5"
}
plugins {
id("com.gradle.build-scan") version "1.15.1"
}
buildScan {
setTermsOfServiceUrl("https://gradle.com/terms-of-service")
setTermsOfServiceAgree("yes")
publishAlways()
}
plugins {
`kotlin-dsl`
}
repositories {
mavenCentral()
jcenter()
google()
}
dependencies {
implementation("com.android.tools.build:gradle:3.2.0")
}
// buildSrc/src/main/kotlin/Config.kt
object Config {
const val ACTIVITY = "com.mautinoa.cardapp.MainActivity"
const val PACKAGE = "com.mautinoa.cardapp"
const val kotlinVersion = "1.2.71"
object SdkVersions {
val versionCode = 1
val compile = 28
val target = 26
val min = 19
}
object Plugins {
const val android = "com.android.tools.build:gradle:3.2.0"
const val kotlin = "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"
const val firebase = "com.google.firebase:firebase-plugins:1.1.5"
const val fabric = "io.fabric.tools:gradle:1.25.4"
const val ktlint = "com.github.shyiko:ktlint:0.28.0"
const val git = "org.ajoberstar:gradle-git:0.2.3"
const val dexcount = "com.getkeepsafe.dexcount:dexcount-gradle-plugin:0.8.3"
const val googleplay_publisher = "com.github.triplet.gradle:play-publisher:1.2.2"
}
}
plugins {
id("jmfayard.github.io.gradle-kotlin-dsl-libs") version "0.2.3" // $ gw syncLibs
}
java {
sourceCompatibility = JavaVersion.VERSION_1_7
targetCompatibility = JavaVersion.VERSION_1_7
}
// buildSrc/src/main/kotlin
fun RepositoryHandler.maven(
url: String,
name: String? = null,
username: String? = null,
password: String? = null,
configure: RepositoryHandler.() -> Unit = {}
) {
this.maven {
setUrl(url)
if (name != null) setName(name)
if (username != null && password != null) {
credentials {
setUsername(username)
setPassword(password)
}
}
configure()
}
}
// buildsrc/src/main/kotlin/Projects.kt
import com.android.build.gradle.BaseExtension
import com.android.build.gradle.internal.dsl.DefaultConfig
import org.gradle.api.artifacts.dsl.RepositoryHandler
fun DefaultConfig.addResValues(
vararg entries: Pair<String, String>
) {
for ((key, value) in entries) {
resValue("string", key, value)
}
}
fun RepositoryHandler.maven(
url: String,
name: String? = null,
username: String? = null,
password: String? = null,
configure: RepositoryHandler.() -> Unit = {}
) {
this.maven {
setUrl(url)
if (name != null) setName(name)
if (username != null && password != null) {
credentials {
setUsername(username)
setPassword(password)
}
}
configure()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment