From 4ca60a2d7dacb13237f596f3df501c65654de881 Mon Sep 17 00:00:00 2001 From: Alexander Udalov Date: Tue, 10 Nov 2020 22:13:42 +0100 Subject: [PATCH] Fix warnings and some inspections in buildSrc --- buildSrc/build.gradle.kts | 7 +++ buildSrc/src/main/kotlin/embeddable.kt | 51 ++++++++++--------- buildSrc/src/main/kotlin/localDependencies.kt | 8 ++- buildSrc/src/main/kotlin/pluginMarkers.kt | 2 +- .../plugins/KotlinBuildPublishingPlugin.kt | 8 ++- .../kotlin/plugins/PublishedKotlinModule.kt | 3 +- buildSrc/src/main/kotlin/tasks.kt | 4 +- 7 files changed, 45 insertions(+), 38 deletions(-) diff --git a/buildSrc/build.gradle.kts b/buildSrc/build.gradle.kts index 497edb3f8d4..2a13884a5e4 100644 --- a/buildSrc/build.gradle.kts +++ b/buildSrc/build.gradle.kts @@ -1,3 +1,5 @@ +import org.jetbrains.kotlin.gradle.tasks.KotlinCompile + extra["versions.native-platform"] = "0.14" buildscript { @@ -126,6 +128,11 @@ java { targetCompatibility = JavaVersion.VERSION_1_8 } +tasks.withType().configureEach { + kotlinOptions.freeCompilerArgs += + listOf("-Xopt-in=kotlin.RequiresOptIn", "-Xskip-runtime-version-check") +} + tasks["build"].dependsOn(":prepare-deps:build") allprojects { diff --git a/buildSrc/src/main/kotlin/embeddable.kt b/buildSrc/src/main/kotlin/embeddable.kt index 83f21aa310b..225b0cf3846 100644 --- a/buildSrc/src/main/kotlin/embeddable.kt +++ b/buildSrc/src/main/kotlin/embeddable.kt @@ -5,10 +5,13 @@ import org.gradle.api.Project import org.gradle.api.file.DuplicatesStrategy import org.gradle.api.tasks.TaskProvider import org.gradle.jvm.tasks.Jar -import org.gradle.kotlin.dsl.* +import org.gradle.kotlin.dsl.named +import org.gradle.kotlin.dsl.project +import org.gradle.kotlin.dsl.provideDelegate +import org.gradle.kotlin.dsl.register import java.io.File -val kotlinEmbeddableRootPackage = "org.jetbrains.kotlin" +const val kotlinEmbeddableRootPackage = "org.jetbrains.kotlin" val packagesToRelocate = listOf( @@ -31,21 +34,23 @@ val packagesToRelocate = // But due to the shadow plugin bug (https://github.com/johnrengelman/shadow/issues/262) it is not possible to use // packagesToRelocate list to for the include list. Therefore the exclude list has to be created. val packagesToExcludeFromDummy = - listOf("org/jetbrains/kotlin/**", - "org/intellij/lang/annotations/**", - "org/jetbrains/jps/**", - "META-INF/**", - "com/sun/jna/**", - "com/thoughtworks/xstream/**", - "javaslang/**", - "*.proto", - "messages/**", - "net/sf/cglib/**", - "one/util/streamex/**", - "org/iq80/snappy/**", - "org/jline/**", - "org/xmlpull/**", - "*.txt") + listOf( + "org/jetbrains/kotlin/**", + "org/intellij/lang/annotations/**", + "org/jetbrains/jps/**", + "META-INF/**", + "com/sun/jna/**", + "com/thoughtworks/xstream/**", + "javaslang/**", + "*.proto", + "messages/**", + "net/sf/cglib/**", + "one/util/streamex/**", + "org/iq80/snappy/**", + "org/jline/**", + "org/xmlpull/**", + "*.txt" + ) private fun ShadowJar.configureEmbeddableCompilerRelocation(withJavaxInject: Boolean = true) { relocate("com.google.protobuf", "org.jetbrains.kotlin.protobuf") @@ -67,8 +72,8 @@ private fun Project.compilerShadowJar(taskName: String, body: ShadowJar.() -> Un dependencies.add(compilerJar.name, dependencies.project(":kotlin-compiler", configuration = "runtimeJar")) return tasks.register(taskName) { - destinationDir = File(buildDir, "libs") - setDuplicatesStrategy(DuplicatesStrategy.EXCLUDE) + destinationDirectory.set(project.file(File(buildDir, "libs"))) + duplicatesStrategy = DuplicatesStrategy.EXCLUDE from(compilerJar) body() } @@ -107,8 +112,8 @@ fun Project.embeddableCompilerDummyForDependenciesRewriting( ) return tasks.register(taskName) { - destinationDir = File(buildDir, "libs") - setDuplicatesStrategy(DuplicatesStrategy.EXCLUDE) + destinationDirectory.set(project.file(File(buildDir, "libs"))) + duplicatesStrategy = DuplicatesStrategy.EXCLUDE from(compilerDummyJar) configureEmbeddableCompilerRelocation(withJavaxInject = false) body() @@ -119,7 +124,7 @@ fun Project.rewriteDepsToShadedJar( originalJarTask: TaskProvider, shadowJarTask: TaskProvider, body: Jar.() -> Unit = {} ): TaskProvider { originalJarTask.configure { - classifier = "original" + archiveClassifier.set("original") } val compilerDummyJarFile by lazy { configurations.getAt("compilerDummyJar").singleFile } @@ -132,7 +137,7 @@ fun Project.rewriteDepsToShadedJar( // which leads to the content of that JAR being excluded as well: exclude { it.file == compilerDummyJarFile } - classifier = "" + archiveClassifier.set("original") body() } return shadowJarTask diff --git a/buildSrc/src/main/kotlin/localDependencies.kt b/buildSrc/src/main/kotlin/localDependencies.kt index 0a4923403c4..ab23a4af3f7 100644 --- a/buildSrc/src/main/kotlin/localDependencies.kt +++ b/buildSrc/src/main/kotlin/localDependencies.kt @@ -132,12 +132,10 @@ object IntellijRootUtils { } } -fun ModuleDependency.includeIntellijCoreJarDependencies(project: Project) = - includeJars(*(project.rootProject.extra["IntellijCoreDependencies"] as List).toTypedArray(), rootProject = project.rootProject) - -fun ModuleDependency.includeIntellijCoreJarDependencies(project: Project, jarsFilterPredicate: (String) -> Boolean) = +@Suppress("UNCHECKED_CAST") +fun ModuleDependency.includeIntellijCoreJarDependencies(project: Project, jarsFilterPredicate: (String) -> Boolean = { true }): Unit = includeJars( - *(project.rootProject.extra["IntellijCoreDependencies"] as List).filter { jarsFilterPredicate(it) }.toTypedArray(), + *(project.rootProject.extra["IntellijCoreDependencies"] as List).filter(jarsFilterPredicate).toTypedArray(), rootProject = project.rootProject ) diff --git a/buildSrc/src/main/kotlin/pluginMarkers.kt b/buildSrc/src/main/kotlin/pluginMarkers.kt index 76be460c42b..8509609ec01 100644 --- a/buildSrc/src/main/kotlin/pluginMarkers.kt +++ b/buildSrc/src/main/kotlin/pluginMarkers.kt @@ -18,7 +18,7 @@ import java.util.* internal const val PLUGIN_MARKER_SUFFIX = ".gradle.plugin" -@UseExperimental(ExperimentalStdlibApi::class) +@OptIn(ExperimentalStdlibApi::class) fun Project.publishPluginMarkers(withEmptyJars: Boolean = true) { val pluginDevelopment = extensions.getByType() val publishingExtension = extensions.getByType() diff --git a/buildSrc/src/main/kotlin/plugins/KotlinBuildPublishingPlugin.kt b/buildSrc/src/main/kotlin/plugins/KotlinBuildPublishingPlugin.kt index a3da701ad7f..00ff6701d4f 100644 --- a/buildSrc/src/main/kotlin/plugins/KotlinBuildPublishingPlugin.kt +++ b/buildSrc/src/main/kotlin/plugins/KotlinBuildPublishingPlugin.kt @@ -8,7 +8,6 @@ package plugins import org.gradle.api.Plugin import org.gradle.api.Project import org.gradle.api.attributes.Usage -import org.gradle.api.component.AdhocComponentWithVariants import org.gradle.api.component.SoftwareComponentFactory import org.gradle.api.plugins.JavaBasePlugin import org.gradle.api.publish.PublishingExtension @@ -23,7 +22,6 @@ import org.gradle.plugins.signing.SigningPlugin import java.util.* import javax.inject.Inject - class KotlinBuildPublishingPlugin @Inject constructor( private val componentFactory: SoftwareComponentFactory ) : Plugin { @@ -47,7 +45,7 @@ class KotlinBuildPublishingPlugin @Inject constructor( } } - val kotlinLibraryComponent = componentFactory.adhoc(ADHOC_COMPONENT_NAME) as AdhocComponentWithVariants + val kotlinLibraryComponent = componentFactory.adhoc(ADHOC_COMPONENT_NAME) components.add(kotlinLibraryComponent) kotlinLibraryComponent.addVariantsFromConfiguration(publishedCompile) { mapToMavenScope("compile") } kotlinLibraryComponent.addVariantsFromConfiguration(publishedRuntime) { mapToMavenScope("runtime") } @@ -139,7 +137,7 @@ class KotlinBuildPublishingPlugin @Inject constructor( const val COMPILE_CONFIGURATION = "publishedCompile" const val RUNTIME_CONFIGURATION = "publishedRuntime" - @UseExperimental(ExperimentalStdlibApi::class) + @OptIn(ExperimentalStdlibApi::class) fun humanReadableName(project: Project) = project.name.split("-").joinToString(separator = " ") { it.capitalize(Locale.ROOT) } } @@ -163,4 +161,4 @@ fun TaskProvider.configureRepository() = configure { } } } -} \ No newline at end of file +} diff --git a/buildSrc/src/main/kotlin/plugins/PublishedKotlinModule.kt b/buildSrc/src/main/kotlin/plugins/PublishedKotlinModule.kt index 1597bedd6f7..016a51c988c 100644 --- a/buildSrc/src/main/kotlin/plugins/PublishedKotlinModule.kt +++ b/buildSrc/src/main/kotlin/plugins/PublishedKotlinModule.kt @@ -1,3 +1,4 @@ +@file:Suppress("DEPRECATION") package plugins import org.codehaus.groovy.runtime.InvokerHelper @@ -16,10 +17,8 @@ import org.gradle.plugins.signing.Sign import org.gradle.plugins.signing.SigningExtension import kotlin.properties.Delegates - /** * Configures a Kotlin module for publication. - * */ open class PublishedKotlinModule : Plugin { diff --git a/buildSrc/src/main/kotlin/tasks.kt b/buildSrc/src/main/kotlin/tasks.kt index 5810bfb46a3..69ad840581a 100644 --- a/buildSrc/src/main/kotlin/tasks.kt +++ b/buildSrc/src/main/kotlin/tasks.kt @@ -154,7 +154,7 @@ fun Project.projectTest( var subProjectTempRoot: Path? = null doFirst { - val teamcity = rootProject.findProperty("teamcity") as? Map + val teamcity = rootProject.findProperty("teamcity") as? Map<*, *> val systemTempRoot = // TC by default doesn't switch `teamcity.build.tempDir` to 'java.io.tmpdir' so it could cause to wasted disk space // Should be fixed soon on Teamcity side @@ -180,7 +180,7 @@ fun Project.projectTest( if (parallel) { maxParallelForks = project.findProperty("kotlin.test.maxParallelForks")?.toString()?.toInt() - ?: Math.max(Runtime.getRuntime().availableProcessors() / if (kotlinBuildProperties.isTeamcityBuild) 2 else 4, 1) + ?: (Runtime.getRuntime().availableProcessors() / if (kotlinBuildProperties.isTeamcityBuild) 2 else 4).coerceAtLeast(1) } body() }