This message was deleted.
# plugin-development
s
This message was deleted.
v
Have you tried using
Property
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
m
I personally want to avoid properties since
property = value
is nicer to work with compared to
property.set(value)
, but I could try using them I guess 😕
v
.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/4933
m
How would I set defaults on the properties of this extension?
m
I switched to properties, but the map entries still don't get passed to the task
v
Where's the test?
m
what test?
v
The one that shows "properties not passing to the task"
m
I have the plugin applied in a local project with properties added, but running
gradle setupMetadata
doesn't list the properties, that's the test
v
What do you mean by "doesn't list the properties"? Where are the properties configured?
m
on the extension using metadata() in my build.gradle.kts, as documented in the project's readme
v
Would you please show a sample project that configures the extension and that "doesn't list the properties"?
m
Here it is as part of a larger project
Copy code
import 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")
}
Now as you can see on the bottom,
debug
should be set to
True/False
, but it's not present in the setupMetadaa output:
Copy code
project_name = "plugin"
project_version = "1.0.0"
build_dir = "/home/mart/git/DeckPlugin/build"
target = "python"
has_stubs = True