Skip to content

Conversation

aSemy
Copy link
Contributor

@aSemy aSemy commented Sep 24, 2022

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:

@aSemy aSemy mentioned this pull request Sep 24, 2022
Comment on lines 26 to 28
if (kkSettings.applyKspPlugin.getOrElse(false)) {
target.pluginManager.apply("com.google.devtools.ksp")
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this doesn't seem to apply KSP automatically - I'm not sure why. I'll investigate.

Comment on lines 47 to 51
target.configurations.matching { it.name == KspGradleSubplugin.KSP_MAIN_CONFIGURATION_NAME }.configureEach {
defaultDependencies {
add(target.dependencies.create("com.github.kopykat-kt.kopykat:ksp:1.0-rc1"))
}
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

defining a dependency like this doesn't seem to work. It might need to be a mandatory dependency. I'll investigate.

Comment on lines 53 to 57
target.extensions.configure<KspExtension> {
arg("mutableCopy", "${kkSettings.mutableCopy.getOrElse(false)}")
arg("copyMap", "${kkSettings.copyMap.getOrElse(false)}")
arg("hierarchyCopy", "${kkSettings.hierarchyCopy.getOrElse(false)}")
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these don't seem to work. If I set copyMap.set(false) in Gradle, I can still use person.copyMap {}. I'm not sure if this is a Gradle or KSP thing. I'll investigate.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that if kkSettings sets mutableCopy (or any other) to null, then the corresponding argument in KSP should not be set. And in any case, it should be set to true if nothing is provided.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point - I've changed it to only set the KSP arg if the value is not-null.

@serras
Copy link
Collaborator

serras commented Sep 24, 2022

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
Copy link
Contributor Author

aSemy commented Sep 24, 2022

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
Copy link
Collaborator

serras commented Sep 24, 2022

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


gradlePlugin {
val kopyKatGradlePlugin by plugins.creating {
id = "at.kopykat"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gh

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

Create Gradle plugin
3 participants