blob: 92daadebb2b5ad6f771af93946f5fb7df46ab9ed [file] [log] [blame]
Jeff Gaston9cfb0a12019-11-06 17:50:14 -05001/*
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() {
Aurimas Liutikas8920b2b2020-03-16 10:43:44 -070018 /*
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)
Jeff Gaston28add7b2019-11-07 14:05:22 -050030 def kotlinDsl = "" + project.gradle.getGradleHomeDir() + "/lib/gradle-kotlin-dsl-" +
Aurimas Liutikas8920b2b2020-03-16 10:43:44 -070031 kotlinDslVersion + ".jar"
Jeff Gaston9cfb0a12019-11-06 17:50:14 -050032 if (!project.file(kotlinDsl).exists()) {
33 throw new GradleException("Kotlin dsl jar does not exist: " + kotlinDsl)
34 }
35 return project.files(kotlinDsl)
36}
37
38ext.findGradleKotlinDsl = this.&findGradleKotlinDsl