Developer Quickstart
This guide explains how to create, package, and run an SPW plugin. The Kotlin API also supports Java callers. Extend SpwPlugin for the plugin lifecycle, use WorkshopApi to access the player, and implement extension points to receive events.
Requirements
The examples use Workshop API and Workshop Gradle plugin version 0.1.0-dev22. This version was compiled with Kotlin 2.4.20 and Java 25.
- Install JDK 25 or later. Select it as the Gradle JDK in your IDE and set
JAVA_HOMEto it on the command line - Use Kotlin 2.4.20 or later for Kotlin plugins. Java-only projects can omit the Kotlin plugin
- Use a Gradle Wrapper that supports JDK 25. See the Workshop API project's wrapper configuration for an example
If your plugin uses Compose UI, also configure the Compose compiler and match the host's Kotlin and Compose versions. See Direct Hook API.
Project Structure
Create a Kotlin or Java JVM project with the Gradle Wrapper and organize your source and build files as follows.
my-plugin/
├── settings.gradle.kts
├── build.gradle.kts
├── gradle.properties
├── gradlew
├── gradlew.bat
├── gradle/
│ ├── libs.versions.toml
│ └── wrapper/
└── src/main/
├── kotlin/com/example/myplugin/
│ ├── MainPlugin.kt
│ └── PlaybackExtension.kt
└── resources/
└── preference_config.jsonPut Java source in src/main/java/. Add preference_config.json if your plugin provides a settings interface.
Configure Gradle
API Dependency
Add the API version and dependency to gradle/libs.versions.toml. This example uses 0.1.0-dev22.
[versions]
spw-workshop-api = "0.1.0-dev22"
[libraries]
spw-workshop-api = { group = "com.github.Moriafly", name = "spw-workshop-api", version.ref = "spw-workshop-api" }Repositories and Plugin Resolution
Edit settings.gradle.kts at the root of your plugin project. Add the settings below to your existing configuration blocks and keep any repositories or settings the project already uses.
- Add JitPack to
pluginManagement.repositoriesto download the Workshop Gradle plugin - Use the
useModule(...)mapping below inpluginManagement.resolutionStrategy.eachPluginto resolve the plugin ID to the implementation published on JitPack - Add JitPack to
dependencyResolutionManagement.repositoriesto download dependencies such as Workshop API
This example is for a new plugin project. Set rootProject.name to your project's name.
pluginManagement {
repositories {
maven("https://jitpack.io")
gradlePluginPortal()
}
resolutionStrategy {
eachPlugin {
if (requested.id.id == "com.xuncorp.spw.workshop") {
useModule(
"com.github.Moriafly.spw-workshop-api:spw-workshop-gradle-plugin:${requested.version}"
)
}
}
}
}
dependencyResolutionManagement {
repositories {
google()
mavenCentral()
maven("https://jitpack.io")
}
}
rootProject.name = "my-plugin"Why the mapping is required
JitPack publishes the modules under the group ID com.github.Moriafly.spw-workshop-api. Gradle's default plugin marker coordinates are different, so keep the useModule(...) mapping to resolve the implementation. See the JitPack multi-module docs and Gradle plugin marker documentation.
Continue to use the plugin ID com.xuncorp.spw.workshop in the module. ${requested.version} uses the Workshop Gradle plugin version in the module's plugins block.
Module Build Configuration
Edit build.gradle.kts or build.gradle in the plugin module. Choose the example corresponding to your project's DSL.
- Apply the Kotlin JVM, Kapt, and Workshop Gradle plugins. Use Workshop Gradle plugin version
0.1.0-dev22to match the API dependency - Declare the API and Kotlin standard library with
compileOnly, and usekaptto process@Extensionand generate the extension index. Useimplementationfor dependencies that must ship with the plugin - Set your metadata in
spmod.PluginClassmust match the fully qualified name of your main class. Choose a unique, stablePluginId
These examples use JDK 25 and a main class named com.example.myplugin.MainPlugin.
plugins {
id("java-library")
kotlin("jvm") version "2.4.20"
kotlin("kapt") version "2.4.20"
id("com.xuncorp.spw.workshop") version "0.1.0-dev22"
}
java {
sourceCompatibility = JavaVersion.VERSION_25
targetCompatibility = JavaVersion.VERSION_25
}
kotlin {
jvmToolchain(25)
}
dependencies {
compileOnly(kotlin("stdlib"))
compileOnly(libs.spw.workshop.api)
kapt(libs.spw.workshop.api)
}
spmod {
PluginClass = "com.example.myplugin.MainPlugin"
PluginId = "com.example.myplugin"
PluginVersion = "1.0.0"
PluginProvider = "Example"
PluginName = "My Plugin"
PluginDescription = "An example Salt Player plugin"
}plugins {
id 'java-library'
id 'org.jetbrains.kotlin.jvm' version '2.4.20'
id 'org.jetbrains.kotlin.kapt' version '2.4.20'
id 'com.xuncorp.spw.workshop' version '0.1.0-dev22'
}
java {
sourceCompatibility = JavaVersion.VERSION_25
targetCompatibility = JavaVersion.VERSION_25
}
kotlin {
jvmToolchain(25)
}
dependencies {
compileOnly 'org.jetbrains.kotlin:kotlin-stdlib'
compileOnly libs.spw.workshop.api
kapt libs.spw.workshop.api
}
spmod { config ->
config.PluginClass = "com.example.myplugin.MainPlugin"
config.PluginId = "com.example.myplugin"
config.PluginVersion = "1.0.0"
config.PluginProvider = "Example"
config.PluginName = "My Plugin"
config.PluginDescription = "An example Salt Player plugin"
}The host provides the API and Kotlin standard library. Use compileOnly to avoid bundling another copy in your plugin.
For a Java-only project, remove the Kotlin JVM and Kapt plugins, the kotlin {} block, and the explicit Kotlin standard library dependency. Replace kapt(libs.spw.workshop.api) with annotationProcessor(libs.spw.workshop.api) and keep the API's compileOnly dependency.
Write the Plugin Class
Create a class that extends SpwPlugin in src/main/kotlin/com/example/myplugin/MainPlugin.kt for Kotlin or src/main/java/com/example/myplugin/MainPlugin.java for Java. Pass the host's PluginContext to the superclass constructor and use the class's fully qualified name as PluginClass.
package com.example.myplugin
import com.xuncorp.spw.workshop.api.PluginContext
import com.xuncorp.spw.workshop.api.SpwPlugin
import com.xuncorp.spw.workshop.api.WorkshopApi
class MainPlugin(pluginContext: PluginContext) : SpwPlugin(pluginContext) {
override fun start() {
WorkshopApi.ui.toast("Plugin enabled", WorkshopApi.Ui.ToastType.Success)
}
override fun stop() {
println("Plugin stopped")
}
}package com.example.myplugin;
import com.xuncorp.spw.workshop.api.PluginContext;
import com.xuncorp.spw.workshop.api.SpwPlugin;
import com.xuncorp.spw.workshop.api.WorkshopApi;
public class MainPlugin extends SpwPlugin {
public MainPlugin(PluginContext pluginContext) {
super(pluginContext);
}
@Override
public void start() {
WorkshopApi.ui().toast("Plugin enabled", WorkshopApi.Ui.ToastType.Success);
}
@Override
public void stop() {
System.out.println("Plugin stopped");
}
}Listen for Playback Events
In src/main/kotlin/com/example/myplugin/PlaybackExtension.kt, implement PlaybackExtensionPoint, add PF4J's @Extension annotation, and override the callbacks you need. This example logs play state and position.
package com.example.myplugin
import com.xuncorp.spw.workshop.api.PlaybackExtensionPoint
import org.pf4j.Extension
@Extension
class PlaybackExtension : PlaybackExtensionPoint {
override fun onIsPlayingChanged(isPlaying: Boolean) {
println("Playing: $isPlaying")
}
override fun onPositionUpdated(position: Long) {
println("Playback position: $position ms")
}
}| Callback | Purpose |
|---|---|
onStateChanged(state) | Receive transitions between Idle, Buffering, Ready, and Ended. |
onIsPlayingChanged(isPlaying) | Receive play and pause state changes. |
onSeekTo(position) | Receive seeks, with the position in milliseconds. |
onPositionUpdated(position) | Receive playback position updates in milliseconds once per second. |
onBeforeLoadLyrics(mediaItem) | Supply lyrics before the default loader runs. Return null to let the default loader continue. |
onAfterLoadLyrics(mediaItem) | Supply fallback lyrics when the default loader cannot find lyrics. Prefer this callback for most plugins. |
onLyricsLineUpdated(lyricsLine) | Receive changes to the current line, which may be null. |
onLyricsLinesUpdated(lyricsLines) | Receive the full lyrics timeline. Available since API 0.1.0-dev21. |
Both lyrics-loading callbacks run on I/O threads. An empty timeline means no timeline is currently available. An empty list can occur when a track changes, when lyrics reload, when no lyrics exist, or when loading fails. Multiple notifications can occur during one load.
Plugin Metadata
Field names in spmod {} start with an uppercase letter. In Groovy, use config.PluginId and similar forms to avoid name collisions with types Gradle imports by default.
| Field | Manifest attribute | Meaning |
|---|---|---|
PluginClass | Plugin-Class | Required. Fully qualified name of the main class extending SpwPlugin. |
PluginId | Plugin-Id | Required. Unique, stable plugin ID. Reverse domain notation is recommended. |
PluginVersion | Plugin-Version | Required. Semantic versioning is recommended. |
PluginProvider | Plugin-Provider | Optional. Plugin author. |
PluginName | Plugin-Name | Optional. Display name. |
PluginDescription | Plugin-Description | Optional. Plugin description. |
PluginOpenSourceUrl | Plugin-Open-Source-Url | Optional. Source code URL. |
PluginHasConfig | Plugin-Has-Config | Defaults to false. Set to true to provide a settings interface. See Plugin Configuration. |
PluginPermissions | Plugin-Permissions | Defaults to an empty list. Use the permission enum from the Workshop Gradle plugin. See Plugin Permissions. |
The build reports empty required fields and omits unset optional strings from the manifest. Keep PluginId stable and increment PluginVersion for updates.
Lifecycle and Cleanup
| Callback | What to do |
|---|---|
start() | Enable the plugin and register events, shortcuts, hooks, or settings listeners. |
stop() | Disable the plugin and release its listeners, threads, and other resources. |
delete() | Perform plugin-specific cleanup when the plugin is deleted. |
update() | Handle updates performed through the player's local update flow. External file replacement may bypass this callback. |
A plugin may be enabled and disabled repeatedly. Register what you need on each call to start() and release plugin-owned resources in stop(). Register shortcuts on the same thread that runs start(). See Plugin Permissions and Direct Hook API for automatic cleanup, and Plugin Performance for startup and background task guidance.
The player assigns WorkshopApi.instance during startup. Leave that property to the host. Kotlin callers must opt in with @OptIn(UnstableSpwWorkshopApi::class) to use APIs marked UnstableSpwWorkshopApi.
Build and Install
Run the plugin task from the root of your plugin project.
.\gradlew.bat plugin./gradlew pluginFor a multi-module project, specify the plugin module. Use .\gradlew.bat :example:plugin on Windows or ./gradlew :example:plugin on Linux. The single-module example on this page produces build/libs/plugin-com.example.myplugin-1.0.0.spmod.
Follow the local import steps to install the .spmod package. After enabling the example plugin, you should see Plugin enabled.
Source availability
We encourage you to open-source your mods and publish unobfuscated plugin code so users can inspect what they install.
See Publish Mods to share your work on GitHub or Steam Workshop.
Fix Plugin Resolution Errors
If Gradle reports UnknownPluginException during sync or build, check Repositories and Plugin Resolution, then sync or build again.
- Confirm that
resolutionStrategyis insidepluginManagementin the project's rootsettings.gradle.kts, and that it mapscom.xuncorp.spw.workshopusinguseModule(...) - Confirm that JitPack is in
pluginManagement.repositories. Gradle uses a separate repository list independencyResolutionManagement.repositoriesfor regular dependencies - Confirm that the plugin and API versions match. Check the JitPack build history for a successful build of the corresponding tag or commit
This error shows Gradle is still looking for the default plugin marker coordinates. Check the mapping and plugin repositories first.
could not resolve plugin artifact 'com.xuncorp.spw.workshop:com.xuncorp.spw.workshop.gradle.plugin:0.1.0-dev22'This error shows Gradle is looking for the JitPack implementation. Check the version, build status, and network or proxy settings.
com.github.Moriafly.spw-workshop-api:spw-workshop-gradle-plugin:0.1.0-dev22For 0.1.0-dev22, you can inspect the plugin implementation POM to confirm the coordinates. Check the corresponding JitPack build and artifacts to confirm availability.
Continue with Plugin Configuration, Plugin Permissions, or Direct Hook API. For source and a complete project, see SPW Workshop API and its example module.
