try fixing gradle config cache errors
This commit is contained in:
parent
24e4cdf329
commit
5656acd350
7 changed files with 128 additions and 56 deletions
|
|
@ -3,7 +3,9 @@ package dev.adamko.kafkatorio.gradle
|
|||
import java.io.ByteArrayOutputStream
|
||||
import org.gradle.api.Project
|
||||
import org.gradle.api.file.Directory
|
||||
import org.gradle.api.file.FileCopyDetails
|
||||
import org.gradle.api.file.ProjectLayout
|
||||
import org.gradle.api.file.RelativePath
|
||||
import org.gradle.api.specs.NotSpec
|
||||
import org.gradle.api.specs.Spec
|
||||
import org.gradle.plugins.ide.idea.model.IdeaModule
|
||||
|
|
@ -14,8 +16,8 @@ import org.jetbrains.kotlin.incremental.md5
|
|||
|
||||
|
||||
operator fun <T> Spec<T>.not(): NotSpec<T> = NotSpec(this)
|
||||
//
|
||||
//
|
||||
|
||||
|
||||
//fun isProcessRunning(process: String, ignoreCase: Boolean = true): Spec<Task> =
|
||||
// Spec<Task> {
|
||||
// ByteArrayOutputStream().use { outputStream ->
|
||||
|
|
@ -59,6 +61,7 @@ fun Project.execCapture(spec: ExecSpec.() -> Unit): String {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
/** https://youtrack.jetbrains.com/issue/KT-50848 */
|
||||
fun Project.yarn(configure: YarnRootExtension.() -> Unit) = with(yarn, configure)
|
||||
|
||||
|
|
@ -68,3 +71,8 @@ fun Directory.filesChecksum() = asFileTree
|
|||
.map { it.readBytes() + it.absolutePath.toByteArray() }
|
||||
.fold(byteArrayOf()) { acc, bytes -> acc + bytes }
|
||||
.md5()
|
||||
|
||||
|
||||
/** Drop the first [count] directories from the path */
|
||||
fun FileCopyDetails.dropDirectories(count: Int = 1): RelativePath =
|
||||
RelativePath(true, *relativePath.segments.drop(count).toTypedArray())
|
||||
|
|
|
|||
|
|
@ -16,11 +16,14 @@ node {
|
|||
distBaseUrl.set(null as String?) // set by dependencyResolutionManagement
|
||||
}
|
||||
|
||||
val projectVersion: Provider<String> = providers.provider { "${project.version}" }
|
||||
|
||||
val updatePackageJson by tasks.registering(UpdatePackageJson::class) {
|
||||
// group = NodePlugin.NODE_GROUP
|
||||
// description = "Read the package.json file and update the version and name, based on the project."
|
||||
|
||||
propertiesToCheck.put("version", providers.provider { "${project.version}" })
|
||||
inputs.property("projectVersion", projectVersion)
|
||||
propertiesToCheck.put("version", projectVersion)
|
||||
|
||||
// check to see if the properties are already up-to-date
|
||||
// outputs.upToDateWhen(areJsonPropertiesUpToDate(packageJsonFile, propertiesToCheck))
|
||||
|
|
|
|||
|
|
@ -0,0 +1,35 @@
|
|||
package dev.adamko.kafkatorio.task
|
||||
|
||||
import javax.inject.Inject
|
||||
import org.gradle.api.file.DirectoryProperty
|
||||
import org.gradle.api.file.FileSystemOperations
|
||||
import org.gradle.api.tasks.JavaExec
|
||||
import org.gradle.api.tasks.OutputDirectory
|
||||
import org.gradle.api.tasks.TaskAction
|
||||
|
||||
|
||||
abstract class GenerateTypescriptTask @Inject constructor(
|
||||
private val fileOps: FileSystemOperations,
|
||||
) : JavaExec() {
|
||||
|
||||
@get:OutputDirectory
|
||||
abstract val output: DirectoryProperty
|
||||
|
||||
init {
|
||||
group = "kt2ts"
|
||||
}
|
||||
|
||||
@TaskAction
|
||||
fun generate() {
|
||||
fileOps.delete { delete(temporaryDir) }
|
||||
temporaryDir.mkdirs()
|
||||
|
||||
super.exec()
|
||||
|
||||
fileOps.sync {
|
||||
from(temporaryDir)
|
||||
into(output)
|
||||
include("**/*.ts")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -19,7 +19,9 @@ import org.gradle.kotlin.dsl.support.useToRun
|
|||
import org.jetbrains.kotlin.util.suffixIfNot
|
||||
|
||||
@CacheableTask
|
||||
abstract class UpdatePackageJson : DefaultTask() {
|
||||
abstract class UpdatePackageJson @Inject constructor(
|
||||
private val providers: ProviderFactory
|
||||
) : DefaultTask() {
|
||||
|
||||
@get:Input
|
||||
abstract val propertiesToCheck: MapProperty<String, String>
|
||||
|
|
@ -27,15 +29,10 @@ abstract class UpdatePackageJson : DefaultTask() {
|
|||
@get:OutputFile
|
||||
abstract val packageJsonFile: RegularFileProperty
|
||||
|
||||
@get:Inject
|
||||
abstract val providers: ProviderFactory
|
||||
//
|
||||
// @get:Inject
|
||||
// abstract val fs: FileSystemOperations
|
||||
|
||||
init {
|
||||
group = NodePlugin.NODE_GROUP
|
||||
description = "Read the package.json file and update the version and name, based on the project."
|
||||
description =
|
||||
"Read the package.json file and update the version and name, based on the project."
|
||||
|
||||
outputs.upToDateWhen(JsonPropertiesUpToDateSpec)
|
||||
|
||||
|
|
@ -47,12 +44,13 @@ abstract class UpdatePackageJson : DefaultTask() {
|
|||
|
||||
@TaskAction
|
||||
fun exec() {
|
||||
val pj = packageJsonFile.asFile.get()
|
||||
val packageJsonFile = packageJsonFile.asFile.get()
|
||||
val propertiesToCheck = propertiesToCheck.get()
|
||||
|
||||
logger.info("updating package.json ${pj.canonicalPath}")
|
||||
val packageJson = jsonMapper.parseToJsonElement(pj.readText()).jsonObject
|
||||
logger.info("updating package.json ${packageJsonFile.canonicalPath}")
|
||||
val packageJson = jsonMapper.parseToJsonElement(packageJsonFile.readText()).jsonObject
|
||||
|
||||
val newJsonProps = propertiesToCheck.get().mapValues { (_, newVal) -> JsonPrimitive(newVal) }
|
||||
val newJsonProps = propertiesToCheck.mapValues { (_, newVal) -> JsonPrimitive(newVal) }
|
||||
|
||||
val packageJsonUpdate = JsonObject(packageJson + newJsonProps)
|
||||
val packageJsonContentUpdated =
|
||||
|
|
@ -62,7 +60,7 @@ abstract class UpdatePackageJson : DefaultTask() {
|
|||
|
||||
logger.debug(packageJsonContentUpdated)
|
||||
|
||||
packageJsonFile.get().asFile.writer().useToRun {
|
||||
packageJsonFile.writer().useToRun {
|
||||
write(packageJsonContentUpdated)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue