Browse Source

fix(Gradle): Allow kotlinVersion override using ext with gradle.properties (#267)

You can now override kotlin version by defining ext kotlinVersion
Thibault Malbranche 6 years ago
parent
commit
2846e27fcf
No account linked to committer's email address
2 changed files with 22 additions and 14 deletions
  1. 17
    14
      android/build.gradle
  2. 5
    0
      android/gradle.properties

+ 17
- 14
android/build.gradle View File

@@ -1,9 +1,12 @@
1 1
 buildscript {
2
-  ext.kotlin_version = '1.2.71'
2
+  //Buildscript is evaluated before everything else so we can't use getExtOrDefault
3
+  def kotlin_version = rootProject.ext.has('kotlinVersion') ? rootProject.ext.get('kotlinVersion') : project.properties['ReactNativeWebview_kotlinVersion']
4
+
3 5
   repositories {
4 6
     google()
5 7
     jcenter()
6 8
   }
9
+
7 10
   dependencies {
8 11
     classpath 'com.android.tools.build:gradle:3.2.1'
9 12
     //noinspection DifferentKotlinGradleVersion
@@ -11,24 +14,23 @@ buildscript {
11 14
   }
12 15
 }
13 16
 
14
-apply plugin: 'com.android.library'
15
-apply plugin: 'kotlin-android'
16
-
17
-def DEFAULT_TARGET_SDK_VERSION = 27
18
-def DEFAULT_COMPILE_SDK_VERSION = 27
19
-def DEFAULT_BUILD_TOOLS_VERSION = "28.0.3"
20
-def DEFAULT_SUPPORT_LIB_VERSION = "28.0.0"
17
+def getExtOrDefault(name) {
18
+  return rootProject.ext.has(name) ? rootProject.ext.get(name) : project.properties['ReactNativeWebview_' + name]
19
+}
21 20
 
22
-def getExtOrDefault(name, defaultValue) {
23
-  return rootProject.ext.has(name) ? rootProject.ext.get(name) : defaultValue
21
+def getExtOrIntegerDefault(name) {
22
+  return rootProject.ext.has(name) ? rootProject.ext.get(name) : (project.properties['ReactNativeWebview_' + name]).toInteger()
24 23
 }
25 24
 
25
+apply plugin: 'com.android.library'
26
+apply plugin: 'kotlin-android'
27
+
26 28
 android {
27
-  compileSdkVersion getExtOrDefault('compileSdkVersion', DEFAULT_COMPILE_SDK_VERSION)
28
-  buildToolsVersion getExtOrDefault('buildToolsVersion', DEFAULT_BUILD_TOOLS_VERSION)
29
+  compileSdkVersion getExtOrIntegerDefault('compileSdkVersion')
30
+  buildToolsVersion getExtOrDefault('buildToolsVersion')
29 31
   defaultConfig {
30 32
     minSdkVersion 16
31
-    targetSdkVersion getExtOrDefault('targetSdkVersion', DEFAULT_TARGET_SDK_VERSION)
33
+    targetSdkVersion getExtOrIntegerDefault('targetSdkVersion')
32 34
     versionCode 1
33 35
     versionName "1.0"
34 36
   }
@@ -117,7 +119,8 @@ repositories {
117 119
   }
118 120
 }
119 121
 
120
-def support_version = getExtOrDefault('supportLibVersion', DEFAULT_SUPPORT_LIB_VERSION)
122
+def support_version = getExtOrDefault('supportLibVersion')
123
+def kotlin_version = getExtOrDefault('kotlinVersion')
121 124
 
122 125
 dependencies {
123 126
   //noinspection GradleDynamicVersion

+ 5
- 0
android/gradle.properties View File

@@ -0,0 +1,5 @@
1
+ReactNativeWebview_kotlinVersion=1.3.11
2
+ReactNativeWebview_compileSdkVersion=28
3
+ReactNativeWebview_buildToolsVersion=28.0.3
4
+ReactNativeWebview_targetSdkVersion=28
5
+ReactNativeWebview_supportLibVersion=28.0.0