Make some build properties extensions in buildSrc

They are used only in main build's .gradle.kts files, so it is more
flexible to define them as extensions - no need to republish
kotlin-build-gradle-plugin when another such property is to be added.
This commit is contained in:
Ilya Gorbunov
2020-03-31 21:01:43 +03:00
parent c046f431d9
commit 1727fcf1a8
4 changed files with 22 additions and 18 deletions
@@ -0,0 +1,18 @@
/*
* Copyright 2010-2020 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.
*/
val KotlinBuildProperties.includeJava9: Boolean
get() = !isInJpsBuildIdeaSync && getBoolean("kotlin.build.java9", true)
val KotlinBuildProperties.useBootstrapStdlib: Boolean
get() = isInJpsBuildIdeaSync || getBoolean("kotlin.build.useBootstrapStdlib", false)
val KotlinBuildProperties.postProcessing: Boolean get() = isTeamcityBuild || getBoolean("kotlin.build.postprocessing", true)
val KotlinBuildProperties.relocation: Boolean get() = postProcessing
val KotlinBuildProperties.proguard: Boolean get() = postProcessing && getBoolean("kotlin.build.proguard", isTeamcityBuild)
val KotlinBuildProperties.jarCompression: Boolean get() = getBoolean("kotlin.build.jar.compression", isTeamcityBuild)
@@ -33,10 +33,10 @@ class KotlinBuildProperties(
} }
} }
private fun getOrNull(key: String): Any? = fun getOrNull(key: String): Any? =
localProperties.getProperty(key) ?: propertiesProvider.getProperty(key) ?: rootProperties.getProperty(key) localProperties.getProperty(key) ?: propertiesProvider.getProperty(key) ?: rootProperties.getProperty(key)
private fun getBoolean(key: String, default: Boolean = false): Boolean = fun getBoolean(key: String, default: Boolean = false): Boolean =
this.getOrNull(key)?.toString()?.trim()?.toBoolean() ?: default this.getOrNull(key)?.toString()?.trim()?.toBoolean() ?: default
private fun hasProperty(key: String): Boolean = getOrNull(key) != null private fun hasProperty(key: String): Boolean = getOrNull(key) != null
@@ -61,12 +61,6 @@ class KotlinBuildProperties(
val isInJpsBuildIdeaSync: Boolean val isInJpsBuildIdeaSync: Boolean
get() = isJpsBuildEnabled && isInIdeaSync 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() private val kotlinUltimateExists: Boolean = propertiesProvider.rootProjectDir.resolve("kotlin-ultimate").exists()
val isTeamcityBuild: Boolean = getBoolean("teamcity") || System.getenv("TEAMCITY_VERSION") != null val isTeamcityBuild: Boolean = getBoolean("teamcity") || System.getenv("TEAMCITY_VERSION") != null
@@ -84,14 +78,6 @@ class KotlinBuildProperties(
val includeUltimate: Boolean = kotlinUltimateExists && (isTeamcityBuild || intellijUltimateEnabled) 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 jarCompression: Boolean get() = getBoolean("kotlin.build.jar.compression", isTeamcityBuild)
val buildCacheUrl: String? = getOrNull("kotlin.build.cache.url") as String? val buildCacheUrl: String? = getOrNull("kotlin.build.cache.url") as String?
val pushToBuildCache: Boolean = getBoolean("kotlin.build.cache.push", isTeamcityBuild) val pushToBuildCache: Boolean = getBoolean("kotlin.build.cache.push", isTeamcityBuild)
+1 -1
View File
@@ -5,7 +5,7 @@ apply plugin: 'kotlin-platform-jvm'
configureJvm6Project(project) configureJvm6Project(project)
configurePublishing(project) configurePublishing(project)
def includeJava9 = BuildPropertiesKt.getKotlinBuildProperties(project).includeJava9 def includeJava9 = BuildPropertiesExtKt.getIncludeJava9(project.kotlinBuildProperties)
sourceSets { sourceSets {
if (includeJava9) { if (includeJava9) {
+1 -1
View File
@@ -4,7 +4,7 @@ apply plugin: 'kotlin'
configureJvm6Project(project) configureJvm6Project(project)
def includeJava9 = BuildPropertiesKt.getKotlinBuildProperties(project).includeJava9 def includeJava9 = BuildPropertiesExtKt.getIncludeJava9(project.kotlinBuildProperties)
sourceSets { sourceSets {
main { main {