[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()
|
||||
|
||||
Reference in New Issue
Block a user