1/* 2 * Copyright 2019 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 17def findGradleKotlinDsl() { 18 /* 19 * TODO(137044144): After we convert this file to Kotlin (build.gradle.kts), we can just 20 * directly call the getGradleKotlinDsl() method. 21 * We're not doing that yet though because Gradle takes more time to process .kts files (at the 22 * time of writing, adding a .kts file adds roughly 10 addition seconds to build startup time). 23 * 24 * getGradleVersion() is in a format of X.Y.Z-rc-1 / X.Y.Z. Kotlin dsl jar always drops the 25 * "-rc-1" suffix of the version, thus we need additional substring logic. 26 */ 27 def dashIndex = project.gradle.getGradleVersion().indexOf("-") 28 def kotlinDslVersion = dashIndex == -1 ? project.gradle.getGradleVersion() 29 : project.gradle.getGradleVersion().substring(0, dashIndex) 30 def kotlinDsl = "" + project.gradle.getGradleHomeDir() + "/lib/gradle-kotlin-dsl-" + 31 kotlinDslVersion + ".jar" 32 return project.files(kotlinDsl) 33} 34 35ext.findGradleKotlinDsl = this.&findGradleKotlinDsl 36