Fix warnings and some inspections in buildSrc

This commit is contained in:
Alexander Udalov
2020-11-10 22:13:42 +01:00
parent 22109e97d6
commit 4ca60a2d7d
7 changed files with 45 additions and 38 deletions
+7
View File
@@ -1,3 +1,5 @@
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
extra["versions.native-platform"] = "0.14" extra["versions.native-platform"] = "0.14"
buildscript { buildscript {
@@ -126,6 +128,11 @@ java {
targetCompatibility = JavaVersion.VERSION_1_8 targetCompatibility = JavaVersion.VERSION_1_8
} }
tasks.withType<KotlinCompile>().configureEach {
kotlinOptions.freeCompilerArgs +=
listOf("-Xopt-in=kotlin.RequiresOptIn", "-Xskip-runtime-version-check")
}
tasks["build"].dependsOn(":prepare-deps:build") tasks["build"].dependsOn(":prepare-deps:build")
allprojects { allprojects {
+28 -23
View File
@@ -5,10 +5,13 @@ import org.gradle.api.Project
import org.gradle.api.file.DuplicatesStrategy import org.gradle.api.file.DuplicatesStrategy
import org.gradle.api.tasks.TaskProvider import org.gradle.api.tasks.TaskProvider
import org.gradle.jvm.tasks.Jar 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 import java.io.File
val kotlinEmbeddableRootPackage = "org.jetbrains.kotlin" const val kotlinEmbeddableRootPackage = "org.jetbrains.kotlin"
val packagesToRelocate = val packagesToRelocate =
listOf( 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 // 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. // packagesToRelocate list to for the include list. Therefore the exclude list has to be created.
val packagesToExcludeFromDummy = val packagesToExcludeFromDummy =
listOf("org/jetbrains/kotlin/**", listOf(
"org/intellij/lang/annotations/**", "org/jetbrains/kotlin/**",
"org/jetbrains/jps/**", "org/intellij/lang/annotations/**",
"META-INF/**", "org/jetbrains/jps/**",
"com/sun/jna/**", "META-INF/**",
"com/thoughtworks/xstream/**", "com/sun/jna/**",
"javaslang/**", "com/thoughtworks/xstream/**",
"*.proto", "javaslang/**",
"messages/**", "*.proto",
"net/sf/cglib/**", "messages/**",
"one/util/streamex/**", "net/sf/cglib/**",
"org/iq80/snappy/**", "one/util/streamex/**",
"org/jline/**", "org/iq80/snappy/**",
"org/xmlpull/**", "org/jline/**",
"*.txt") "org/xmlpull/**",
"*.txt"
)
private fun ShadowJar.configureEmbeddableCompilerRelocation(withJavaxInject: Boolean = true) { private fun ShadowJar.configureEmbeddableCompilerRelocation(withJavaxInject: Boolean = true) {
relocate("com.google.protobuf", "org.jetbrains.kotlin.protobuf") 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")) dependencies.add(compilerJar.name, dependencies.project(":kotlin-compiler", configuration = "runtimeJar"))
return tasks.register<ShadowJar>(taskName) { return tasks.register<ShadowJar>(taskName) {
destinationDir = File(buildDir, "libs") destinationDirectory.set(project.file(File(buildDir, "libs")))
setDuplicatesStrategy(DuplicatesStrategy.EXCLUDE) duplicatesStrategy = DuplicatesStrategy.EXCLUDE
from(compilerJar) from(compilerJar)
body() body()
} }
@@ -107,8 +112,8 @@ fun Project.embeddableCompilerDummyForDependenciesRewriting(
) )
return tasks.register<ShadowJar>(taskName) { return tasks.register<ShadowJar>(taskName) {
destinationDir = File(buildDir, "libs") destinationDirectory.set(project.file(File(buildDir, "libs")))
setDuplicatesStrategy(DuplicatesStrategy.EXCLUDE) duplicatesStrategy = DuplicatesStrategy.EXCLUDE
from(compilerDummyJar) from(compilerDummyJar)
configureEmbeddableCompilerRelocation(withJavaxInject = false) configureEmbeddableCompilerRelocation(withJavaxInject = false)
body() body()
@@ -119,7 +124,7 @@ fun Project.rewriteDepsToShadedJar(
originalJarTask: TaskProvider<out Jar>, shadowJarTask: TaskProvider<out Jar>, body: Jar.() -> Unit = {} originalJarTask: TaskProvider<out Jar>, shadowJarTask: TaskProvider<out Jar>, body: Jar.() -> Unit = {}
): TaskProvider<out Jar> { ): TaskProvider<out Jar> {
originalJarTask.configure { originalJarTask.configure {
classifier = "original" archiveClassifier.set("original")
} }
val compilerDummyJarFile by lazy { configurations.getAt("compilerDummyJar").singleFile } 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: // which leads to the content of that JAR being excluded as well:
exclude { it.file == compilerDummyJarFile } exclude { it.file == compilerDummyJarFile }
classifier = "" archiveClassifier.set("original")
body() body()
} }
return shadowJarTask return shadowJarTask
@@ -132,12 +132,10 @@ object IntellijRootUtils {
} }
} }
fun ModuleDependency.includeIntellijCoreJarDependencies(project: Project) = @Suppress("UNCHECKED_CAST")
includeJars(*(project.rootProject.extra["IntellijCoreDependencies"] as List<String>).toTypedArray(), rootProject = project.rootProject) fun ModuleDependency.includeIntellijCoreJarDependencies(project: Project, jarsFilterPredicate: (String) -> Boolean = { true }): Unit =
fun ModuleDependency.includeIntellijCoreJarDependencies(project: Project, jarsFilterPredicate: (String) -> Boolean) =
includeJars( includeJars(
*(project.rootProject.extra["IntellijCoreDependencies"] as List<String>).filter { jarsFilterPredicate(it) }.toTypedArray(), *(project.rootProject.extra["IntellijCoreDependencies"] as List<String>).filter(jarsFilterPredicate).toTypedArray(),
rootProject = project.rootProject rootProject = project.rootProject
) )
+1 -1
View File
@@ -18,7 +18,7 @@ import java.util.*
internal const val PLUGIN_MARKER_SUFFIX = ".gradle.plugin" internal const val PLUGIN_MARKER_SUFFIX = ".gradle.plugin"
@UseExperimental(ExperimentalStdlibApi::class) @OptIn(ExperimentalStdlibApi::class)
fun Project.publishPluginMarkers(withEmptyJars: Boolean = true) { fun Project.publishPluginMarkers(withEmptyJars: Boolean = true) {
val pluginDevelopment = extensions.getByType<PluginBundleExtension>() val pluginDevelopment = extensions.getByType<PluginBundleExtension>()
val publishingExtension = extensions.getByType<PublishingExtension>() val publishingExtension = extensions.getByType<PublishingExtension>()
@@ -8,7 +8,6 @@ package plugins
import org.gradle.api.Plugin import org.gradle.api.Plugin
import org.gradle.api.Project import org.gradle.api.Project
import org.gradle.api.attributes.Usage import org.gradle.api.attributes.Usage
import org.gradle.api.component.AdhocComponentWithVariants
import org.gradle.api.component.SoftwareComponentFactory import org.gradle.api.component.SoftwareComponentFactory
import org.gradle.api.plugins.JavaBasePlugin import org.gradle.api.plugins.JavaBasePlugin
import org.gradle.api.publish.PublishingExtension import org.gradle.api.publish.PublishingExtension
@@ -23,7 +22,6 @@ import org.gradle.plugins.signing.SigningPlugin
import java.util.* import java.util.*
import javax.inject.Inject import javax.inject.Inject
class KotlinBuildPublishingPlugin @Inject constructor( class KotlinBuildPublishingPlugin @Inject constructor(
private val componentFactory: SoftwareComponentFactory private val componentFactory: SoftwareComponentFactory
) : Plugin<Project> { ) : Plugin<Project> {
@@ -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) components.add(kotlinLibraryComponent)
kotlinLibraryComponent.addVariantsFromConfiguration(publishedCompile) { mapToMavenScope("compile") } kotlinLibraryComponent.addVariantsFromConfiguration(publishedCompile) { mapToMavenScope("compile") }
kotlinLibraryComponent.addVariantsFromConfiguration(publishedRuntime) { mapToMavenScope("runtime") } kotlinLibraryComponent.addVariantsFromConfiguration(publishedRuntime) { mapToMavenScope("runtime") }
@@ -139,7 +137,7 @@ class KotlinBuildPublishingPlugin @Inject constructor(
const val COMPILE_CONFIGURATION = "publishedCompile" const val COMPILE_CONFIGURATION = "publishedCompile"
const val RUNTIME_CONFIGURATION = "publishedRuntime" const val RUNTIME_CONFIGURATION = "publishedRuntime"
@UseExperimental(ExperimentalStdlibApi::class) @OptIn(ExperimentalStdlibApi::class)
fun humanReadableName(project: Project) = fun humanReadableName(project: Project) =
project.name.split("-").joinToString(separator = " ") { it.capitalize(Locale.ROOT) } project.name.split("-").joinToString(separator = " ") { it.capitalize(Locale.ROOT) }
} }
@@ -1,3 +1,4 @@
@file:Suppress("DEPRECATION")
package plugins package plugins
import org.codehaus.groovy.runtime.InvokerHelper import org.codehaus.groovy.runtime.InvokerHelper
@@ -16,10 +17,8 @@ import org.gradle.plugins.signing.Sign
import org.gradle.plugins.signing.SigningExtension import org.gradle.plugins.signing.SigningExtension
import kotlin.properties.Delegates import kotlin.properties.Delegates
/** /**
* Configures a Kotlin module for publication. * Configures a Kotlin module for publication.
*
*/ */
open class PublishedKotlinModule : Plugin<Project> { open class PublishedKotlinModule : Plugin<Project> {
+2 -2
View File
@@ -154,7 +154,7 @@ fun Project.projectTest(
var subProjectTempRoot: Path? = null var subProjectTempRoot: Path? = null
doFirst { doFirst {
val teamcity = rootProject.findProperty("teamcity") as? Map<Any?, *> val teamcity = rootProject.findProperty("teamcity") as? Map<*, *>
val systemTempRoot = val systemTempRoot =
// TC by default doesn't switch `teamcity.build.tempDir` to 'java.io.tmpdir' so it could cause to wasted disk space // 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 // Should be fixed soon on Teamcity side
@@ -180,7 +180,7 @@ fun Project.projectTest(
if (parallel) { if (parallel) {
maxParallelForks = maxParallelForks =
project.findProperty("kotlin.test.maxParallelForks")?.toString()?.toInt() 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() body()
} }