Samples: Don't reuse the root gradle.properties

Earlier we used a single gradle.properties in all samples. But some
of samples are represented by separate gradle builds. In such samples
we had to read this gradle.properties manually making these samples
less clear. This patch creates a separate gradle.properties for
each gradle build and gets rid of manual property reading.
This commit is contained in:
Ilya Matveev
2019-04-01 20:12:25 +07:00
committed by Ilya Matveev
parent 59fd50895c
commit 15746490d5
7 changed files with 34 additions and 67 deletions
@@ -1 +1,11 @@
kotlin.code.style=official
# Run parallel builds in Gradle:
org.gradle.parallel=true
org.gradle.workers.max=4
# Pin Kotlin version:
kotlin_version=1.3.30-eap-113
# Use custom Kotlin/Native home:
org.jetbrains.kotlin.native.home=../../dist
@@ -1,20 +0,0 @@
// Reuse Kotlin version from the root project.
File rootProjectGradlePropertiesFile = file("${rootProject.projectDir}/../gradle.properties")
if (!rootProjectGradlePropertiesFile.isFile()) {
throw new Exception("File $rootProjectGradlePropertiesFile does not exist or is not a file")
}
Properties rootProjectProperties = new Properties()
rootProjectGradlePropertiesFile.withInputStream { inputStream ->
rootProjectProperties.load(inputStream)
if (!rootProjectProperties.containsKey('kotlin_version')) {
throw new Exception("No 'kotlin_version' property in $rootProjectGradlePropertiesFile file")
}
}
gradle.beforeProject { project ->
rootProjectProperties.forEach { String key, value ->
if (!project.hasProperty(key))
project.ext[key] = value
}
}
+7
View File
@@ -1,4 +1,11 @@
kotlin.code.style=official
# Run parallel builds in Gradle:
org.gradle.parallel=true
org.gradle.workers.max=4
# Pin Kotlin version:
kotlin_version=1.3.30-eap-113
# Use custom Kotlin/Native home:
org.jetbrains.kotlin.native.home=../../../dist
-21
View File
@@ -1,24 +1,3 @@
// Reuse Kotlin version from the root project.
File rootProjectGradlePropertiesFile = file("${rootProject.projectDir}/../gradle.properties")
if (!rootProjectGradlePropertiesFile.isFile()) {
throw new Exception("File $rootProjectGradlePropertiesFile does not exist or is not a file")
}
Properties rootProjectProperties = new Properties()
rootProjectGradlePropertiesFile.withInputStream { inputStream ->
rootProjectProperties.load(inputStream)
if (!rootProjectProperties.containsKey('kotlin_version')) {
throw new Exception("No 'kotlin_version' property in $rootProjectGradlePropertiesFile file")
}
}
gradle.beforeProject { project ->
rootProjectProperties.forEach { String key, value ->
if (!project.hasProperty(key))
project.ext[key] = value
}
}
include ':arithmeticParser'
include ':cliApp'
@@ -1 +1,11 @@
org.jetbrains.kotlin.native.home=../../../dist
kotlin.code.style=official
# Run parallel builds in Gradle:
org.gradle.parallel=true
org.gradle.workers.max=4
# Pin Kotlin version:
kotlin_version=1.3.30-eap-113
# Use custom Kotlin/Native home:
org.jetbrains.kotlin.native.home=../../../dist
@@ -6,36 +6,15 @@ pluginManagement {
}
resolutionStrategy {
// Workaround to be able to read plugin version from the properties file.
// See: https://stackoverflow.com/questions/52800536/how-to-use-plugin-version-from-gradle-properties-in-gradle-kotlin-dsl.
val kotlinVersion = getRootProperties().getValue("kotlin_version") as String
val kotlin_version: String by settings
eachPlugin {
when {
requested.id.id == "org.jetbrains.kotlin.native.cocoapods" ||
requested.id.id == "kotlin-native-cocoapods" ->
useModule("org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion")
useModule("org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version")
requested.id.id.startsWith("org.jetbrains.kotlin") ->
useVersion(kotlinVersion)
useVersion(kotlin_version)
}
}
}
}
// Reuse Kotlin version and other properties from the root samples project.
fun getRootProperties() = java.util.Properties().apply {
val rootProjectGradlePropertiesFile = file("${rootProject.projectDir}/../../gradle.properties")
if (!rootProjectGradlePropertiesFile.isFile) {
throw Exception("File $rootProjectGradlePropertiesFile does not exist or is not a file")
}
rootProjectGradlePropertiesFile.inputStream().use { inputStream ->
load(inputStream)
}
}
gradle.beforeProject {
getRootProperties().forEach { key, value ->
if (!project.hasProperty(key as String))
project.extra[key] = value
}
}
}
+2
View File
@@ -1,3 +1,5 @@
kotlin.code.style=official
# Run parallel builds in Gradle:
org.gradle.parallel=true