ge-org / multiplatform-swiftpackage

Gradle plugin that generates a Swift Package Manager manifest and an XCFramework to distribute a Kotlin Multiplatform library for Apple platforms.
Apache License 2.0
336 stars 49 forks source link

Allow conditionally applying this plugin #6

Closed netroy closed 3 years ago

netroy commented 3 years ago

I'd like to do something like this

import com.chromaticnoise.multiplatformswiftpackage.MultiplatformSwiftPackagePlugin

val isCI = System.getenv("CI") == "true"

plugins {
  kotlin("multiplatform") version "1.4.20"
  id("com.chromaticnoise.multiplatform-swiftpackage") version "2.0.0" apply false
}

kotlin {
  jvm()
  ios()
}

if (isCI) {
  apply(plugin = "com.chromaticnoise.multiplatform-swiftpackage")
  configure<MultiplatformSwiftPackagePlugin> {
    multiplatformSwiftPackage {
      packageName("MyFramework")
      swiftToolsVersion("5.3")
      targetPlatforms {
        iOS { v("13.0") }
      }
    }
  }
}

But , since MultiplatformSwiftPackagePlugin is marked a internal, I'm unable to do this. Because of this anyone working on the jvm part of our library has to chose between removing this plugin, or setting up xcode.

If it's okay, I can send a pull-request to make the plugin class public.

ge-org commented 3 years ago

Hi @netroy,

thanks for your feedback and explaining the use case. You're welcome to create a PR to add the public keyword to the class. Please send the PR to the next-release branch so I can include in the next version.

netroy commented 3 years ago

Hey @ge-org sorry for wasting your time earlier. looks like I had to use SwiftPackageExtension (which was already public) for the configure block & not MultiplatformSwiftPackagePlugin.

This is what is working for me:

import com.chromaticnoise.multiplatformswiftpackage.SwiftPackageExtension

val isCI = System.getenv("CI") == "true"

plugins {
  kotlin("multiplatform") version "1.4.20"
  id("com.chromaticnoise.multiplatform-swiftpackage") version "2.0.1" apply false
}

kotlin {
  jvm()
  if (isCI) {
    ios()
  }
}

if (isCI) {
  apply(plugin = "com.chromaticnoise.multiplatform-swiftpackage")
  configure<SwiftPackageExtension> {
    packageName("MyFramework")
    swiftToolsVersion("5.3")
    targetPlatforms {
      iOS { v("13.0") }
    }
  }
}

still, thanks a lot for helping out. cheers

ge-org commented 3 years ago

Hey @netroy, never mind. Doesn't hurt if this class is public as well 🤷‍♀️

This is still a young project and I'm happy to learn about any use case. I'll definitely keep this one in mind when making further changes in the future.