equal
deleted
inserted
replaced
|
1 package com.geekorum.build |
|
2 |
|
3 import com.android.build.gradle.BaseExtension |
|
4 import org.gradle.api.JavaVersion |
|
5 import org.gradle.api.Project |
|
6 import org.gradle.api.plugins.ExtensionAware |
|
7 import org.gradle.kotlin.dsl.dependencies |
|
8 import org.jetbrains.kotlin.gradle.dsl.KotlinJvmOptions |
|
9 |
|
10 /** |
|
11 * Configure java version compile options based on minSdkVersion value |
|
12 */ |
|
13 fun BaseExtension.configureJavaVersion() { |
|
14 val api = defaultConfig.minSdkVersion?.apiLevel ?: 0 |
|
15 val version = when { |
|
16 api >= 24 -> JavaVersion.VERSION_1_8 |
|
17 api >= 19 -> JavaVersion.VERSION_1_7 |
|
18 else -> JavaVersion.VERSION_1_6 |
|
19 } |
|
20 compileOptions { |
|
21 sourceCompatibility = version |
|
22 targetCompatibility = version |
|
23 } |
|
24 |
|
25 (this as ExtensionAware).extensions.findByType(KotlinJvmOptions::class.java)?.apply { |
|
26 if (version >= JavaVersion.VERSION_1_8) { |
|
27 jvmTarget = "1.8" |
|
28 } |
|
29 } |
|
30 } |
|
31 |
|
32 /** |
|
33 * Add missing annotation processord dependencies to build on Java 11 |
|
34 */ |
|
35 fun Project.configureAnnotationProcessorDeps() { |
|
36 dependencies { |
|
37 configurations.whenObjectAdded { |
|
38 when (name) { |
|
39 "kapt" -> { |
|
40 add(name,"javax.xml.bind:jaxb-api:2.3.1") |
|
41 add(name, "com.sun.xml.bind:jaxb-core:2.3.0.1") |
|
42 add(name, "com.sun.xml.bind:jaxb-impl:2.3.2") |
|
43 } |
|
44 "annotationProcessor" -> add(name, "javax.xml.bind:jaxb-api:2.3.1") |
|
45 } |
|
46 } |
|
47 } |
|
48 } |