buildSrc/src/main/kotlin/AndroidJavaVersion.kt
changeset 19 91a3ad3b1b9c
parent 10 9aad34f43f71
child 20 5d8a0555733d
equal deleted inserted replaced
18:3ccb29f83309 19:91a3ad3b1b9c
    19  * You should have received a copy of the GNU General Public License
    19  * You should have received a copy of the GNU General Public License
    20  * along with Geekdroid.  If not, see <http://www.gnu.org/licenses/>.
    20  * along with Geekdroid.  If not, see <http://www.gnu.org/licenses/>.
    21  */
    21  */
    22 package com.geekorum.build
    22 package com.geekorum.build
    23 
    23 
       
    24 import com.android.build.api.dsl.CommonExtension
       
    25 import com.android.build.api.dsl.DefaultConfig
    24 import com.android.build.gradle.BaseExtension
    26 import com.android.build.gradle.BaseExtension
    25 import org.gradle.api.JavaVersion
    27 import org.gradle.api.JavaVersion
    26 import org.gradle.api.Project
    28 import org.gradle.api.Project
    27 import org.gradle.api.plugins.ExtensionAware
    29 import org.gradle.api.plugins.ExtensionAware
    28 import org.gradle.kotlin.dsl.dependencies
    30 import org.gradle.kotlin.dsl.dependencies
    29 import org.jetbrains.kotlin.gradle.dsl.KotlinJvmOptions
    31 import org.jetbrains.kotlin.gradle.dsl.KotlinJvmOptions
    30 
    32 
    31 /**
    33 /**
    32  * Configure java version compile options based on minSdkVersion value
    34  * Configure java version compile options based on minSdkVersion value
    33  */
    35  */
       
    36 @Suppress("UNCHECKED_CAST")
    34 fun BaseExtension.configureJavaVersion() {
    37 fun BaseExtension.configureJavaVersion() {
    35     val api = defaultConfig.minSdkVersion?.apiLevel ?: 0
    38     (this as CommonExtension<*, *, DefaultConfig, *>).configureJavaVersion()
       
    39 }
       
    40 
       
    41 fun CommonExtension<*, *, DefaultConfig, *>.configureJavaVersion() {
       
    42     val api = defaultConfig.minSdk ?: 1
    36     val version = when {
    43     val version = when {
       
    44         api >= 30 -> JavaVersion.VERSION_11
    37         api >= 24 -> JavaVersion.VERSION_1_8
    45         api >= 24 -> JavaVersion.VERSION_1_8
    38         api >= 19 -> JavaVersion.VERSION_1_7
    46         api >= 19 -> JavaVersion.VERSION_1_7
    39         else -> JavaVersion.VERSION_1_6
    47         else -> JavaVersion.VERSION_1_6
    40     }
    48     }
    41     compileOptions {
    49     compileOptions {
    49         }
    57         }
    50     }
    58     }
    51 }
    59 }
    52 
    60 
    53 /**
    61 /**
    54  * Add missing annotation processord dependencies to build on Java 11
    62  * Add missing annotation processor dependencies to build on Java 11
    55  */
    63  */
    56 fun Project.configureAnnotationProcessorDeps() {
    64 fun Project.configureAnnotationProcessorDeps() {
    57     dependencies {
    65     dependencies {
    58         configurations.whenObjectAdded {
    66         configurations.whenObjectAdded {
    59             when (name) {
    67             when (name) {
    60                 "kapt" -> {
    68                 "kapt" -> {
    61                     add(name, "javax.xml.bind:jaxb-api:2.3.1")
    69                     add(name, "javax.xml.bind:jaxb-api:2.3.1")
    62                     add(name, "com.sun.xml.bind:jaxb-core:2.3.0.1")
    70                     add(name, "com.sun.xml.bind:jaxb-core:2.3.0.1")
    63                     add(name, "com.sun.xml.bind:jaxb-impl:2.3.2")
    71                     add(name, "com.sun.xml.bind:jaxb-impl:2.3.2")
    64                 }
    72                 }
       
    73 
    65                 "annotationProcessor" -> add(name, "javax.xml.bind:jaxb-api:2.3.1")
    74                 "annotationProcessor" -> add(name, "javax.xml.bind:jaxb-api:2.3.1")
    66                 // I guess that on AGP 4.x+ testAnnotationProcessor inherit from annotationProcessor
       
    67                 // not on 3.6.x
       
    68                 "testAnnotationProcessor" -> add(name, "javax.xml.bind:jaxb-api:2.3.1")
       
    69                 "androidTestAnnotationProcessor" -> add(name, "javax.xml.bind:jaxb-api:2.3.1")
       
    70             }
    75             }
    71         }
    76         }
    72     }
    77     }
    73 }
    78 }