Repository: cortinico/ktfmt-gradle (kotlin)

Issue:
Cannot add task 'ktfmtCheckAndroidTest' as a task with that name already exists.
## 🐛 Describe the bug
unable to run the formatter with android multiplatform

## ⚠️ Current behavior
```
$ ./gradlew ktfmtFormat

FAILURE: Build failed with an exception.

* Where:
Build file '/Users/ohadshai/IdeaProjects/kotlin-logging/build.gradle.kts' line: 63

* What went wrong:
Cannot add task 'ktfmtCheckAndroidTest' as a task with that name already exists.
```

## ✅ Expected behavior

To format code.

## 💣 Steps to reproduce

Checkout code from https://github.com/oshai/kotlin-logging/pull/271/commits/148291d5f45a857a37c3dddef825a1c62fdc8f82

Run `./gradlew ktfmtFormat`


## 📱 Tech info
 - Device: mac
 - Library/App version: 0.11
 - Java 17.

Pull request description:
## 🚀 Description
I'm updating KMP tasks to be prefixed with `kmp` like `ktfmtFormatKmpCommonMain`.

## 📄 Motivation and Context
This will solve #121 and will help to decouple Android tasks from KMP tasks.
Fixes #121 
Closes #128

## 🧪 How Has This Been Tested?
Tests are attached.

## 📦 Types of changes
- [x] Bug fix (non-breaking change which fixes an issue)
- [x] Breaking change (fix or feature that would cause existing functionality to not work as expected)

Patch:
diff --git a/.idea/misc.xml b/.idea/misc.xml
index 998c28f9..7d0d9538 100644
--- a/.idea/misc.xml
+++ b/.idea/misc.xml
@@ -5,9 +5,4 @@
     <file type="web" url="file://$PROJECT_DIR$" />
   </component>
   <component name="ProjectRootManager" version="2" languageLevel="JDK_11" default="true" project-jdk-name="openjdk-16" project-jdk-type="JavaSDK" />
-  <component name="SwUserDefinedSpecifications">
-    <option name="specTypeByUrl">
-      <map />
-    </option>
-  </component>
 </project>
\ No newline at end of file
diff --git a/plugin-build/plugin/src/main/java/com/ncorti/ktfmt/gradle/KtfmtPlugin.kt b/plugin-build/plugin/src/main/java/com/ncorti/ktfmt/gradle/KtfmtPlugin.kt
index e683ab9a..d88b6ef1 100644
--- a/plugin-build/plugin/src/main/java/com/ncorti/ktfmt/gradle/KtfmtPlugin.kt
+++ b/plugin-build/plugin/src/main/java/com/ncorti/ktfmt/gradle/KtfmtPlugin.kt
@@ -57,9 +57,10 @@ abstract class KtfmtPlugin : Plugin<Project> {
     private fun applyKtfmtToMultiplatformProject(project: Project) {
         val extension = project.extensions.getByType(KotlinMultiplatformExtension::class.java)
         extension.sourceSets.all {
+            val name = "kmp ${it.name}"
             createTasksForSourceSet(
                 project,
-                it.name,
+                name,
                 it.kotlin.sourceDirectories,
                 ktfmtExtension,
                 topLevelFormat,


Test patch:
diff --git a/plugin-build/plugin/src/test/java/com/ncorti/ktfmt/gradle/KtfmtPluginTest.kt b/plugin-build/plugin/src/test/java/com/ncorti/ktfmt/gradle/KtfmtPluginTest.kt
index 8311fb70..b198a710 100644
--- a/plugin-build/plugin/src/test/java/com/ncorti/ktfmt/gradle/KtfmtPluginTest.kt
+++ b/plugin-build/plugin/src/test/java/com/ncorti/ktfmt/gradle/KtfmtPluginTest.kt
@@ -61,19 +61,19 @@ class KtfmtPluginTest {
         project.pluginManager.apply("org.jetbrains.kotlin.multiplatform")
         project.pluginManager.apply("com.ncorti.ktfmt.gradle")
 
-        assertThat(project.tasks.getByName("ktfmtCheckCommonMain"))
+        assertThat(project.tasks.getByName("ktfmtCheckKmpCommonMain"))
             .isInstanceOf(KtfmtCheckTask::class.java)
-        assertThat(project.tasks.getByName("ktfmtFormatCommonMain"))
+        assertThat(project.tasks.getByName("ktfmtFormatKmpCommonMain"))
             .isInstanceOf(KtfmtFormatTask::class.java)
-        assertThat(project.tasks.getByName("ktfmtCheckCommonTest"))
+        assertThat(project.tasks.getByName("ktfmtCheckKmpCommonTest"))
             .isInstanceOf(KtfmtCheckTask::class.java)
-        assertThat(project.tasks.getByName("ktfmtFormatCommonTest"))
+        assertThat(project.tasks.getByName("ktfmtFormatKmpCommonTest"))
             .isInstanceOf(KtfmtFormatTask::class.java)
 
         assertThat(project["ktfmtCheck"].dependencies)
-            .containsExactly("ktfmtCheckCommonMain", "ktfmtCheckCommonTest")
+            .containsExactly("ktfmtCheckKmpCommonMain", "ktfmtCheckKmpCommonTest")
         assertThat(project["ktfmtFormat"].dependencies)
-            .containsExactly("ktfmtFormatCommonMain", "ktfmtFormatCommonTest")
+            .containsExactly("ktfmtFormatKmpCommonMain", "ktfmtFormatKmpCommonTest")
     }
 
     @Suppress("LongMethod")