/*
 * Copyright 2021 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

pluginManagement {
    repositories {
        mavenCentral()
        google()
        gradlePluginPortal().content {
            it.includeModule("org.jetbrains.kotlin.jvm", "org.jetbrains.kotlin.jvm.gradle.plugin")
        }
    }
}

dependencyResolutionManagement {
    repositories {
        mavenCentral()
        google()
        gradlePluginPortal().content {
            it.includeModule("com.gradle", "develocity-gradle-plugin")
            it.includeModule("com.gradle", "common-custom-user-data-gradle-plugin")
            it.includeModule("org.spdx", "spdx-gradle-plugin")
            it.includeModule("com.gradleup.shadow",
                    "com.gradleup.shadow.gradle.plugin")
            it.includeModule("com.gradleup.shadow", "shadow-gradle-plugin")
        }
    }
}

apply from: "shared/src/main/groovy/out-setup.groovy"
getGradle().beforeProject { project ->
    init.chooseBuildDirectory(
            new File("${buildscript.sourceFile.parent}/../.."), rootProject.name, project
    )
}
System.setProperty("ALLOW_PUBLIC_REPOS", "true")
rootProject.name = "playground-plugin"
includeBuild("../../buildSrc") {
    // cannot use name buildSrc, it is reserved.
    name = "supportBuildSrc"
    dependencySubstitution {
        substitute module('supportBuildSrc:public') using project(':public')
        substitute module('supportBuildSrc:private') using project(':private')
        substitute module('supportBuildSrc:plugins') using project(':plugins')
    }
}
include(":shared")
// Build cache configuration is duplicated here from the GradleEnterpriseConventionsPlugin,
// so that when building the `playground-plugin` included build the same build cache settings will be used.
// Without this, Gradle Enterprise erroneously reports a problem with 'buildSrc' build cache configuration.
def isCI = System.getenv("CI") == "true"
buildCache {
    local {
        // Aggressively clean up stale build cache entries on CI
        if (isCI) {
            removeUnusedEntriesAfterDays = 1
        }
    }
    remote(HttpBuildCache) {
        url = "https://ge.androidx.dev/cache/"
        var buildCachePassword = System.getenv("GRADLE_BUILD_CACHE_PASSWORD")
        if (isCI && buildCachePassword != null && !buildCachePassword.empty) {
            push = true
            credentials {
                username = "ci"
                password = buildCachePassword
            }
        } else {
            push = false
        }
    }
}
