kopykat-kt / kopykat

Little utilities for more pleasant immutable data in Kotlin
Other
283 stars 16 forks source link

KopyKat Gradle plugin #40

Open aSemy opened 2 years ago

aSemy commented 2 years ago

Here's an initial attempt. It's still a little rough, but it's ready for a first look.

fixes #29

It requires some setup:

  1. use a JitPack workaround to allow for JitPack to host Gradle Plugins
    // $projectRootDir/settings.gradle.kts
    pluginManagement {
       repositories {
           gradlePluginPortal()
           maven("https://jitpack.io")
       }
       resolutionStrategy {
           eachPlugin {
               if (requested.id.id == "at.kopykat") {
                   // TODO change to kopykat repo
                   useModule("com.github.aSemy.kopykat:kopykat-gradle-plugin:${requested.version}")
               }
           }
       }
    }
  2. import the plugin

    // build.gradle.kts
    
    plugins {
      id("at.kopykat") version "feat~gradle_plugin-SNAPSHOT"
      id("com.google.devtools.ksp") version "1.7.10-1.0.6" // TODO why isn't KSP plugin applied automatically by kopykat plugin?
    }
    
    kopykat {
     copyMap.set(true)
    }
    
    dependencies {
       ksp("com.github.kopykat-kt.kopykat:ksp:1.0-rc1") // TODO kopykat should add this automatically
    }

Notes:

serras commented 2 years ago

I think we should be careful with this, and ensure that it doesn’t get harder than the current instructions. My experience with this is that a custom plug-in sometimes fail on Android or MPP, for which KSP has special instructions.

aSemy commented 2 years ago

Yeah, the plugin instructions would be easier if the KopyKat plugin can be published to Maven Central or the Gradle Plugin Portal. JitPack manually overrides the project's group, which in turn breaks the Gradle plugin marker. If published on Maven Central, the resolutionStrategy {} workaround isn't needed.

The plugin in this PR shouldn't cause problems with Kotlin Multiplatform, but users might have to manually enable KSP per source set. There's ways to test for this though, either manually with example projects, or with Gradle TestKit. I can include them in this PR, if you'd like? But I think that would make it too large.

Can you find the special instructions for Android? I could only find them for Kotlin Multiplatform.

serras commented 2 years ago

I'm working on publishing to Maven Central (#41), which should make things easier