Build: Add kotlin-build-gradle-plugin & use it prebuilt from bintray
With extracted buildProperties.kt from buildSrc required for settings.gradle, using buildSrc classes is not allowed there since gradle 6.0
This commit is contained in:
@@ -83,9 +83,10 @@ extra["versions.androidDxSources"] = "5.0.0_r2"
|
||||
extra["customDepsOrg"] = "kotlin.build"
|
||||
|
||||
repositories {
|
||||
maven("https://jetbrains.bintray.com/intellij-third-party-dependencies/")
|
||||
maven("https://plugins.gradle.org/m2/")
|
||||
jcenter()
|
||||
maven("https://jetbrains.bintray.com/intellij-third-party-dependencies/")
|
||||
maven("https://kotlin.bintray.com/kotlin-dependencies")
|
||||
gradlePluginPortal()
|
||||
|
||||
extra["buildSrcKotlinRepo"]?.let {
|
||||
maven(url = it)
|
||||
@@ -94,6 +95,8 @@ repositories {
|
||||
|
||||
dependencies {
|
||||
compile(kotlin("stdlib", embeddedKotlinVersion))
|
||||
compile("org.jetbrains.kotlin:kotlin-build-gradle-plugin:0.0.1")
|
||||
|
||||
compile("net.rubygrapefruit:native-platform:${property("versions.native-platform")}")
|
||||
compile("net.rubygrapefruit:native-platform-windows-amd64:${property("versions.native-platform")}")
|
||||
compile("net.rubygrapefruit:native-platform-windows-i386:${property("versions.native-platform")}")
|
||||
|
||||
@@ -1,119 +0,0 @@
|
||||
import org.gradle.api.Project
|
||||
import org.gradle.api.initialization.Settings
|
||||
import org.gradle.api.internal.DynamicObjectAware
|
||||
import java.io.File
|
||||
import java.util.*
|
||||
|
||||
/*
|
||||
* Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
interface PropertiesProvider {
|
||||
val rootProjectDir: File
|
||||
fun getProperty(key: String): Any?
|
||||
}
|
||||
|
||||
class KotlinBuildProperties(
|
||||
private val propertiesProvider: PropertiesProvider
|
||||
) {
|
||||
private val localProperties: Properties = Properties()
|
||||
|
||||
init {
|
||||
val localPropertiesFile = propertiesProvider.rootProjectDir.resolve("local.properties")
|
||||
if (localPropertiesFile.isFile) {
|
||||
localPropertiesFile.reader().use(localProperties::load)
|
||||
}
|
||||
}
|
||||
|
||||
private operator fun get(key: String): Any? = localProperties.getProperty(key) ?: propertiesProvider.getProperty(key)
|
||||
|
||||
private fun getBoolean(key: String, default: Boolean = false): Boolean =
|
||||
this[key]?.toString()?.trim()?.toBoolean() ?: default
|
||||
|
||||
val isJpsBuildEnabled: Boolean = getBoolean("jpsBuild")
|
||||
|
||||
val isInIdeaSync: Boolean = run {
|
||||
// "idea.sync.active" was introduced in 2019.1
|
||||
System.getProperty("idea.sync.active")?.toBoolean() == true || let {
|
||||
// before 2019.1 there is "idea.active" that was true only on sync,
|
||||
// but since 2019.1 "idea.active" present in task execution too.
|
||||
// So let's check Idea version
|
||||
val majorIdeaVersion = System.getProperty("idea.version")
|
||||
?.split(".")
|
||||
?.getOrNull(0)
|
||||
val isBeforeIdea2019 = majorIdeaVersion == null || majorIdeaVersion.toInt() < 2019
|
||||
|
||||
isBeforeIdea2019 && System.getProperty("idea.active")?.toBoolean() == true
|
||||
}
|
||||
}
|
||||
|
||||
val isInJpsBuildIdeaSync: Boolean
|
||||
get() = isJpsBuildEnabled && isInIdeaSync
|
||||
|
||||
val includeJava9: Boolean
|
||||
get() = !isInJpsBuildIdeaSync && getBoolean("kotlin.build.java9", true)
|
||||
|
||||
val useBootstrapStdlib: Boolean
|
||||
get() = isInJpsBuildIdeaSync || getBoolean("kotlin.build.useBootstrapStdlib", false)
|
||||
|
||||
private val kotlinUltimateExists: Boolean = propertiesProvider.rootProjectDir.resolve("kotlin-ultimate").exists()
|
||||
|
||||
val isTeamcityBuild: Boolean = getBoolean("teamcity") || System.getenv("TEAMCITY_VERSION") != null
|
||||
|
||||
val intellijUltimateEnabled: Boolean
|
||||
get() {
|
||||
val explicitlyEnabled = getBoolean("intellijUltimateEnabled")
|
||||
if (!kotlinUltimateExists && explicitlyEnabled) {
|
||||
error("intellijUltimateEnabled property is set, while kotlin-ultimate repository is not provided")
|
||||
}
|
||||
return kotlinUltimateExists && (explicitlyEnabled || isTeamcityBuild)
|
||||
}
|
||||
|
||||
val includeCidrPlugins: Boolean = kotlinUltimateExists && getBoolean("cidrPluginsEnabled")
|
||||
|
||||
val includeUltimate: Boolean = kotlinUltimateExists && (isTeamcityBuild || intellijUltimateEnabled)
|
||||
|
||||
val postProcessing: Boolean get() = isTeamcityBuild || getBoolean("kotlin.build.postprocessing", true)
|
||||
|
||||
val relocation: Boolean get() = postProcessing
|
||||
|
||||
val proguard: Boolean get() = postProcessing && getBoolean("kotlin.build.proguard", isTeamcityBuild)
|
||||
|
||||
val jsIrDist: Boolean get() = getBoolean("kotlin.stdlib.js.ir.dist")
|
||||
|
||||
val jarCompression: Boolean get() = getBoolean("kotlin.build.jar.compression", isTeamcityBuild)
|
||||
}
|
||||
|
||||
private const val extensionName = "kotlinBuildProperties"
|
||||
|
||||
class ProjectProperties(val project: Project) : PropertiesProvider {
|
||||
override val rootProjectDir: File
|
||||
get() = project.projectDir
|
||||
|
||||
override fun getProperty(key: String): Any? = project.findProperty(key)
|
||||
}
|
||||
|
||||
val Project.kotlinBuildProperties: KotlinBuildProperties
|
||||
get() = rootProject.extensions.findByName(extensionName) as KotlinBuildProperties?
|
||||
?: KotlinBuildProperties(ProjectProperties(rootProject)).also {
|
||||
rootProject.extensions.add(extensionName, it)
|
||||
}
|
||||
|
||||
class SettingsProperties(val settings: Settings) : PropertiesProvider {
|
||||
override val rootProjectDir: File
|
||||
get() = settings.rootDir
|
||||
|
||||
override fun getProperty(key: String): Any? {
|
||||
val obj = (settings as DynamicObjectAware).asDynamicObject
|
||||
return if (obj.hasProperty(key)) obj.getProperty(key) else null
|
||||
}
|
||||
}
|
||||
|
||||
fun getKotlinBuildPropertiesForSettings(settings: Any) = (settings as Settings).kotlinBuildProperties
|
||||
|
||||
val Settings.kotlinBuildProperties: KotlinBuildProperties
|
||||
get() = extensions.findByName(extensionName) as KotlinBuildProperties?
|
||||
?: KotlinBuildProperties(SettingsProperties(this)).also {
|
||||
extensions.add(extensionName, it)
|
||||
}
|
||||
Reference in New Issue
Block a user