Bug 1439410 - 1. Enable Kotlin for geckoview tests; r=nalexander
Kotlin has several nice features for writing tests, such as lambdas and
default implementations for interface methods. This patch adds Kotlin
support to the geckoview module build.gradle. We don't want to use
Kotlin in non-test code yet, so the patch ensures that only test code
contains Kotlin files.
MozReview-Commit-ID: FcQiHj20xlB
--- a/build.gradle
+++ b/build.gradle
@@ -45,19 +45,22 @@ buildscript {
}
}
// For in tree plugins.
maven {
url "file://${gradle.mozconfig.topsrcdir}/mobile/android/gradle/m2repo"
}
}
+ ext.kotlin_version = '1.1.51'
+
dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'
classpath 'com.getkeepsafe.dexcount:dexcount-gradle-plugin:0.8.2'
+ classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
if ('multi' == System.env.AB_CD) {
// Multi-l10n builds set `AB_CD=multi`, which isn't a valid locale. This
// causes the
//
// |mach build| > |mach gradle| > |make gradle-targets| > AndroidManifest.xml > strings.xml > multi/brand.dtd
--- a/mobile/android/geckoview/build.gradle
+++ b/mobile/android/geckoview/build.gradle
@@ -1,11 +1,12 @@
buildDir "${topobjdir}/gradle/build/mobile/android/geckoview"
apply plugin: 'com.android.library'
+apply plugin: 'kotlin-android'
apply from: "${topsrcdir}/mobile/android/gradle/product_flavors.gradle"
// This converts MOZ_APP_VERSION into an integer
// version code.
//
// We take something like 58.1.2a1 and come out with 5800102
// This gives us 3 digits for the major number, and 2 digits
@@ -146,20 +147,22 @@ android {
}
}
}
dependencies {
implementation "com.android.support:support-v4:${mozconfig.substs.ANDROID_SUPPORT_LIBRARY_VERSION}"
implementation "com.android.support:palette-v7:${mozconfig.substs.ANDROID_SUPPORT_LIBRARY_VERSION}"
+ testImplementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
testImplementation 'junit:junit:4.12'
testImplementation 'org.robolectric:robolectric:3.5.1'
testImplementation 'org.mockito:mockito-core:1.10.19'
+ androidTestImplementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
androidTestImplementation 'com.android.support.test:runner:0.5'
androidTestImplementation 'com.android.support.test:rules:0.5'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:2.2.2'
androidTestImplementation "com.android.support:support-annotations:${mozconfig.substs.ANDROID_SUPPORT_LIBRARY_VERSION}"
}
apply from: "${topsrcdir}/mobile/android/gradle/with_gecko_binaries.gradle"
@@ -215,17 +218,17 @@ android.libraryVariants.all { variant ->
}
}
android.libraryVariants.all { variant ->
configureLibraryVariantWithJNIWrappers(variant, "Generated")
}
apply plugin: 'maven'
-
+
uploadArchives {
repositories.mavenDeployer {
pom.groupId = 'org.mozilla'
pom.artifactId = "geckoview-${mozconfig.substs.MOZ_UPDATE_CHANNEL}-${mozconfig.substs.ANDROID_CPU_ARCH}"
pom.version = mozconfig.substs.MOZ_APP_VERSION
pom.project {
licenses {
license {
@@ -259,13 +262,25 @@ afterEvaluate {
artifacts {
// Instead of default (release) configuration, publish one with Gecko binaries.
archives bundleOfficialWithGeckoBinariesNoMinApiRelease
// Javadoc and sources for developer ergononomics.
archives javadocJarOfficialWithGeckoBinariesNoMinApiRelease
archives sourcesJarOfficialWithGeckoBinariesNoMinApiRelease
}
+
+ // For now, ensure Kotlin is only used in tests.
+ android.sourceSets.all { sourceSet ->
+ if (sourceSet.name.startsWith('test') || sourceSet.name.startsWith('androidTest')) {
+ return
+ }
+ (sourceSet.java.srcDirs + sourceSet.kotlin.srcDirs).each {
+ if (!fileTree(it, { include '**/*.kt' }).empty) {
+ throw new GradleException("Kotlin used in non-test directory ${it.path}")
+ }
+ }
+ }
}
// Bug 1353055 - Strip 'vars' debugging information to agree with moz.build.
apply from: "${topsrcdir}/mobile/android/gradle/debug_level.gradle"
android.libraryVariants.all configureVariantDebugLevel