1/* 2 * Copyright 2018 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16package androidx.build 17 18import androidx.build.license.CheckExternalDependencyLicensesTask 19import org.gradle.api.JavaVersion 20import org.gradle.api.Plugin 21import org.gradle.api.Project 22import org.gradle.api.plugins.JavaPluginConvention 23import org.gradle.api.tasks.bundling.Jar 24 25class SupportKotlinLibraryPlugin : Plugin<Project> { 26 override fun apply(project: Project) { 27 val supportLibraryExtension = project.extensions.create("supportLibrary", 28 SupportLibraryExtension::class.java, project) 29 apply(project, supportLibraryExtension) 30 project.apply(mapOf("plugin" to "kotlin")) 31 project.apply(mapOf("plugin" to "kotlin-kapt")) 32 33 project.afterEvaluate { 34 val convention = project.convention.getPlugin(JavaPluginConvention::class.java) 35 if (supportLibraryExtension.java8Library) { 36 convention.sourceCompatibility = JavaVersion.VERSION_1_8 37 convention.targetCompatibility = JavaVersion.VERSION_1_8 38 } else { 39 convention.sourceCompatibility = JavaVersion.VERSION_1_7 40 convention.targetCompatibility = JavaVersion.VERSION_1_7 41 } 42 43 project.tasks.withType(Jar::class.java) { jarTask -> 44 jarTask.setReproducibleFileOrder(true) 45 jarTask.setPreserveFileTimestamps(false) 46 } 47 48 } 49 50 CheckExternalDependencyLicensesTask.configure(project) 51 } 52} 53