blob: 943d15f9f7191e920bffee754412c4ac4cb09887 [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() {
18 // TODO(137044144): After we convert this file to Kotlin (build.gradle.kts), we can just
19 // directly call the getGradleKotlinDsl() method.
20 // We're not doing that yet though because Gradle takes more time to process .kts files (at the
21 // time of writing, adding a .kts file adds roughly 10 addition seconds to build startup time).
22 def gradleUserHome = project.gradle.getGradleUserHomeDir()
23 def gradleVersion = project.gradle.getGradleVersion()
24 def containingPath = "" + gradleUserHome + "/wrapper/dists/gradle-" + gradleVersion + "-bin"
25 def subdirs = project.file(containingPath).listFiles()
26 if (subdirs.length != 1) {
27 throw new GradleException("Could not identify Gradle distribution in " + containingPath +
28 "; expected 1, found " + subdirs.length + ": " + subdirs)
29 }
30 def gradleHashDir = subdirs[0]
31 def kotlinDsl = "" + gradleHashDir + "/gradle-" + gradleVersion + "/lib/gradle-kotlin-dsl-" +
32 gradleVersion + ".jar"
33 if (!project.file(kotlinDsl).exists()) {
34 throw new GradleException("Kotlin dsl jar does not exist: " + kotlinDsl)
35 }
36 return project.files(kotlinDsl)
37}
38
39ext.findGradleKotlinDsl = this.&findGradleKotlinDsl