From 15746490d5516bff9b965f18df3e37c80520b4d1 Mon Sep 17 00:00:00 2001 From: Ilya Matveev Date: Mon, 1 Apr 2019 20:12:25 +0700 Subject: [PATCH] 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. --- .../androidNativeActivity/gradle.properties | 10 +++++++ samples/androidNativeActivity/settings.gradle | 20 ------------- samples/calculator/gradle.properties | 7 +++++ samples/calculator/settings.gradle | 21 -------------- .../kotlin-library/gradle.properties | 12 +++++++- .../kotlin-library/settings.gradle.kts | 29 +++---------------- samples/gradle.properties | 2 ++ 7 files changed, 34 insertions(+), 67 deletions(-) diff --git a/samples/androidNativeActivity/gradle.properties b/samples/androidNativeActivity/gradle.properties index 7fc6f1ff272..4e9746efc25 100644 --- a/samples/androidNativeActivity/gradle.properties +++ b/samples/androidNativeActivity/gradle.properties @@ -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 diff --git a/samples/androidNativeActivity/settings.gradle b/samples/androidNativeActivity/settings.gradle index 43c08c10733..e69de29bb2d 100644 --- a/samples/androidNativeActivity/settings.gradle +++ b/samples/androidNativeActivity/settings.gradle @@ -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 - } -} diff --git a/samples/calculator/gradle.properties b/samples/calculator/gradle.properties index 23f4b0b5150..cf65dbcc7e9 100644 --- a/samples/calculator/gradle.properties +++ b/samples/calculator/gradle.properties @@ -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 diff --git a/samples/calculator/settings.gradle b/samples/calculator/settings.gradle index 4df713ebf56..fe07c42cef4 100644 --- a/samples/calculator/settings.gradle +++ b/samples/calculator/settings.gradle @@ -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' diff --git a/samples/cocoapods/kotlin-library/gradle.properties b/samples/cocoapods/kotlin-library/gradle.properties index 270d6aecf68..cf65dbcc7e9 100644 --- a/samples/cocoapods/kotlin-library/gradle.properties +++ b/samples/cocoapods/kotlin-library/gradle.properties @@ -1 +1,11 @@ -org.jetbrains.kotlin.native.home=../../../dist \ No newline at end of file +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 diff --git a/samples/cocoapods/kotlin-library/settings.gradle.kts b/samples/cocoapods/kotlin-library/settings.gradle.kts index a00d777ee3f..7e3308930c6 100644 --- a/samples/cocoapods/kotlin-library/settings.gradle.kts +++ b/samples/cocoapods/kotlin-library/settings.gradle.kts @@ -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 - } -} +} \ No newline at end of file diff --git a/samples/gradle.properties b/samples/gradle.properties index c258c3de2e0..056f49c89be 100644 --- a/samples/gradle.properties +++ b/samples/gradle.properties @@ -1,3 +1,5 @@ +kotlin.code.style=official + # Run parallel builds in Gradle: org.gradle.parallel=true