@@ -33,7 +33,7 @@ private val LOGGER: Logger = Logger.getLogger("Kotlin settings logger")
3333 * @return a Kotlin API version parametrized from command line nor gradle.properties, null otherwise
3434 */
3535fun 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
3737 return if (apiVersion != null ) {
3838 LOGGER .info(""" Configured Kotlin API version: '$apiVersion ' for project $${project.name} """ )
3939 KotlinVersion .fromVersion(apiVersion)
@@ -48,7 +48,7 @@ fun getOverriddenKotlinApiVersion(project: Project): KotlinVersion? {
4848 * @return a Kotlin Language version parametrized from command line nor gradle.properties, null otherwise
4949 */
5050fun 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
5252 return if (languageVersion != null ) {
5353 LOGGER .info(""" Configured Kotlin Language version: '$languageVersion ' for project ${project.name} """ )
5454 KotlinVersion .fromVersion(languageVersion)
@@ -66,7 +66,7 @@ fun getOverriddenKotlinLanguageVersion(project: Project): KotlinVersion? {
6666 * @return an url for a kotlin compiler repository parametrized from command line nor gradle.properties, empty string otherwise
6767 */
6868fun 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
7070 if (url != null ) {
7171 LOGGER .info(""" Configured Kotlin Compiler repository url: '$url ' for project ${project.name} """ )
7272 return URI .create(url)
@@ -114,7 +114,7 @@ fun Project.configureCommunityBuildTweaks() {
114114 }.files.single()
115115
116116 manifest.readLines().forEach {
117- println (it)
117+ LOGGER .info (it)
118118 }
119119 }
120120 }
@@ -125,9 +125,8 @@ fun Project.configureCommunityBuildTweaks() {
125125 */
126126fun getOverriddenKotlinVersion (project : Project ): String? =
127127 if (isSnapshotTrainEnabled(project)) {
128- val snapshotVersion = project.rootProject.properties[ " kotlin_snapshot_version" ]
128+ project.providers.gradleProperty( " kotlin_snapshot_version" ).orNull
129129 ? : error(" 'kotlin_snapshot_version' should be defined when building with a snapshot compiler" )
130- snapshotVersion.toString()
131130 } else {
132131 null
133132 }
@@ -136,14 +135,29 @@ fun getOverriddenKotlinVersion(project: Project): String? =
136135 * Checks if the project is built with a snapshot version of Kotlin compiler.
137136 */
138137fun 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
140139 return ! buildSnapshotTrain.isNullOrBlank()
141140}
142141
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+
143152fun 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
147161 }
148162 }
149163 return hasSnapshotDependency || isSnapshotTrainEnabled(project)
@@ -154,7 +168,7 @@ fun shouldUseLocalMaven(project: Project): Boolean {
154168 * Then, `true` means that warnings should be treated as errors, `false` means that they should not.
155169 */
156170private 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 ) {
158172 null -> null
159173 " enable" -> true
160174 " disable" -> false
@@ -187,10 +201,10 @@ fun KotlinCommonCompilerOptions.configureKotlinUserProject() {
187201 * See <https://github.com/Kotlin/kotlinx.coroutines/pull/4392#issuecomment-2775630200>
188202 */
189203fun 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
191205 if (extraOptions != null ) {
192206 LOGGER .info(""" Adding extra compiler flags '$extraOptions ' for a compilation in the project $${project.name} """ )
193- extraOptions.split(" " )? .forEach {
207+ extraOptions.split(" " ).forEach {
194208 if (it.isNotEmpty()) freeCompilerArgs.add(it)
195209 }
196210 }
0 commit comments