add cleanup dependencies tasks for buildSrc

change embedded kotlin version to bootstrap for buildSrc
This commit is contained in:
nataliya.valtman
2020-01-29 14:27:02 +03:00
parent ea7b5827ab
commit 8a8536f8ae
13 changed files with 181 additions and 194 deletions

View File

@@ -5,10 +5,10 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import proguard.gradle.ProGuardTask
buildscript {
extra["defaultSnapshotVersion"] = "1.4-SNAPSHOT"
val cacheRedirectorEnabled = findProperty("cacheRedirectorEnabled")?.toString()?.toBoolean() == true
kotlinBootstrapFrom(BootstrapOption.BintrayBootstrap("1.4.0-dev-1075", cacheRedirectorEnabled))
kotlinBootstrapFrom(BootstrapOption.BintrayBootstrap(kotlinBuildProperties.kotlinBootstrapVersion!!, cacheRedirectorEnabled))
repositories {
bootstrapKotlinRepo?.let(::maven)
@@ -28,7 +28,7 @@ buildscript {
dependencies {
bootstrapCompilerClasspath(kotlin("compiler-embeddable", bootstrapKotlinVersion))
classpath("org.jetbrains.kotlin:kotlin-build-gradle-plugin:0.0.12")
classpath("org.jetbrains.kotlin:kotlin-build-gradle-plugin:0.0.13")
classpath("com.gradle.publish:plugin-publish-plugin:0.9.7")
classpath(kotlin("gradle-plugin", bootstrapKotlinVersion))
classpath("net.sf.proguard:proguard-gradle:6.1.0")

View File

@@ -1,10 +1,11 @@
extra["versions.native-platform"] = "0.14"
buildscript {
val cacheRedirectorEnabled = findProperty("cacheRedirectorEnabled")?.toString()?.toBoolean() == true
val buildSrcKotlinVersion: String by extra(findProperty("buildSrc.kotlin.version")?.toString() ?: embeddedKotlinVersion)
val buildSrcKotlinRepo: String? by extra(findProperty("buildSrc.kotlin.repo") as String?)
extra["defaultSnapshotVersion"] = kotlinBuildProperties.defaultSnapshotVersion
kotlinBootstrapFrom(BootstrapOption.BintrayBootstrap(kotlinBuildProperties.kotlinBootstrapVersion!!, cacheRedirectorEnabled))
repositories {
if (cacheRedirectorEnabled) {
@@ -15,21 +16,21 @@ buildscript {
maven("https://kotlin.bintray.com/kotlin-dependencies")
}
buildSrcKotlinRepo?.let {
project.bootstrapKotlinRepo?.let {
maven(url = it)
}
}
dependencies {
classpath("org.jetbrains.kotlin:kotlin-build-gradle-plugin:0.0.12")
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:$buildSrcKotlinVersion")
classpath("org.jetbrains.kotlin:kotlin-sam-with-receiver:$buildSrcKotlinVersion")
classpath("org.jetbrains.kotlin:kotlin-build-gradle-plugin:0.0.13")
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:${project.bootstrapKotlinVersion}")
classpath("org.jetbrains.kotlin:kotlin-sam-with-receiver:${project.bootstrapKotlinVersion}")
}
}
val cacheRedirectorEnabled = findProperty("cacheRedirectorEnabled")?.toString()?.toBoolean() == true
logger.info("buildSrcKotlinVersion: " + extra["buildSrcKotlinVersion"])
logger.info("buildSrcKotlinVersion: " + extra["bootstrapKotlinVersion"])
logger.info("buildSrc kotlin compiler version: " + org.jetbrains.kotlin.config.KotlinCompilerVersion.VERSION)
logger.info("buildSrc stdlib version: " + KotlinVersion.CURRENT)
@@ -83,14 +84,14 @@ repositories {
maven("https://kotlin.bintray.com/kotlin-dependencies")
gradlePluginPortal()
extra["buildSrcKotlinRepo"]?.let {
extra["bootstrapKotlinRepo"]?.let {
maven(url = it)
}
}
dependencies {
implementation(kotlin("stdlib", embeddedKotlinVersion))
implementation("org.jetbrains.kotlin:kotlin-build-gradle-plugin:0.0.12")
implementation("org.jetbrains.kotlin:kotlin-build-gradle-plugin:0.0.13")
implementation("net.rubygrapefruit:native-platform:${property("versions.native-platform")}")
implementation("net.rubygrapefruit:native-platform-windows-amd64:${property("versions.native-platform")}")

View File

@@ -9,6 +9,9 @@ import java.text.SimpleDateFormat
import java.util.*
import javax.xml.stream.XMLOutputFactory
import org.jetbrains.kotlin.gradle.tasks.internal.CleanableStore
import org.jetbrains.kotlin.gradle.tasks.CleanDataTask
plugins {
base
}
@@ -105,7 +108,8 @@ val nodeJSPlugin by configurations.creating
val intellijRuntimeAnnotations = "intellij-runtime-annotations"
val dependenciesDir = (findProperty("kotlin.build.dependencies.dir") as String?)?.let(::File)
?: rootProject.rootDir.parentFile.resolve("dependencies")
?: (findProperty("agent.persistent.cache") as String?)?.let(::File)
?: rootProject.gradle.gradleUserHomeDir.resolve("kotlin-build-dependencies")
val customDepsRepoDir = dependenciesDir.resolve("repo")
@@ -142,14 +146,29 @@ dependencies {
}
}
val makeIntellijCore = buildIvyRepositoryTask(intellijCore, customDepsOrg, customDepsRepoDir)
val cleanupIntellijCore = tasks.register<CleanDataTask>("cleanupIntellijCore") {
cleanableStoreProvider = provider { CleanableStore[repoDir.resolve("intellij-core").absolutePath] }
}
val cleanupIntellijAnnotation = tasks.register<CleanDataTask>("cleanupIntellijAnnotation") {
cleanableStoreProvider = provider { CleanableStore[repoDir.resolve(intellijRuntimeAnnotations).absolutePath] }
}
val cleanupDependencies = tasks.register("cleanupDependencies") {
dependsOn(cleanupIntellijCore)
dependsOn(cleanupIntellijAnnotation)
}
val makeIntellijCore = buildIvyRepositoryTaskAndRegisterCleanupTask(intellijCore, customDepsOrg, customDepsRepoDir)
val makeIntellijAnnotations by tasks.registering(Copy::class) {
dependsOn(makeIntellijCore)
from(repoDir.resolve("intellij-core/$intellijVersion/artifacts/annotations.jar"))
val intellijCoreRepo = CleanableStore[repoDir.resolve("intellij-core").absolutePath][intellijVersion].use()
from(intellijCoreRepo.resolve("artifacts/annotations.jar"))
val targetDir = File(repoDir, "$intellijRuntimeAnnotations/$intellijVersion")
val targetDir = CleanableStore[repoDir.resolve(intellijRuntimeAnnotations).absolutePath][intellijVersion].use()
into(targetDir)
val ivyFile = File(targetDir, "$intellijRuntimeAnnotations.ivy.xml")
@@ -181,20 +200,20 @@ val mergeSources by tasks.creating(Jar::class.java) {
val sourcesFile = mergeSources.outputs.files.singleFile
val makeIde = if (androidStudioBuild != null) {
buildIvyRepositoryTask(
buildIvyRepositoryTaskAndRegisterCleanupTask(
androidStudio,
customDepsOrg,
customDepsRepoDir,
if (androidStudioOs == "mac")
::skipContentsDirectory
else
::skipContentsDirectory
else
::skipToplevelDirectory
)
} else {
val task = if (installIntellijUltimate) {
buildIvyRepositoryTask(intellijUltimate, customDepsOrg, customDepsRepoDir, null, sourcesFile)
buildIvyRepositoryTaskAndRegisterCleanupTask(intellijUltimate, customDepsOrg, customDepsRepoDir, null, sourcesFile)
} else {
buildIvyRepositoryTask(intellij, customDepsOrg, customDepsRepoDir, null, sourcesFile)
buildIvyRepositoryTaskAndRegisterCleanupTask(intellij, customDepsOrg, customDepsRepoDir, null, sourcesFile)
}
task.configure {
@@ -204,8 +223,7 @@ val makeIde = if (androidStudioBuild != null) {
task
}
val buildJpsStandalone = buildIvyRepositoryTask(jpsStandalone, customDepsOrg, customDepsRepoDir, null, sourcesFile)
val buildNodeJsPlugin = buildIvyRepositoryTask(nodeJSPlugin, customDepsOrg, customDepsRepoDir, ::skipToplevelDirectory, sourcesFile)
val buildJpsStandalone = buildIvyRepositoryTaskAndRegisterCleanupTask(jpsStandalone, customDepsOrg, customDepsRepoDir, null, sourcesFile)
tasks.named("build") {
dependsOn(
@@ -215,11 +233,16 @@ tasks.named("build") {
makeIntellijAnnotations
)
if (installIntellijUltimate) {
dependsOn(buildNodeJsPlugin)
}
}
if (installIntellijUltimate) {
val buildNodeJsPlugin =
buildIvyRepositoryTaskAndRegisterCleanupTask(nodeJSPlugin, customDepsOrg, customDepsRepoDir, ::skipToplevelDirectory, sourcesFile)
tasks.named("build") { dependsOn(buildNodeJsPlugin) }
}
tasks.named("build") { dependsOn(cleanupDependencies) }
// Task to delete legacy repo locations
tasks.register<Delete>("cleanLegacy") {
delete("$projectDir/android-dx")
@@ -227,93 +250,114 @@ tasks.register<Delete>("cleanLegacy") {
}
tasks.named<Delete>("clean") {
//TODO specify repos to clean? Use CleanDataTask
delete(customDepsRepoDir)
}
fun buildIvyRepositoryTask(
fun buildIvyRepositoryTaskAndRegisterCleanupTask(
configuration: Configuration,
organization: String,
repoDirectory: File,
pathRemap: ((String) -> String)? = null,
sources: File? = null
) = tasks.register("buildIvyRepositoryFor${configuration.name.capitalize()}") {
): TaskProvider<Task> {
fun ResolvedArtifact.storeDirectory(): CleanableStore =
CleanableStore[repoDirectory.resolve("$organization/${moduleVersion.id.name}").absolutePath]
fun ResolvedArtifact.moduleDirectory(): File =
File(repoDirectory, "$organization/${moduleVersion.id.name}/${moduleVersion.id.version}")
storeDirectory()[moduleVersion.id.version].use()
dependsOn(configuration)
inputs.files(configuration)
val buildIvyRepositoryTask = tasks.register("buildIvyRepositoryFor${configuration.name.capitalize()}") {
dependsOn(configuration)
inputs.files(configuration)
if (verifyDependencyOutput) {
outputs.dir(provider {
configuration.resolvedConfiguration.resolvedArtifacts.single().moduleDirectory()
})
} else {
outputs.upToDateWhen {
configuration.resolvedConfiguration.resolvedArtifacts.single()
.moduleDirectory()
.exists()
}
}
doFirst {
configuration.resolvedConfiguration.resolvedArtifacts.single().run {
val moduleDirectory = moduleDirectory()
val artifactsDirectory = File(moduleDirectory(), "artifacts")
logger.info("Unpacking ${file.name} into ${artifactsDirectory.absolutePath}")
copy {
val fileTree = when (extension) {
"tar.gz" -> tarTree(file)
"zip" -> zipTree(file)
else -> error("Unsupported artifact extension: $extension")
if (verifyDependencyOutput) {
outputs.dir(
provider {
configuration.resolvedConfiguration.resolvedArtifacts.single().moduleDirectory()
}
from(fileTree.matching {
exclude("**/plugins/Kotlin/**")
})
into(artifactsDirectory)
if (pathRemap != null) {
eachFile {
path = pathRemap(path)
}
}
includeEmptyDirs = false
}
writeIvyXml(
organization,
moduleVersion.id.name,
moduleVersion.id.version,
moduleVersion.id.name,
File(artifactsDirectory, "lib"),
File(artifactsDirectory, "lib"),
File(moduleDirectory, "ivy"),
*listOfNotNull(sources).toTypedArray()
)
} else {
outputs.upToDateWhen {
configuration.resolvedConfiguration.resolvedArtifacts.single()
.moduleDirectory()
.exists()
}
}
val pluginsDirectory = File(artifactsDirectory, "plugins")
if (pluginsDirectory.exists()) {
file(File(artifactsDirectory, "plugins"))
.listFiles { file: File -> file.isDirectory }
.forEach {
writeIvyXml(
organization,
it.name,
moduleVersion.id.version,
it.name,
File(it, "lib"),
File(it, "lib"),
File(moduleDirectory, "ivy"),
*listOfNotNull(sources).toTypedArray()
)
doFirst {
configuration.resolvedConfiguration.resolvedArtifacts.single().run {
val moduleDirectory = moduleDirectory()
val artifactsDirectory = File(moduleDirectory(), "artifacts")
logger.info("Unpacking ${file.name} into ${artifactsDirectory.absolutePath}")
copy {
val fileTree = when (extension) {
"tar.gz" -> tarTree(file)
"zip" -> zipTree(file)
else -> error("Unsupported artifact extension: $extension")
}
from(
fileTree.matching {
exclude("**/plugins/Kotlin/**")
}
)
into(artifactsDirectory)
if (pathRemap != null) {
eachFile {
path = pathRemap(path)
}
}
includeEmptyDirs = false
}
writeIvyXml(
organization,
moduleVersion.id.name,
moduleVersion.id.version,
moduleVersion.id.name,
File(artifactsDirectory, "lib"),
File(artifactsDirectory, "lib"),
File(moduleDirectory, "ivy"),
*listOfNotNull(sources).toTypedArray()
)
val pluginsDirectory = File(artifactsDirectory, "plugins")
if (pluginsDirectory.exists()) {
file(File(artifactsDirectory, "plugins"))
.listFiles { file: File -> file.isDirectory }
.forEach {
writeIvyXml(
organization,
it.name,
moduleVersion.id.version,
it.name,
File(it, "lib"),
File(it, "lib"),
File(moduleDirectory, "ivy"),
*listOfNotNull(sources).toTypedArray()
)
}
}
}
}
}
val cleanupIvyRepositoryTask = tasks.register<CleanDataTask>("cleanupIvyRepositoryFor${configuration.name.capitalize()}") {
cleanableStoreProvider = provider {
configuration.resolvedConfiguration.resolvedArtifacts.single().storeDirectory()
}
}
cleanupDependencies {
dependsOn(cleanupIvyRepositoryTask)
}
return buildIvyRepositoryTask
}
fun writeIvyXml(

View File

@@ -20,7 +20,7 @@ buildscript {
}
}
dependencies {
classpath("org.jetbrains.kotlin:kotlin-build-gradle-plugin:0.0.12")
classpath("org.jetbrains.kotlin:kotlin-build-gradle-plugin:0.0.13")
}
}

View File

@@ -2,14 +2,12 @@
// usages in build scripts are not tracked properly
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
import org.gradle.api.GradleException
import org.gradle.api.Project
import org.gradle.api.artifacts.ProjectDependency
import org.gradle.api.artifacts.dsl.DependencyHandler
import org.gradle.api.file.ConfigurableFileCollection
import org.gradle.api.file.FileCollection
import org.gradle.api.tasks.AbstractCopyTask
import org.gradle.kotlin.dsl.extra
import org.gradle.kotlin.dsl.project
import java.io.File

View File

@@ -4,7 +4,7 @@ plugins {
}
group = "org.jetbrains.kotlin"
version = "0.0.12"
version = "0.0.13"
repositories {
mavenCentral()

View File

@@ -1,20 +1,20 @@
@file:Suppress("unused") // usages in build scripts are not tracked properly
/*
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
import org.gradle.api.Project
import org.gradle.kotlin.dsl.*
import java.net.URI
var Project.bootstrapKotlinVersion: String
get() = this.property("bootstrapKotlinVersion") as String
get() = property("bootstrapKotlinVersion") as String
private set(value) {
this.extra["bootstrapKotlinVersion"] = value
extensions.extraProperties.set("bootstrapKotlinVersion", value)
}
var Project.bootstrapKotlinRepo: String?
get() = this.property("bootstrapKotlinRepo") as String?
get() = property("bootstrapKotlinRepo") as String?
private set(value) {
this.extra["bootstrapKotlinRepo"] = value
extensions.extraProperties.set("bootstrapKotlinRepo", value)
}
val Project.internalKotlinRepo: String?
@@ -22,16 +22,16 @@ val Project.internalKotlinRepo: String?
"branch:default:any/artifacts/content/internal/repo"
fun Project.kotlinBootstrapFrom(defaultSource: BootstrapOption) {
val customVersion = project.findProperty("bootstrap.kotlin.version") as String?
val customRepo = project.findProperty("bootstrap.kotlin.repo") as String?
val teamCityVersion = project.findProperty("bootstrap.teamcity.kotlin.version") as String?
val teamCityBuild = project.findProperty("bootstrap.teamcity.build.number") as String?
val teamCityProject = project.findProperty("bootstrap.teamcity.project") as String?
val customVersion = findProperty("bootstrap.custom.kotlin.version") as String?
val customRepo = findProperty("bootstrap.custom.kotlin.repo") as String?
val teamCityVersion = findProperty("bootstrap.teamcity.kotlin.version") as String?
val teamCityBuild = findProperty("bootstrap.teamcity.build.number") as String?
val teamCityProject = findProperty("bootstrap.teamcity.project") as String?
val bootstrapSource = when {
project.hasProperty("bootstrap.local") -> BootstrapOption.Local(
project.findProperty("bootstrap.local.version") as String?,
project.findProperty("bootstrap.local.path") as String?
hasProperty("bootstrap.local") -> BootstrapOption.Local(
findProperty("bootstrap.local.version") as String?,
findProperty("bootstrap.local.path") as String?
)
teamCityVersion != null -> BootstrapOption.TeamCity(
teamCityVersion,
@@ -43,8 +43,8 @@ fun Project.kotlinBootstrapFrom(defaultSource: BootstrapOption) {
else -> defaultSource
}
bootstrapSource.applyToProject(project)
project.logger.lifecycle("Using kotlin bootstrap version $bootstrapKotlinVersion from repo $bootstrapKotlinRepo")
bootstrapSource.applyToProject(this)
logger.lifecycle("Using kotlin bootstrap version $bootstrapKotlinVersion from repo $bootstrapKotlinRepo")
}
sealed class BootstrapOption {

View File

@@ -19,16 +19,24 @@ class KotlinBuildProperties(
private val propertiesProvider: PropertiesProvider
) {
private val localProperties: Properties = Properties()
private val rootProperties: Properties = Properties()
init {
val localPropertiesFile = propertiesProvider.rootProjectDir.resolve("local.properties")
if (localPropertiesFile.isFile) {
localPropertiesFile.reader().use(localProperties::load)
loadPropertyFile("local.properties", localProperties)
loadPropertyFile("gradle.properties", rootProperties)
}
private fun loadPropertyFile(fileName: String, propertiesDestination: Properties) {
val propertiesFile = propertiesProvider.rootProjectDir.resolve(fileName)
if (propertiesFile.isFile) {
propertiesFile.reader().use(propertiesDestination::load)
}
}
private operator fun get(key: String): Any? = localProperties.getProperty(key) ?: propertiesProvider.getProperty(key)
private fun getLocalOrRoot(key: String): Any? = get(key) ?: rootProperties.getProperty(key)
private fun getBoolean(key: String, default: Boolean = false): Boolean =
this[key]?.toString()?.trim()?.toBoolean() ?: default
@@ -96,6 +104,10 @@ class KotlinBuildProperties(
val buildCacheUser: String? = get("kotlin.build.cache.user") as String?
val buildCachePassword: String? = get("kotlin.build.cache.password") as String?
val kotlinBootstrapVersion: String? = getLocalOrRoot("bootstrap.kotlin.version") as String?
val defaultSnapshotVersion: String? = getLocalOrRoot("defaultSnapshotVersion") as String?
}
private const val extensionName = "kotlinBuildProperties"

View File

@@ -1,13 +1,17 @@
org.gradle.jvmargs=-Duser.country=US -Dkotlin.daemon.jvm.options=-Xmx1600m -Dfile.encoding=UTF-8
cacheRedirectorEnabled=true
defaultSnapshotVersion=1.4-SNAPSHOT
kotlin.compiler.effectSystemEnabled=true
kotlin.compiler.newInferenceEnabled=true
#maven.repository.mirror=http://repository.jetbrains.com/remote-repos/
#bootstrap.kotlin.repo=https://dl.bintray.com/kotlin/kotlin-dev
#bootstrap.kotlin.version=1.1.50-dev-1451
#bootstrap.custom.kotlin.repo=https://dl.bintray.com/kotlin/kotlin-dev
#bootstrap.custom.kotlin.version=1.1.50-dev-1451
bootstrap.kotlin.version=1.4.0-dev-1148
#signingRequired=true
#org.gradle.debug=true
## The following properties can be added to your local.properties file to customize the build:

View File

@@ -1,24 +0,0 @@
org.gradle.jvmargs=-Duser.country=US -Dkotlin.daemon.jvm.options=-Xmx1600m -Dfile.encoding=UTF-8
cacheRedirectorEnabled=true
kotlin.compiler.effectSystemEnabled=true
kotlin.compiler.newInferenceEnabled=true
#maven.repository.mirror=http://repository.jetbrains.com/remote-repos/
#bootstrap.kotlin.repo=https://dl.bintray.com/kotlin/kotlin-dev
#bootstrap.kotlin.version=1.1.50-dev-1451
#signingRequired=true
intellijUltimateEnabled=false
intellijEnforceCommunitySdk=true
## The following properties can be added to your local.properties file to customize the build:
#jpsBuild=true
#cidrPluginsEnabled=true
## Used for compare gradle and jps build
#kotlin.build.postprocessing=false
#kotlin.build.java9=false
#kotlin.build.useBootstrapStdlib=true

View File

@@ -1,24 +0,0 @@
org.gradle.jvmargs=-Duser.country=US -Dkotlin.daemon.jvm.options=-Xmx1600m -Dfile.encoding=UTF-8
cacheRedirectorEnabled=true
kotlin.compiler.effectSystemEnabled=true
kotlin.compiler.newInferenceEnabled=true
#maven.repository.mirror=http://repository.jetbrains.com/remote-repos/
#bootstrap.kotlin.repo=https://dl.bintray.com/kotlin/kotlin-dev
#bootstrap.kotlin.version=1.1.50-dev-1451
#signingRequired=true
intellijUltimateEnabled=false
intellijEnforceCommunitySdk=true
## The following properties can be added to your local.properties file to customize the build:
#jpsBuild=true
#cidrPluginsEnabled=true
## Used for compare gradle and jps build
#kotlin.build.postprocessing=false
#kotlin.build.java9=false
#kotlin.build.useBootstrapStdlib=true

View File

@@ -1,24 +0,0 @@
org.gradle.jvmargs=-Duser.country=US -Dkotlin.daemon.jvm.options=-Xmx1600m -Dfile.encoding=UTF-8
cacheRedirectorEnabled=true
kotlin.compiler.effectSystemEnabled=true
kotlin.compiler.newInferenceEnabled=true
#maven.repository.mirror=http://repository.jetbrains.com/remote-repos/
#bootstrap.kotlin.repo=https://dl.bintray.com/kotlin/kotlin-dev
#bootstrap.kotlin.version=1.1.50-dev-1451
#signingRequired=true
intellijUltimateEnabled=false
intellijEnforceCommunitySdk=true
## The following properties can be added to your local.properties file to customize the build:
#jpsBuild=true
#cidrPluginsEnabled=true
## Used for compare gradle and jps build
#kotlin.build.postprocessing=false
#kotlin.build.java9=false
#kotlin.build.useBootstrapStdlib=true

View File

@@ -27,7 +27,7 @@ buildscript {
}
}
dependencies {
classpath("org.jetbrains.kotlin:kotlin-build-gradle-plugin:0.0.12")
classpath("org.jetbrains.kotlin:kotlin-build-gradle-plugin:0.0.13")
}
}