agentleFS
JetBrainsKnown publisherJetBrains/koog/.claude/skills/split-jvm-nonjvm/SKILL.md

split-jvm-nonjvm

Skill4.6k starsChanged 7 months agoApache-2.0View on GitHub

Splits a class or several classes in the common source set commonMain into JVM and non-JVM parts into jvmCommonMain and nonJvmCommonMain. This is used to provide some JVM-specific functionality for a class on JVM targets (e.g. Kotlin/JVM or Java backend or Android).

Trending

Quiet since October.about the whole repository

Jan 2026: 0 mentionsFeb 2026: 2 mentionsMar 2026: 5 mentionsApr 2026: 2 mentionsMay 2026: 2 mentionsJun 2026: 0 mentionsJul 2026: 4 mentionsAug 2026: 3 mentionsSep 2026: 12 mentionsOct 2026: 5 mentionsNov 2026: 0 mentionsDec 2026: 0 mentions
Jan 2026Jul 2026Dec 2026
Mentions a month of the JetBrains/koog repository that our weekly crawl found. There is no adoption data for this file yet.

Who's talking about JetBrains/koog

The biggest 5 of 59 mentions linking to the repository that our crawl found. Each line is their own headline.

See all 59

Talked about on GitHub, Bluesky and Hacker News (59 times).

On GitHub · 46

41 more on GitHub

On Bluesky · 12

7 more on Bluesky

On Hacker News · 1

The file

We split this skill into the rules it gives an agent

10 rules. About 0 are common, 5 are distinctive, and 5 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈5

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 5

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    When using this skill, avoid unnecessarily looking at existing implementations of the split in the project, just follow this instruction.

    line 9
  2. Very specific:

    If MyClass had any internal symbols, these should also be listed in the expect class along with their KDocs.

    line 95
  3. Very specific:

    If MyClass had a KDoc, add it on top of the expect class without parameters/properties description.

    line 96
  4. Very specific:

    If MyClass original KDoc described certain parameters/properties that it accepted in its constructor, add these to KDoc of the expect class …

    line 97
  5. Distinctive:

    After these steps, the structure should look as follows, omitting irrelevant packages and files:

    line 136
  6. Distinctive:

    If the users asked for certain JVM-specific/non-JVM-specific functionality, these actual classes might contain additional public symbols …

    line 179
  7. Very specific:

    Do not rename the test, it should still be called e.g.

    line 207
  8. Very specific:

    If you need to test some platform-specific functionality, create tests in jvmCommonTest and/or nonJvmCommonTest source sets.

    line 208
  9. Distinctive:

    If both pass, the split is working correctly.

    line 218
  10. Distinctive:

    When creating the new files (API interface, Impl, expect class, actual classes), carry over all relevant imports from the original class.

    line 227

≈ “Common” is an estimate: at least 1 in 5 of the 213,897 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

The following example shows how to split a class into JVM and non-JVM parts. When using this skill, avoid unnecessarily looking at existing implementations of the split in the project, just follow this instruction. You can, however, check existing implementations for reference if you have a complex case or otherwise stuck.

Here's a sample class in a commonMain source set

package com.example

/**
* A sample class with an external dependency, some logic and public methods
 * @param name Some public property
 * @param myRepo Some external dependency, private property
*/
public class MyClass(
    public val name: String,
    private val myRepo: MyRepo,
) {
    /**
     * Public API method
     */
    public fun doSomething(): String {
        return fetchData()
    }
    
    /**
     * Private implementation logic
     */
    private fun fetchData(): String {
        return myRepo.getData()
    }
    
    /*
     * Internal method
     */
    internal fun doInternal(): String {
        return "Internal"
    }
}

In the same package as MyClass in commonMain, create the following files. The original MyClass.kt file will be overwritten with the expect class (see step three).

First, the API interface describing the contract. It should contain only public symbols from the MyClass. Take KDocs from the respective symbols in MyClass and add them to the interface.

package com.example

/**
 * API for [MyClass]
 */
public interface MyClassAPI {
    /**
     * Some public property
     */
    public val name: String
    
    /**
     * Public API method
     */
    public fun doSomething(): String
}

Second, MyClassImpl.kt — implementation of the API interface providing the implementation logic. The filename matches the class name.

internal class MyClassImpl(
    override val name: String,
    private val myRepo: MyRepo,
) : MyClassAPI {
    override fun doSomething(): String {
        return fetchData()
    }
    
    private fun fetchData(): String {
        return myRepo.getData()
    }
    
    internal fun doInternal(): String {
        return "Internal"
    }
}

Third, the original class becomes expect class MyClass should extend MyClassAPI and override all public symbols from MyClassAPI, without method bodies and property values, since expect classes can't have any. If MyClass had any internal symbols, these should also be listed in the expect class along with their KDocs. If MyClass had a KDoc, add it on top of the expect class without parameters/properties description. If MyClass original KDoc described certain parameters/properties that it accepted in its constructor, add these to KDoc of the expect class secondary constructor. This constructor KDoc can't have @property tag for parameters, use only @param for all parameters, even if the original was @property.

package com.example

/**
 * A sample class with an external dependency, some logic and public methods
 */
public expect class MyClass internal constructor(
    delegate: MyClassImpl,
) : MyClassAPI {
    /**
     * Constructs a new instance of [MyClass]
     * 
     * @param name Some public property
     * @param myRepo Some external dependency,
     */
    public constructor(
        name: String,
        myRepo: MyRepo,
    )
    
    internal val delegate: MyClassImpl
    
    override val name: String
    override fun doSomething(): String
    
    /**
     * Internal method
     */
    internal fun doInternal(): String
}

Fourth, ensure that jvmCommonMain and nonJvmCommonMain source sets have a package directory for MyClass, i.e., com.example. If not, create missing package directories. The source sets themselves are already declared in the Gradle convention plugin — you do NOT need to add them to the module's build.gradle.kts unless you need to add dependencies specifically for these source sets. Then, create MyClass.kt files in jvmCommonMain and nonJvmCommonMain source sets.

After these steps, the structure should look as follows, omitting irrelevant packages and files:

commonMain/
    kotlin/
        com/example/
            MyClass.kt
            MyClassAPI.kt
            MyClassImpl.kt
jvmCommonMain/
    kotlin/
        com/example/
            MyClass.kt
nonJvmCommonMain/
    kotlin/
        com/example/
            MyClass.kt

Fifth, in MyClass.kt files in jvmCommonMain and nonJvmCommonMain create actual declarations for MyClass. Initially, they should be identical for both source sets. It should use by delegate to delegate all public symbols from MyClassAPI to the implementation, and direct delegation to delegate internal symbols.

// Suppress IntelliJ warnings
@file:Suppress("MissingKDocForPublicAPI")

package com.example

public actual class MyClass internal actual constructor(
    internal actual val delegate: MyClassImpl,
) : MyClassAPI by delegate {
    public actual constructor(
        name: String,
        myRepo: MyRepo,
    ) : this(
        delegate = MyClassImpl(name, myRepo)
    )
    
    internal actual fun doInternal(): String = delegate.doInternal()
}

Sixth, optional, step. If the users asked for certain JVM-specific/non-JVM-specific functionality, these actual classes might contain additional public symbols not present in the API interface. Such additional public symbols should be documented properly and concisely with KDoc

For example, jvmCommonMain implementation that uses JVM-specific API

// Suppress IntelliJ warnings
@file:Suppress("MissingKDocForPublicAPI")

package com.example

public actual class MyClass internal actual constructor(
    internal actual val delegate: MyClassImpl,
) : MyClassAPI by delegate {
    public actual constructor(
        name: String,
        myRepo: MyRepo,
    ) : this(
        delegate = MyClassImpl(name, myRepo)
    )
    
    /**
     * Gets environment variable value by [key]
     */
    public fun getEnv(key: String): String = System.getenv(key)
}

Seventh, if MyClass had any tests in the original commonTest source set, use MyClassImpl in the test to verify common implementation. Do not rename the test, it should still be called e.g. MyClassTest. If you need to test some platform-specific functionality, create tests in jvmCommonTest and/or nonJvmCommonTest source sets. Kotlin tests for JVM-specific functionality should go to jvmCommonTest. IMPORTANT: if the test suite is written in Java, it MUST go to jvmTest, not jvmCommonTest. KMP only compiles Java code in jvmMain/jvmTest source sets.

Finally, ensure that the implementation compiles by running:

./gradlew :mymodule:compileKotlinJvm
./gradlew :mymodule:compileKotlinJs

Replace :mymodule with the actual Gradle module path derived from the file location (e.g., agents/agents-core → :agents:agents-core). If both pass, the split is working correctly.

IntelliJ false positives

Due to the experimental state of expect/actual classifiers, IntelliJ may report false positive errors such as "no actual for expect" or "no expect for actual". These diagnostics should NOT be trusted. The only reliable verification is running the Gradle compile tasks listed above.

Important notes

Imports

When creating the new files (API interface, Impl, expect class, actual classes), carry over all relevant imports from the original class.

Annotations

Classes being split should not have annotations. If the original class has annotations (e.g., @Serializable, @Deprecated), ask the user explicitly how to handle them before proceeding.

Companion objects

Classes being split should not have companion objects. If the original class has a companion object, ask the user explicitly how to handle it before proceeding.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.