Slackbot
09/17/2022, 9:06 AMVladimir Sitnikov
09/17/2022, 2:23 PMProperty
for the properties?
It works great for both task properties and extension properties: https://docs.gradle.org/current/userguide/lazy_configuration.html#lazy_properties
It does resolve many issues with “value is set too late”
At the same time, there’s MapProperty
, so you could replace your own mutableMapOf
with MapProperty
Martmists
09/17/2022, 2:24 PMproperty = value
is nicer to work with compared to property.set(value)
, but I could try using them I guess 😕Vladimir Sitnikov
09/17/2022, 2:29 PM.set
is not that harmful, however, it makes the use of plugin WAY better. It is a real pain to integrate several plugins that use primitive fields instead of Property
Then, it looks like the upcoming Gradle (8?) would include a Kotlin plugin that would enable use of Property<..>
via regular prop = value
syntax: https://github.com/JetBrains/kotlin/pull/4933Martmists
09/17/2022, 2:52 PMVladimir Sitnikov
09/17/2022, 2:58 PMinit {
prop.convention(...)
}
See https://github.com/sigstore/sigstore-java/blob/8bf92a22ffd326834b5d61acff00abe1781[…]ugin/src/main/kotlin/dev/sigstore/sign/SigstoreSignExtension.ktMartmists
09/17/2022, 5:20 PMVladimir Sitnikov
09/17/2022, 5:42 PMMartmists
09/17/2022, 5:42 PMVladimir Sitnikov
09/17/2022, 5:44 PMMartmists
09/17/2022, 5:44 PMgradle setupMetadata
doesn't list the properties, that's the testVladimir Sitnikov
09/17/2022, 6:05 PMMartmists
09/17/2022, 6:06 PMVladimir Sitnikov
09/17/2022, 6:20 PMMartmists
09/17/2022, 6:21 PMimport com.martmists.kpy.plugin.PythonVersion
import org.jetbrains.kotlin.gradle.dsl.KotlinCommonOptions
import org.jetbrains.kotlin.gradle.dsl.KotlinCompile
import org.jetbrains.kotlin.gradle.targets.js.webpack.KotlinWebpack
import org.jetbrains.kotlin.gradle.tasks.Kotlin2JsCompile
plugins {
kotlin("multiplatform") version "1.7.0"
id("com.martmists.kpy.kpy-plugin") version "0.4.5"
}
group = "com.martmists"
version = "1.0.0"
val production: String? by project
val isDevelopment = production != "true"
repositories {
mavenCentral()
}
kotlin {
js("frontend", IR) {
browser {
commonWebpackConfig {
outputFileName = "index.js"
}
}
binaries.executable()
}
linuxX64("python") {
binaries {
staticLib(listOf(if (isDevelopment) DEBUG else RELEASE)) {
binaryOptions["memoryModel"] = "experimental"
}
}
}
linuxX64("backend") {
binaries {
executable(listOf(if (isDevelopment) DEBUG else RELEASE)){
binaryOptions["memoryModel"] = "experimental"
}
}
}
sourceSets {
val frontendMain by getting {
dependencies {
compileOnly(npm("decky-frontend-lib", "3.0.0"))
// Kotlin Wrappers
for ((module, version) in listOf(
"react" to "18.2.0-pre.383",
"react-dom" to "18.2.0-pre.383",
)) {
implementation("org.jetbrains.kotlin-wrappers:kotlin-$module:$version")
}
}
}
}
}
val plugin by sourceSets.creating {
resources {
srcDir("src/plugin")
}
}
val python by sourceSets.creating {
resources {
srcDir("src/pythonMain/python")
}
}
tasks {
withType<Kotlin2JsCompile> {
kotlinOptions {
freeCompilerArgs += listOfNotNull(
if (isDevelopment) null else "-Xir-minimized-member-names",
if (isDevelopment) null else "-Xir-dce",
if (isDevelopment) "-source-map" else null,
if (isDevelopment) "-source-map-embed-sources=always" else null,
"-Xir-build-cache",
"-opt-in=kotlin.js.ExperimentalJsExport",
)
}
}
withType<KotlinCompile<KotlinCommonOptions>> {
kotlinOptions {
freeCompilerArgs += listOfNotNull(
"-Xenable-incremental-compilation",
)
}
}
val webpackTask by named<KotlinWebpack>("frontendBrowser${if (isDevelopment) "Development" else "Production"}Webpack") {
outputs.upToDateWhen { false }
}
val buildPython by creating(Exec::class) {
dependsOn("pythonBinaries")
executable = "python3.10"
args("src/pythonMain/resources/setup.py", "build", "--build-lib=${buildDir}/python")
outputs.dir("${buildDir}/python")
}
val installPythonDev by creating(Exec::class) {
dependsOn(buildPython)
executable = "python3.10"
args("-m", "pip", "install", "--use-pep517", "-e", "src/pythonMain/resources")
}
val bundle by creating(Copy::class) {
dependsOn(webpackTask, named("backendBinaries"))
destinationDir = file("${buildDir}/bundle")
into(project.name) {
from(
python.resources,
buildPython,
"README.md",
"LICENSE",
)
from(plugin.resources){
filesMatching("package.json") {
expand(mapOf(
"project" to project.name.toLowerCase(),
"version" to project.version,
))
}
}
into("dist") {
from(webpackTask.destinationDirectory) {
// filter {
// it.replace("${project.name} =", "return")
// }
}
}
into("bin") {
from("${buildDir}/bin/backend/${if (isDevelopment) "debug" else "release"}Executable") {
rename(".*\\.kexe", "backend")
}
}
}
}
val bundleZip by creating(Zip::class) {
dependsOn(bundle)
archiveFileName.set("${project.name}-${project.version}.zip")
destinationDirectory.set(file("${buildDir}/bundled"))
from(bundle.destinationDir)
}
val build by getting {
dependsOn(bundleZip)
}
}
kpy {
target.set("python")
moduleName.set("plugin")
metadata("debug", if (isDevelopment) "True" else "False")
}
Martmists
09/17/2022, 6:23 PMdebug
should be set to True/False
, but it's not present in the setupMetadaa output:
project_name = "plugin"
project_version = "1.0.0"
build_dir = "/home/mart/git/DeckPlugin/build"
target = "python"
has_stubs = True