[Build] Fix configuration cache issues (part 2)
* Make WriteCopyrightToFile task compatible with configuration cache * Configure shadowJar task in compatible with configuration cache way * Configure compileJava9Java task in compatible with configuration cache way * Make :js:js.tests buildscript compatible with configuration cache Relates to #KT-44611
This commit is contained in:
@@ -25,7 +25,6 @@ import org.gradle.api.tasks.TaskProvider
|
||||
import org.gradle.api.tasks.Upload
|
||||
import org.gradle.api.tasks.javadoc.Javadoc
|
||||
import org.gradle.jvm.tasks.Jar
|
||||
import org.gradle.api.artifacts.dsl.DependencyHandler
|
||||
import org.gradle.kotlin.dsl.*
|
||||
import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSetContainer
|
||||
import plugins.KotlinBuildPublishingPlugin
|
||||
|
||||
@@ -8,48 +8,37 @@ package tasks
|
||||
import groovy.util.Node
|
||||
import groovy.util.XmlParser
|
||||
import org.gradle.api.DefaultTask
|
||||
import org.gradle.api.Project
|
||||
import org.gradle.api.file.RegularFileProperty
|
||||
import org.gradle.api.provider.Property
|
||||
import org.gradle.api.tasks.Input
|
||||
import org.gradle.api.tasks.InputFile
|
||||
import org.gradle.api.tasks.OutputFile
|
||||
import org.gradle.api.tasks.TaskAction
|
||||
import java.io.File
|
||||
import java.util.*
|
||||
|
||||
|
||||
|
||||
|
||||
open class WriteCopyrightToFile : DefaultTask() {
|
||||
|
||||
abstract class WriteCopyrightToFile : DefaultTask() {
|
||||
@InputFile
|
||||
var path = project.file("${project.rootDir}/.idea/copyright/apache.xml")
|
||||
val path = project.file("${project.rootDir}/.idea/copyright/apache.xml")
|
||||
|
||||
@OutputFile
|
||||
var outputFile: File? = null
|
||||
@get:OutputFile
|
||||
abstract val outputFile: RegularFileProperty
|
||||
|
||||
@Input
|
||||
var commented: Boolean = true
|
||||
@get:Input
|
||||
val commented: Property<Boolean> = project.objects.property(Boolean::class.java).convention(true)
|
||||
|
||||
@TaskAction
|
||||
fun write() {
|
||||
if (commented) {
|
||||
outputFile!!.writeText(project.readCopyrightCommented())
|
||||
} else {
|
||||
outputFile!!.writeText(project.readCopyright())
|
||||
}
|
||||
val file = outputFile.asFile.get()
|
||||
file.writeText(if (commented.get()) readCopyrightCommented() else readCopyright())
|
||||
}
|
||||
|
||||
|
||||
fun Project.readCopyright(): String {
|
||||
val file = rootDir.resolve(".idea/copyright/apache.xml")
|
||||
|
||||
assert(file.exists()) {
|
||||
"File $file with copyright not found"
|
||||
private fun readCopyright(): String {
|
||||
assert(path.exists()) {
|
||||
"File $path with copyright not found"
|
||||
}
|
||||
|
||||
|
||||
val xmlParser = XmlParser()
|
||||
val node = xmlParser.parse(file)
|
||||
val node = xmlParser.parse(path)
|
||||
assert(node.attribute("name") == "CopyrightManager") {
|
||||
"Format changed occasionally?"
|
||||
}
|
||||
@@ -59,7 +48,7 @@ open class WriteCopyrightToFile : DefaultTask() {
|
||||
return noticeNode.attribute("value").toString().replace("$today.year", GregorianCalendar()[Calendar.YEAR].toString())
|
||||
}
|
||||
|
||||
fun Project.readCopyrightCommented(): String {
|
||||
private fun readCopyrightCommented(): String {
|
||||
return "/*\n" + readCopyright().prependIndent(" * ") + "\n */"
|
||||
}
|
||||
}
|
||||
@@ -128,7 +128,6 @@ fun Project.rewriteDepsToShadedJar(
|
||||
archiveClassifier.set("original")
|
||||
}
|
||||
|
||||
val compilerDummyJarFile by lazy { configurations.getAt("compilerDummyJar").singleFile }
|
||||
|
||||
shadowJarTask.configure {
|
||||
dependsOn(originalJarTask)
|
||||
@@ -136,7 +135,8 @@ fun Project.rewriteDepsToShadedJar(
|
||||
|
||||
// When Gradle traverses the inputs, reject the shaded compiler JAR,
|
||||
// which leads to the content of that JAR being excluded as well:
|
||||
exclude { it.file == compilerDummyJarFile }
|
||||
val compilerDummyJarFile = project.provider { configurations.getByName("compilerDummyJar").singleFile }
|
||||
exclude { it.file == compilerDummyJarFile.get() }
|
||||
|
||||
archiveClassifier.set("original")
|
||||
body()
|
||||
|
||||
@@ -1,6 +1,3 @@
|
||||
|
||||
import org.gradle.jvm.tasks.Jar
|
||||
|
||||
description = "Compiler runner + daemon client"
|
||||
|
||||
plugins {
|
||||
|
||||
@@ -20,8 +20,8 @@ dependencies {
|
||||
}
|
||||
|
||||
val writeCopyright by task<tasks.WriteCopyrightToFile> {
|
||||
outputFile = file("$buildDir/copyright/notice.txt")
|
||||
commented = true
|
||||
outputFile.set(file("$buildDir/copyright/notice.txt"))
|
||||
commented.set(true)
|
||||
}
|
||||
|
||||
application {
|
||||
|
||||
@@ -28,8 +28,8 @@ dependencies {
|
||||
}
|
||||
|
||||
val writeCopyright by task<WriteCopyrightToFile> {
|
||||
outputFile = file("$buildDir/copyright/notice.txt")
|
||||
commented = true
|
||||
outputFile.set(file("$buildDir/copyright/notice.txt"))
|
||||
commented.set(true)
|
||||
}
|
||||
|
||||
application {
|
||||
|
||||
@@ -23,8 +23,8 @@ dependencies {
|
||||
}
|
||||
|
||||
val writeCopyright by task<tasks.WriteCopyrightToFile> {
|
||||
outputFile = file("$buildDir/copyright/notice.txt")
|
||||
commented = true
|
||||
outputFile.set(file("$buildDir/copyright/notice.txt"))
|
||||
commented.set(true)
|
||||
}
|
||||
|
||||
application {
|
||||
|
||||
@@ -104,7 +104,7 @@ val currentOsType = run {
|
||||
else -> OsName.UNKNOWN
|
||||
}
|
||||
|
||||
val osArch = when (System.getProperty("sun.arch.data.model")) {
|
||||
val osArch = when (providers.systemProperty("sun.arch.data.model").forUseAtConfigurationTime().get()) {
|
||||
"32" -> OsArch.X86_32
|
||||
"64" -> OsArch.X86_64
|
||||
else -> OsArch.UNKNOWN
|
||||
@@ -219,13 +219,15 @@ fun Test.setUpBoxTests() {
|
||||
workingDir = rootDir
|
||||
dependsOn(antLauncherJar)
|
||||
inputs.files(antLauncherJar)
|
||||
val antLauncherJarPath = antLauncherJar.asPath
|
||||
doFirst {
|
||||
systemProperty("kotlin.ant.classpath", antLauncherJar.asPath)
|
||||
systemProperty("kotlin.ant.classpath", antLauncherJarPath)
|
||||
systemProperty("kotlin.ant.launcher.class", "org.apache.tools.ant.Main")
|
||||
}
|
||||
|
||||
systemProperty("kotlin.js.test.root.out.dir", "$buildDir/")
|
||||
systemProperty("overwrite.output", findProperty("overwrite.output") ?: "false")
|
||||
systemProperty("overwrite.output", project.providers.gradleProperty("overwrite.output")
|
||||
.forUseAtConfigurationTime().orNull ?: "false")
|
||||
|
||||
val prefixForPpropertiesToForward = "fd."
|
||||
for ((key, value) in properties) {
|
||||
|
||||
@@ -62,9 +62,10 @@ ext.compileJava9Sources = { Project project, String moduleName, Collection<FileC
|
||||
it.options.forkOptions.javaHome = file(JDK_9)
|
||||
it.options.sourcepath = files(java9SourceSet.srcDirs)
|
||||
def compileClasspath = project.configurations.java9CompileClasspath
|
||||
def objects = project.objects
|
||||
|
||||
doFirst {
|
||||
def moduleFiles = files(*moduleOutputs)
|
||||
def moduleFiles = objects.fileCollection().from(*moduleOutputs)
|
||||
def modulePath = compileClasspath.filter { !(it in moduleFiles.files) }
|
||||
|
||||
options.compilerArgs = [
|
||||
@@ -73,7 +74,7 @@ ext.compileJava9Sources = { Project project, String moduleName, Collection<FileC
|
||||
'-Xlint:-requires-transitive-automatic' // suppress automatic module transitive dependencies in kotlin.test
|
||||
]
|
||||
|
||||
classpath = files()
|
||||
classpath = objects.fileCollection().from()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user