{"id":18823573,"url":"https://github.com/05nelsonm/gradle-kmp-configuration-plugin","last_synced_at":"2025-06-27T22:32:49.450Z","repository":{"id":103798531,"uuid":"598538224","full_name":"05nelsonm/gradle-kmp-configuration-plugin","owner":"05nelsonm","description":"A Gradle Plugin for setting up Kotlin Multiplatform projects","archived":false,"fork":false,"pushed_at":"2025-05-20T00:51:58.000Z","size":255,"stargazers_count":10,"open_issues_count":3,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-05-20T01:31:44.871Z","etag":null,"topics":["gradle","gradle-plugin","gradle-plugin-kotlin","kotlin","kotlin-multiplatform","kotlin-multiplatform-mobile","kotlinmultiplatform"],"latest_commit_sha":null,"homepage":"","language":"Kotlin","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/05nelsonm.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2023-02-07T10:14:36.000Z","updated_at":"2025-05-20T00:51:57.000Z","dependencies_parsed_at":"2024-06-15T10:28:01.879Z","dependency_job_id":"839f22b1-cc79-4598-93c0-e95e2838df66","html_url":"https://github.com/05nelsonm/gradle-kmp-configuration-plugin","commit_stats":null,"previous_names":[],"tags_count":19,"template":false,"template_full_name":null,"purl":"pkg:github/05nelsonm/gradle-kmp-configuration-plugin","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/05nelsonm%2Fgradle-kmp-configuration-plugin","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/05nelsonm%2Fgradle-kmp-configuration-plugin/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/05nelsonm%2Fgradle-kmp-configuration-plugin/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/05nelsonm%2Fgradle-kmp-configuration-plugin/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/05nelsonm","download_url":"https://codeload.github.com/05nelsonm/gradle-kmp-configuration-plugin/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/05nelsonm%2Fgradle-kmp-configuration-plugin/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262343827,"owners_count":23296400,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["gradle","gradle-plugin","gradle-plugin-kotlin","kotlin","kotlin-multiplatform","kotlin-multiplatform-mobile","kotlinmultiplatform"],"created_at":"2024-11-08T00:54:03.574Z","updated_at":"2025-06-27T22:32:49.424Z","avatar_url":"https://github.com/05nelsonm.png","language":"Kotlin","funding_links":[],"categories":[],"sub_categories":[],"readme":"# gradle-kmp-configuration-plugin\nA Gradle Plugin for setting up Kotlin Multiplatform projects.\n\n1. Automatically configures hierarchical source sets.\n2. Enables passing of build targets via command line to control what gets \n   configured (great for CI).\n\n## Hierarchical Source Set Structure\n\nWill automatically configure project with a hierarchical source set structure\n\n```\n common\n   |-- jvmAndroid\n   |     |-- jvm\n   |     '-- android\n   '-- nonJvm\n         |-- js\n         |-- wasm\n         |-- wasmJs\n         |-- wasmWasi\n         '-- native\n               |-- unix\n               |     |-- androidNative\n               |     |     |-- androidNativeArm32\n               |     |     |-- androidNativeArm64\n               |     |     |-- androidNativeX64\n               |     |     '-- androidNativeX86\n               |     |-- darwin\n               |     |     |-- ios\n               |     |     |     |-- iosArm32\n               |     |     |     |-- iosArm64\n               |     |     |     |-- iosX64\n               |     |     |     '-- iosSimulatorArm64\n               |     |     |-- macos\n               |     |     |     |-- macosArm64\n               |     |     |     '-- macosX64\n               |     |     |-- tvos\n               |     |     |     |-- tvosArm64\n               |     |     |     |-- tvosX64\n               |     |     |     '-- tvosSimulatorArm64\n               |     |     '-- watchos\n               |     |           |-- watchosArm32\n               |     |           |-- watchosArm64\n               |     |           |-- watchosDeviceArm64\n               |     |           |-- watchosX64\n               |     |           |-- watchosX86\n               |     |           '-- watchosSimulatorArm64\n               |     '-- linux\n               |           |-- linuxArm32Hfp\n               |           |-- linuxArm64\n               |           |-- linuxMips32\n               |           |-- linuxMipsel32\n               |           '-- linuxX64\n               |-- mingw\n               |     |-- mingwX64\n               |     '-- mingwX86\n               '-- wasmNative\n                     '-- wasm32\n```\n\n## Target Properties\n\nYou can control what targets are enabled via passing of properties at build time.\n\nOnly enable the `linuxX64` target when building\n```bash\n./gradlew :samples:native:runDebugExecutableLinuxX64 -PKMP_TARGETS=LINUX_X64\n```\n\nOnly configure the `jvm` target when building\n```bash\n./gradlew :samples:javafx:run -PKMP_TARGETS=JVM\n```\n\nOverride any `KMP_TARGETS` property that may be configured (note the usage of `-D` instead of `-P`)\n```bash\n./gradlew build -DKMP_TARGETS_ALL\n```\n\nThis helps with fine-tuning CI builds. For example, if you want to run tests for `Java 11, 16, 17, 18`, \nyou can configure things to build all targets for `Java 11`, then pass only `-PKMP_TARGETS=JVM` \nfor the `Java 16, 17, 18` builds such that you are not wasting resources by compiling, say, all the \ndarwin targets (iOS, macOS, tvOS, watchOS).\n\nList of all `KMP_TARGETS`\n```\nANDROID,ANDROID_ARM32,ANDROID_ARM64,ANDROID_X64,ANDROID_X86\nJVM\nJS\nLINUX_ARM64,LINUX_X64\nMINGW_X64\nIOS_ARM64,IOS_SIMULATOR_ARM64,IOS_X64\nMACOS_ARM64,MACOS_X64\nTVOS_ARM64,TVOS_SIMULATOR_ARM64,TVOS_X64\nWATCHOS_ARM32,WATCHOS_ARM64,WATCHOS_DEVICE_ARM64,WATCHOS_SIMULATOR_ARM64,WATCHOS_X64\nWASM_JS,WASM_WASI,WASM\n\n// DEPRECATED as of 0.1.5 (based on Kotlin 1.9.20)\nLINUX_ARM32HFP,LINUX_MIPS32,LINUX_MIPSEL32\nMINGW_X86\nIOS_ARM32\nWATCHOS_X86\nWASM_32\n```\n\nExample usage (comma separated list)\n```bash\n./gradlew build -PKMP_TARGETS=\"JVM,JS,ANDROID,MACOS_ARM64,MACOS_X64,WASM_JS,WASM_WASI\"\n```\n\nThis is useful in projects that contain multiple modules which support different targets.\n\n - Module A: `jvm`, `js`\n - Module B: `js`\n - Module C: `jvm`\n\nModule B depends on A  \nModule C depends on A  \n\nPassing `-PKMP_TARGETS=JVM` when building means no targets are enabled for Module B. In \nthis event, the Kotlin Multiplatform plugin will not be applied and nothing will be \nconfigured (i.e. the build will not fail due to kotlin multiplatform plugin requiring \nat least 1 target being enabled).\n\n## Extension Usage\n\nFor composite builds, you can reference the following examples:\n - [PR #19][pr-19]\n - The [encoding][url-encoding] project\n\n```kotlin\nkmpConfiguration {\n    configure {\n        jvm {\n            target {\n                \n            }\n            sourceSetMain {\n                dependencies {\n                    // Jvm only dependencies\n                }\n            }\n            sourceSetTest {\n                // ...\n            }\n\n            // Will automatically set\n            // KotlinJvmCompilation.kotlinOptions.jvmTarget\n            kotlinJvmTarget = JavaVersion.VERSION_1_8\n            \n            // If you aren't using android and have elected for `withJava()` \n            // in the `target` block above setting this will automatically\n            // configure for you:\n            //\n            // JavaPluginExtension.sourceCompatibility\n            // JavaPluginExtension.targetCompatibility\n            compileSourceCompatibility = JavaVersion.VERSION_1_8\n            compileTargetCompatibility = JavaVersion.VERSION_1_8\n        }\n\n        // Android.\n        // Note that only 1 android example below will be utilized b/c\n        // you can only have 1 android target in a multiplatform module.\n\n        // The `com.android.application` plugin will be applied automatically \n        // if this target is enabled.\n        androidApp {\n            // Plugins to be applied if this target is being configured. In other\n            // words, these plugins will not be applied in the event KMP_TARGETS\n            // is passed via command line and does not contain ANDROID\n            //\n            // `pluginIds` are available for all targets for selectively applying\n            // them based on needs\n            pluginIds(\"org.jetbrains.kotlin.kapt\", \"androidx.navigation.safeargs\")\n\n            target {\n                // ..\n            }\n            android {\n                // configure BaseAppModuleExtension\n            }\n\n            // See jvm lambda above for explanation, works the same\n            kotlinJvmTarget = JavaVersion.VERSION_1_8\n            compileSourceCompatibility = JavaVersion.VERSION_1_8\n            compileTargetCompatibility = JavaVersion.VERSION_1_8\n        }\n\n        // Will automatically apply the `com.android.library` plugin\n        // if this target is enabled.\n        androidLibrary {\n            target {\n                publishLibraryVariant(\"release\")\n            }\n            android {\n                // configure LibraryExtension\n            }\n            \n            // Additional sourceSet lambda for androidLibrary and androidApp\n            sourceSetTestInstrumented {\n                // ...\n            }\n        }\n\n        // The `*All` shortcuts enable all targets for that platform type.\n        //\n        // NOTE: If more targets become available in future Kotlin\n        // releases, this will automatically add them. If that behavior\n        // is undesired, consider not utilizing the `*All` shortcuts.\n        iosAll()\n        macosAll()\n        tvosAll()\n        watchosAll()\n\n        options {\n            // Will create additional source sets for `iOS`, `tvOS`, and\n            // `watchOS` simulator targets to inherit from\n            //\n            // e.g. iosSimulator{Main/Test}\n            useSimulatorSourceSets = true\n            \n            // Will create additional source sets for `iOS`, `tvOS`, and\n            // `watchOS` NON-simulator targets to inherit from\n            //\n            // e.g. iosNonSimulator{Main/Test}\n            useNonSimulatorSourceSets = true\n        }\n\n        androidNativeAll()\n        linuxAll()\n\n        // All androidNative targets are enabled from above, but say you only\n        // need to configure the X64 variant. This will return the same lazy\n        // container that was created in `androidNativeAll` above so you can\n        // do that.\n        androidNativeX64 {\n            target {\n                // ...\n            }\n        }\n        \n        // Add another with a non-default name\n        androidNativeX64(\"androidNativeX64Awesome\") {\n            // ...\n        }\n\n        js()\n        wasmJs {\n            // ...\n        }\n        wasmWasi {\n            // ..\n        }\n        \n        // The `common` block is for configuring common source sets.\n        // This will only be invoked if there is at least 1 target\n        // being configured.\n        common {\n            pluginIds(\"kotlinx-atomicfu\")\n\n            sourceSetMain {\n                dependencies {\n                    // ...\n                }\n            }\n            sourceSetTest {\n                dependencies {\n                    implementation(kotlin(\"test\"))\n                }\n            }\n        }\n\n        // This will only be invoked if there is at least 1 target\n        // being configured.\n        kotlin {\n            // Additional configuration via the KotlinMultiplatformExtension\n            \n            with(sourcSets) {\n                // Want to use `findByName` in the event KMP_TARGETS is\n                // set and does not include ANDROID or JVM, which means\n                // the `jvmAndroid` intermediate source set will not be\n                // created.\n                val jvmAndroidMain: KotlinSourceSet? = findByName(\"jvmAndroidMain\")?.apply {\n\n                }\n\n                // More intermediate source sets, as depicted above in\n                // section `Hierarchical Source Set Structure`\n                val nativeMain: KotlinSourceSet? = findByName(\"nativeMain\")?.apply {\n\n                }\n                val darwinMain: KotlinSourceSet? = findByName(\"darwinMain\")?.apply {\n\n                }\n                val iosMain: KotlinSourceSet? = findByName(\"iosMain\")?.apply {\n\n                }\n\n                // setup additional source set configurations\n                val linuxMain = findByName(\"linuxMain\")\n                val androidNativeMain = findByName(\"androidNativeMain\")\n\n                if (linuxMain != null || androidNativeMain != null) {\n                    val linuxAndroidMain = maybeCreate(\"linuxAndroidMain\").apply {\n                        // `linux` and `androidNative` intermediate source sets\n                        // inherit from unix, so it will always be available\n                        // if either of them are configured. So, we can use\n                        // `getByName` safely.\n                        dependsOn(getByName(\"unixMain\"))\n                    }\n                    val linuxAndroidTest = maybeCreate(\"linuxAndroidTest\").apply {\n                        dependsOn(getByName(\"unixTest\"))\n                    }\n\n                    linuxMain?.apply { dependsOn(linuxAndroidMain) }\n                    findByName(\"linuxTest\")?.apply { dependsOn(linuxAndroidTest) }\n\n                    androidNativeMain?.apply { dependsOn(linuxAndroidMain) }\n                    findByName(\"androidNativeTest\")?.apply { dependsOn(linuxAndroidTest) }\n                }\n            }\n        }\n    }\n}\n```\n\n## Gradle\n\n**Using the `plugins` block**\n\u003cdetails open\u003e\n    \u003csummary\u003eKotlin\u003c/summary\u003e\n\n\u003c!-- TAG_VERSION --\u003e\n\n```kotlin\nplugins {\n    // If you are using androidApp (as depicted in the above example)\n    id(\"com.android.application\") version(\"x.x.x\") apply(false)\n\n    // If you are using androidLibrary (as depicted in the above example)\n    id(\"com.android.library\") version(\"x.x.x\") apply(false)\n\n    id(\"org.jetbrains.kotlin.multiplatform\") version(\"x.x.x\") apply(false)\n    id(\"io.matthewnelson.kmp.configuration\") version(\"0.4.1\")\n}\n```\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n    \u003csummary\u003eGroovy\u003c/summary\u003e\n\n\u003c!-- TAG_VERSION --\u003e\n\n```groovy\nplugins {\n    // If you are using androidApp (as depicted in the above example)\n    id 'com.android.application' version 'x.x.x' apply false\n\n    // If you are using androidLibrary (as depicted in the above example)\n    id 'com.android.library' version 'x.x.x' apply false\n\n    id 'org.jetbrains.kotlin.multiplatform' version 'x.x.x' apply false\n    id 'io.matthewnelson.kmp.configuration' version '0.4.1'\n}\n```\n\n\u003c/details\u003e\n\n**Using the `apply plugin` (the old way)**\n\u003cdetails open\u003e\n    \u003csummary\u003eKotlin\u003c/summary\u003e\n\n\u003c!-- TAG_VERSION --\u003e\n\ntop-level build file:\n```kotlin\nbuildscript {\n    repositories {\n        mavenCentral()\n    }\n    \n    dependencies {\n        // kotlin gradle\n        // android gradle (if you have an android target)\n        classpath(\"io.matthewnelson:gradle-kmp-configuration-plugin:0.4.1\")\n    }\n}\n```\n\nproject module:\n```kotlin\nplugins {\n    id(\"io.matthewnelson.kmp.configuration\")\n}\n\nkmpConfiguration {\n    configure {\n        // ...\n    }\n}\n```\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n    \u003csummary\u003eGroovy\u003c/summary\u003e\n\n\u003c!-- TAG_VERSION --\u003e\n\ntop-level build file:\n```groovy\nbuildscript {\n    repositories {\n        mavenCentral()\n    }\n    dependencies {\n        classpath 'io.matthewnelson:gradle-kmp-configuration-plugin:0.4.1'\n    }\n}\n```\n\nproject module:\n```groovy\nplugins {\n    id 'io.matthewnelson.kmp.configuration'\n}\n\nkmpConfiguration {\n    configure {\n        // ...\n    }\n}\n```\n\n\u003c/details\u003e\n\n[pr-19]: https://github.com/05nelsonm/gradle-kmp-configuration-plugin/pull/19\n[url-encoding]: https://github.com/05nelsonm/encoding\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F05nelsonm%2Fgradle-kmp-configuration-plugin","html_url":"https://awesome.ecosyste.ms/projects/github.com%2F05nelsonm%2Fgradle-kmp-configuration-plugin","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F05nelsonm%2Fgradle-kmp-configuration-plugin/lists"}