1 /* <lambda>null2 * Copyright 2017 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 */ 16 17 package androidx.build 18 19 import com.android.build.gradle.LibraryExtension 20 import com.android.builder.core.BuilderConstants 21 22 import org.gradle.api.Project 23 import org.gradle.api.plugins.JavaPluginConvention 24 import org.gradle.api.tasks.bundling.Jar 25 26 /** 27 * Sets up a source jar task for an Android library project. 28 */ 29 fun setUpSoureJarTaskForAndroidProject(project: Project, extension: LibraryExtension) { 30 // Create sources jar for release builds 31 extension.libraryVariants.all { libraryVariant -> 32 if (libraryVariant.buildType.name != BuilderConstants.RELEASE) { 33 return@all // Skip non-release builds. 34 } 35 36 val sourceJar = project.tasks.create("sourceJarRelease", Jar::class.java) 37 sourceJar.isPreserveFileTimestamps = false 38 sourceJar.classifier = "sources" 39 sourceJar.from(extension.sourceSets.findByName("main")!!.java.srcDirs) 40 project.artifacts.add("archives", sourceJar) 41 } 42 } 43 44 /** 45 * Sets up a source jar task for a Java library project. 46 */ setUpSourceJarTaskForJavaProjectnull47fun setUpSourceJarTaskForJavaProject(project: Project) { 48 val sourceJar = project.tasks.create("sourceJar", Jar::class.java) 49 sourceJar.isPreserveFileTimestamps = false 50 sourceJar.classifier = "sources" 51 val convention = project.convention.getPlugin(JavaPluginConvention::class.java) 52 sourceJar.from(convention.sourceSets.findByName("main")!!.allSource.srcDirs) 53 project.artifacts.add("archives", sourceJar) 54 } 55