@@ -33,7 +33,7 @@ private val LOGGER: Logger = Logger.getLogger("Kotlin settings logger")
33
33
* @return a Kotlin API version parametrized from command line nor gradle.properties, null otherwise
34
34
*/
35
35
fun getOverriddenKotlinApiVersion (project : Project ): KotlinVersion ? {
36
- val apiVersion = project.rootProject.properties[ " kotlin_api_version" ] as ? String
36
+ val apiVersion = project.providers.gradleProperty( " kotlin_api_version" ).orNull
37
37
return if (apiVersion != null ) {
38
38
LOGGER .info(""" Configured Kotlin API version: '$apiVersion ' for project $${project.name} """ )
39
39
KotlinVersion .fromVersion(apiVersion)
@@ -48,7 +48,7 @@ fun getOverriddenKotlinApiVersion(project: Project): KotlinVersion? {
48
48
* @return a Kotlin Language version parametrized from command line nor gradle.properties, null otherwise
49
49
*/
50
50
fun getOverriddenKotlinLanguageVersion (project : Project ): KotlinVersion ? {
51
- val languageVersion = project.rootProject.properties[ " kotlin_language_version" ] as ? String
51
+ val languageVersion = project.providers.gradleProperty( " kotlin_language_version" ).orNull
52
52
return if (languageVersion != null ) {
53
53
LOGGER .info(""" Configured Kotlin Language version: '$languageVersion ' for project ${project.name} """ )
54
54
KotlinVersion .fromVersion(languageVersion)
@@ -66,7 +66,7 @@ fun getOverriddenKotlinLanguageVersion(project: Project): KotlinVersion? {
66
66
* @return an url for a kotlin compiler repository parametrized from command line nor gradle.properties, empty string otherwise
67
67
*/
68
68
fun getKotlinDevRepositoryUrl (project : Project ): URI ? {
69
- val url: String? = project.rootProject.properties[ " kotlin_repo_url" ] as ? String
69
+ val url: String? = project.providers.gradleProperty( " kotlin_repo_url" ).orNull
70
70
if (url != null ) {
71
71
LOGGER .info(""" Configured Kotlin Compiler repository url: '$url ' for project ${project.name} """ )
72
72
return URI .create(url)
@@ -114,7 +114,7 @@ fun Project.configureCommunityBuildTweaks() {
114
114
}.files.single()
115
115
116
116
manifest.readLines().forEach {
117
- println (it)
117
+ LOGGER .info (it)
118
118
}
119
119
}
120
120
}
@@ -125,9 +125,8 @@ fun Project.configureCommunityBuildTweaks() {
125
125
*/
126
126
fun getOverriddenKotlinVersion (project : Project ): String? =
127
127
if (isSnapshotTrainEnabled(project)) {
128
- val snapshotVersion = project.rootProject.properties[ " kotlin_snapshot_version" ]
128
+ project.providers.gradleProperty( " kotlin_snapshot_version" ).orNull
129
129
? : error(" 'kotlin_snapshot_version' should be defined when building with a snapshot compiler" )
130
- snapshotVersion.toString()
131
130
} else {
132
131
null
133
132
}
@@ -136,14 +135,29 @@ fun getOverriddenKotlinVersion(project: Project): String? =
136
135
* Checks if the project is built with a snapshot version of Kotlin compiler.
137
136
*/
138
137
fun isSnapshotTrainEnabled (project : Project ): Boolean {
139
- val buildSnapshotTrain = project.rootProject.properties[ " build_snapshot_train" ] as ? String
138
+ val buildSnapshotTrain = project.providers.gradleProperty( " build_snapshot_train" ).orNull
140
139
return ! buildSnapshotTrain.isNullOrBlank()
141
140
}
142
141
142
+ /* *
143
+ * The list of projects snapshot versions of which we may want to use with `kotlinx.coroutines`.
144
+ *
145
+ * In `gradle.properties`, these properties are defined as `<name>_version`, e.g. `kotlin_version`.
146
+ */
147
+ val firstPartyDependencies = listOf (
148
+ " kotlin" ,
149
+ " atomicfu" ,
150
+ )
151
+
143
152
fun shouldUseLocalMaven (project : Project ): Boolean {
144
- val hasSnapshotDependency = project.rootProject.properties.any { (key, value) ->
145
- key.endsWith(" _version" ) && value is String && value.endsWith(" -SNAPSHOT" ).also {
146
- if (it) println (" NOTE: USING SNAPSHOT VERSION: $key =$value " )
153
+ val hasSnapshotDependency = firstPartyDependencies.any { dependencyName ->
154
+ val key = " ${dependencyName} _version"
155
+ val value = project.providers.gradleProperty(key).orNull
156
+ if (value != null && value.endsWith(" -SNAPSHOT" )) {
157
+ LOGGER .info(" NOTE: USING SNAPSHOT VERSION: $key =$value " )
158
+ true
159
+ } else {
160
+ false
147
161
}
148
162
}
149
163
return hasSnapshotDependency || isSnapshotTrainEnabled(project)
@@ -154,7 +168,7 @@ fun shouldUseLocalMaven(project: Project): Boolean {
154
168
* Then, `true` means that warnings should be treated as errors, `false` means that they should not.
155
169
*/
156
170
private fun warningsAreErrorsOverride (project : Project ): Boolean? =
157
- when (val prop = project.rootProject.properties[ " kotlin_Werror_override" ] as ? String ) {
171
+ when (val prop = project.providers.gradleProperty( " kotlin_Werror_override" ).orNull ) {
158
172
null -> null
159
173
" enable" -> true
160
174
" disable" -> false
@@ -187,10 +201,10 @@ fun KotlinCommonCompilerOptions.configureKotlinUserProject() {
187
201
* See <https://github.com/Kotlin/kotlinx.coroutines/pull/4392#issuecomment-2775630200>
188
202
*/
189
203
fun KotlinCommonCompilerOptions.addExtraCompilerFlags (project : Project ) {
190
- val extraOptions = project.rootProject.properties[ " kotlin_additional_cli_options" ] as ? String
204
+ val extraOptions = project.providers.gradleProperty( " kotlin_additional_cli_options" ).orNull
191
205
if (extraOptions != null ) {
192
206
LOGGER .info(""" Adding extra compiler flags '$extraOptions ' for a compilation in the project $${project.name} """ )
193
- extraOptions.split(" " )? .forEach {
207
+ extraOptions.split(" " ).forEach {
194
208
if (it.isNotEmpty()) freeCompilerArgs.add(it)
195
209
}
196
210
}
0 commit comments