├── .github └── FUNDING.yml ├── .gitignore ├── LICENSE ├── README.md ├── api └── kmp-fatframework-cocoa.api ├── build.gradle.kts ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── settings.gradle.kts └── src ├── main ├── kotlin │ └── com │ │ └── prof18 │ │ └── kmp │ │ └── fatframework │ │ └── cocoa │ │ ├── CocoaPodRepoDSL.kt │ │ ├── KMPFatFrameworkCocoaExtension.kt │ │ ├── KMPFatFrameworkCocoaPlugin.kt │ │ ├── data │ │ ├── CocoaPodRepoInfo.kt │ │ ├── PluginConfig.kt │ │ └── PluginConfigErrorMessages.kt │ │ ├── task │ │ ├── GenerateCocoaPodRepositoryTask.kt │ │ ├── common │ │ │ ├── PublishDebugUtils.kt │ │ │ ├── PublishPreparationTasks.kt │ │ │ └── PublishReleaseUtils.kt │ │ ├── fatframework │ │ │ ├── BuildDebugFatFrameworkTask.kt │ │ │ ├── BuildReleaseFatFrameworkTask.kt │ │ │ ├── PublishDebugFatFramework.kt │ │ │ └── PublishReleaseFatFramework.kt │ │ └── xcframework │ │ │ ├── BuildDebugXCFrameworkTask.kt │ │ │ ├── BuildReleaseXCFrameworkTask.kt │ │ │ ├── PublishDebugXCFramework.kt │ │ │ ├── PublishReleaseXCFramework.kt │ │ │ └── common │ │ │ └── BuildXCFramework.kt │ │ └── utils │ │ └── Utils.kt └── resources │ ├── META-INF │ └── gradle-plugins │ │ └── com.prof18.kmp.fatframework.cocoa.properties │ └── template │ └── Framework.podspec.template └── test ├── kotlin └── com │ └── prof18 │ └── kmp │ └── fatframework │ └── cocoa │ ├── task │ ├── FatFrameworkTasksWithoutFieldsTest.kt │ └── GenerateCocoaPodTaskWithoutFieldsTest.kt │ └── testutils │ └── TestUtils.kt └── resources └── test-project ├── settings.gradle └── src └── commonMain └── kotlin └── com └── prof18 └── example └── Greeting.kt /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | # These are supported funding model platforms 2 | 3 | custom: https://www.paypal.me/MarcoGomiero 4 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/caches 5 | /.idea/libraries 6 | /.idea/modules.xml 7 | /.idea/workspace.xml 8 | /.idea/navEditor.xml 9 | /.idea/assetWizardSettings.xml 10 | .DS_Store 11 | /build 12 | 13 | .idea/ -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright 2021 Marco Gomiero 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | This plugin has been archived in favour of [KMP Framework Bundler](https://github.com/prof18/kmp-framework-bundler). You can find a migration guide [here](https://github.com/prof18/kmp-framework-bundler#migration-from-kmp-fatframework-cocoa) 2 | 3 | # KMP FatFramework Cocoa 4 | 5 | [![Maven Central](https://maven-badges.herokuapp.com/maven-central/com.prof18.kmp.fatframework.cocoa/com.prof18.kmp.fatframework.cocoa.gradle.plugin/badge.svg)](https://search.maven.org/artifact/com.prof18.kmp.fatframework.cocoa/com.prof18.kmp.fatframework.cocoa.gradle.plugin/) 6 | [![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0) 7 | 8 | **KMP FatFramework Cocoa** is a Gradle plugin for Kotlin Multiplatform projects that generates a **FatFramework** for iOS targets, or a **XCFramework** 9 | for Apple targets and manages the publishing process in a CocoaPod Repository. 10 | 11 | ## Installation 12 | 13 | The library is uploaded on MavenCentral, so you can easily add the dependency on the `plugins` block: 14 | 15 | ```kotlin 16 | plugins { 17 | id("com.prof18.kmp.fatframework.cocoa") version "" 18 | } 19 | ``` 20 | 21 | ## Usage 22 | 23 | The plugin adds five Gradle tasks to your project. 24 | 25 | - `buildDebugIosFatFramework` that creates a **FatFramework** with the `Debug` target. 26 | 27 | 28 | - `buildDebugXCFramework` that creates a **XCFramework** with the `Debug` target. 29 | 30 | 31 | - `buildReleaseIosFatFramework` that creates a **FatFramework** with the `Release` target. 32 | 33 | 34 | - `buildReleaseXCFramework` that creates a **XCFramework** with the `Release` target. 35 | 36 | 37 | - `generateCocoaPodRepo` that generates a CocoaPod repository ready to host the Framework. 38 | 39 | 40 | - `publishDebugIosFatFramework` that publishes the `Debug` version of the **FatFramework** in the CocoaPod repository. 41 | 42 | 43 | - `publishDebugXCFramework` that publishes the `Debug` version of the **XCFramework** in the CocoaPod repository. 44 |

45 | The "publishDebug" task (for both the type of frameworks) takes care of everything: 46 | - changing the working branch from main/master to develop; 47 | - building the debug framework; 48 | - updating the version name inside the Podspec file; 49 | - committing the changes; 50 | - and publishing to remote. 51 | 52 | In this way, in the iOS project, you can use the latest changes published on the develop branch: 53 | 54 | ```ruby 55 | pod '', :git => "git@github.com:/.git", :branch => 'develop' 56 | ``` 57 | To run this task, the output path provided in the [configuration](#configuration) must be a git repository. 58 | 59 | 60 | - `publishReleaseIosFatFramework` that publishes the `Release` version of the **FatFramework** in the CocoaPod repository. 61 | 62 | 63 | - `publishReleaseXCFramework` that publishes the `Release` version of the **XCFramework** in the CocoaPod repository. 64 |

65 | The "publishRelease" task (for both the type of frameworks) takes care of everything: 66 | - changing the working branch from develop to main/master; 67 | - building the release framework; 68 | - updating the version name inside the Podspec file; 69 | - committing the changes; 70 | - tagging the commit; 71 | - and publishing to remote. 72 | 73 | In this way, in the iOS project, you have to specify a version: 74 | 75 | ```ruby 76 | pod '', :git => "git@github.com:/.git", :tag => '' 77 | ``` 78 | 79 | To run this task, the output path provided in the [configuration](#configuration) must be a git repository. 80 | 81 | ## Configuration 82 | 83 | You can configure the plugin with the `fatFrameworkCocoaConfig` block in your `build.gradle[.kts]`. 84 | 85 | The mandatory fields are three: 86 | 87 | - the name of the FatFramework 88 | - the output path 89 | - the version name 90 | - For XCFramework support, you need to set the `useXCFramework` flag. When the flag is set, only the XCFramework task can be called. 91 | 92 | ```kotlin 93 | fatFrameworkCocoaConfig { 94 | frameworkName = "LibraryName" 95 | outputPath = "$rootDir/../test-dest" 96 | versionName = "1.0" 97 | useXCFramework = true 98 | } 99 | ``` 100 | 101 | When using a FatFramework, only iOS targets can be packed together. With XCFramework you can pack together all the Apple families: iOS, macOS, etc. 102 | 103 | If you want to run the `generateCocoaPodRepo` task to generate a CocoaPod repository, you have to 104 | provide the mandatory fields mentioned above and some other parameters in the `cocoaPodRepoInfo` block: 105 | 106 | - a summary of the library 107 | - the homepage of the library 108 | - the license of the library 109 | - the authors of the library 110 | - the url of the git repository that hosts the CocoaPod repo. 111 | 112 | ```kotlin 113 | fatFrameworkCocoaConfig { 114 | frameworkName = "LibraryName" 115 | outputPath = "$rootDir/../test-dest" 116 | versionName = "1.0" 117 | 118 | cocoaPodRepoInfo { 119 | summary = "This is a test KMP framework" 120 | homepage = "https://github.com/prof18/ccoca-repo-test" 121 | license = "Apache" 122 | authors = "\"Marco Gomiero\" => \"mg@mail.it\"" 123 | gitUrl = "git@github.com:prof18/ccoca-repo-test.git" 124 | } 125 | } 126 | ``` 127 | 128 | ## Changelog 129 | 130 | - The version `0.2.1` introduce some breaking changes to better support XCFrameworks. Give a look to the [0.2.1 release notes](https://github.com/prof18/kmp-fatframework-cocoa/releases/tag/0.2.1). 131 | 132 | ## Sample Project 133 | 134 | To see the plugin in action, I've published [a little sample project](https://github.com/prof18/kmp-fatframework-test-project). 135 | 136 | ## Further Readings 137 | 138 | This plugin is born from a set of unbundled Gradle tasks that I was copying between every Kotlin Multiplatform project. 139 | I've written about these 140 | tasks [in an article on my website](https://www.marcogomiero.com/posts/2021/kmp-existing-project/). 141 | 142 | For more info about CocoaPod repo, I suggest reading the following resources: 143 | 144 | - https://guides.cocoapods.org/making/private-cocoapods.html 145 | - https://guides.cocoapods.org/ 146 | 147 | ## License 148 | 149 | ``` 150 | Copyright 2021 Marco Gomiero 151 | 152 | Licensed under the Apache License, Version 2.0 (the "License"); 153 | you may not use this file except in compliance with the License. 154 | You may obtain a copy of the License at 155 | 156 | http://www.apache.org/licenses/LICENSE-2.0 157 | 158 | Unless required by applicable law or agreed to in writing, software 159 | distributed under the License is distributed on an "AS IS" BASIS, 160 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 161 | See the License for the specific language governing permissions and 162 | limitations under the License. 163 | ``` 164 | -------------------------------------------------------------------------------- /api/kmp-fatframework-cocoa.api: -------------------------------------------------------------------------------- 1 | public final class com/prof18/kmp/fatframework/cocoa/CocoaPodRepoDSL { 2 | public fun ()V 3 | public final fun getAuthors ()Ljava/lang/String; 4 | public final fun getGitUrl ()Ljava/lang/String; 5 | public final fun getHomepage ()Ljava/lang/String; 6 | public final fun getLicense ()Ljava/lang/String; 7 | public final fun getSummary ()Ljava/lang/String; 8 | public final fun setAuthors (Ljava/lang/String;)V 9 | public final fun setGitUrl (Ljava/lang/String;)V 10 | public final fun setHomepage (Ljava/lang/String;)V 11 | public final fun setLicense (Ljava/lang/String;)V 12 | public final fun setSummary (Ljava/lang/String;)V 13 | } 14 | 15 | public abstract class com/prof18/kmp/fatframework/cocoa/KMPFatFrameworkCocoaExtension { 16 | public fun (Lorg/gradle/api/Project;)V 17 | public final fun cocoaPodRepoInfo (Lgroovy/lang/Closure;)V 18 | public final fun cocoaPodRepoInfo (Lkotlin/jvm/functions/Function1;)V 19 | public final fun getFrameworkName ()Ljava/lang/String; 20 | public final fun getOutputPath ()Ljava/lang/String; 21 | public final fun getUseXCFramework ()Z 22 | public final fun getVersionName ()Ljava/lang/String; 23 | public final fun setFrameworkName (Ljava/lang/String;)V 24 | public final fun setOutputPath (Ljava/lang/String;)V 25 | public final fun setUseXCFramework (Z)V 26 | public final fun setVersionName (Ljava/lang/String;)V 27 | } 28 | 29 | public abstract class com/prof18/kmp/fatframework/cocoa/KMPFatFrameworkCocoaPlugin : org/gradle/api/Plugin { 30 | public fun ()V 31 | public synthetic fun apply (Ljava/lang/Object;)V 32 | public fun apply (Lorg/gradle/api/Project;)V 33 | } 34 | 35 | -------------------------------------------------------------------------------- /build.gradle.kts: -------------------------------------------------------------------------------- 1 | import java.util.* 2 | 3 | buildscript { 4 | repositories { 5 | mavenCentral() 6 | } 7 | dependencies { 8 | classpath("org.jetbrains.kotlinx:binary-compatibility-validator:0.4.0") 9 | } 10 | } 11 | 12 | apply(plugin = "binary-compatibility-validator") 13 | 14 | plugins { 15 | `kotlin-dsl` 16 | `java-gradle-plugin` 17 | `maven-publish` 18 | signing 19 | } 20 | 21 | val versionName = "0.2.1" 22 | val group = "com.prof18.kmp.fatframework.cocoa" 23 | 24 | version = versionName 25 | 26 | repositories { 27 | mavenCentral() 28 | } 29 | 30 | val fixtureClasspath by configurations.creating 31 | 32 | // Append any extra dependencies to the test fixtures via a custom configuration classpath. This 33 | // allows us to apply additional plugins in a fixture while still leveraging dependency resolution 34 | // and de-duplication semantics. 35 | tasks.pluginUnderTestMetadata { 36 | pluginClasspath.from(fixtureClasspath) 37 | } 38 | 39 | dependencies { 40 | compileOnly(gradleApi()) 41 | 42 | compileOnly("org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.20") 43 | compileOnly("org.jetbrains.kotlin:kotlin-compiler-embeddable:1.5.20") 44 | 45 | testImplementation("junit:junit:4.13.1") 46 | testImplementation("com.google.truth:truth:1.0.1") 47 | fixtureClasspath(kotlin("gradle-plugin")) 48 | } 49 | 50 | java { 51 | sourceCompatibility = JavaVersion.VERSION_1_8 52 | targetCompatibility = JavaVersion.VERSION_1_8 53 | 54 | withJavadocJar() 55 | withSourcesJar() 56 | } 57 | 58 | tasks.test { 59 | useJUnit() 60 | } 61 | 62 | gradlePlugin { 63 | plugins { 64 | create("fatframeworkCocoa") { 65 | id = group 66 | implementationClass = "com.prof18.kmp.fatframework.cocoa.KMPFatFrameworkCocoaPlugin" 67 | version = versionName 68 | } 69 | } 70 | } 71 | 72 | val local = Properties() 73 | val localProperties: File = rootProject.file("local.properties") 74 | if (localProperties.exists()) { 75 | localProperties.inputStream().use { local.load(it) } 76 | local.forEach { name, value -> 77 | ext { 78 | set(name as String, value) 79 | } 80 | } 81 | } else { 82 | ext { 83 | set("signing.keyId", System.getenv("SIGNING_KEY_ID")) 84 | set("signing.password", System.getenv("SIGNING_PASSWORD")) 85 | set("signing.secretKeyRingFile", System.getenv("SIGNING_SECRET_KEY_RING_FILE")) 86 | set("ossrhUsername", System.getenv("OSSRH_USERNAME")) 87 | set("ossrhPassword", System.getenv("OSSRH_PASSWORD")) 88 | } 89 | } 90 | 91 | publishing { 92 | publications { 93 | create("pluginMaven") { 94 | pom { 95 | groupId = group 96 | artifactId = "com.prof18.kmp.fatframework.cocoa.gradle.plugin" 97 | 98 | name.set("KMP FatFramework Cocoa") 99 | description.set("Gradle plugin to distribute a Kotlin Multiplatform iOS library in a FatFramework with CocoaPod") 100 | url.set("https://github.com/prof18/kmp-fatframework-cocoa") 101 | 102 | licenses { 103 | license { 104 | name.set("Apache License, Version 2.0") 105 | url.set("https://www.apache.org/licenses/LICENSE-2.0.txt") 106 | } 107 | } 108 | developers { 109 | developer { 110 | id.set("prof18") 111 | name.set("Marco Gomiero") 112 | } 113 | } 114 | scm { 115 | connection.set("scm:git:https://github.com/prof18/kmp-fatframework-cocoa") 116 | developerConnection.set("scm:git:ssh://git@github.com/prof18/kmp-fatframework-cocoa.git") 117 | url.set("https://github.com/prof18/kmp-fatframework-cocoa") 118 | } 119 | } 120 | } 121 | } 122 | 123 | repositories { 124 | maven { 125 | val releasesUrl = "https://oss.sonatype.org/service/local/staging/deploy/maven2/" 126 | val snapshotsUrl = "https://oss.sonatype.org/content/repositories/snapshots/" 127 | name = "sonatype" 128 | url = uri(if (version.toString().endsWith("SNAPSHOT")) snapshotsUrl else releasesUrl) 129 | credentials { 130 | username = local.getProperty("ossrhUsername") ?: System.getenv("OSSRH_USERNAME") 131 | password = local.getProperty("ossrhPassword") ?: System.getenv("OSSRH_PASSWORD") 132 | } 133 | } 134 | } 135 | } 136 | 137 | signing { 138 | sign(publishing.publications["pluginMaven"]) 139 | } 140 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | kotlin.code.style=official -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prof18/kmp-fatframework-cocoa/0fbd5dfcac4de2d317b982e9e190e915c654f308/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-6.8.1-bin.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | # 4 | # Copyright 2015 the original author or authors. 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # https://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | # 18 | 19 | ############################################################################## 20 | ## 21 | ## Gradle start up script for UN*X 22 | ## 23 | ############################################################################## 24 | 25 | # Attempt to set APP_HOME 26 | # Resolve links: $0 may be a link 27 | PRG="$0" 28 | # Need this for relative symlinks. 29 | while [ -h "$PRG" ] ; do 30 | ls=`ls -ld "$PRG"` 31 | link=`expr "$ls" : '.*-> \(.*\)$'` 32 | if expr "$link" : '/.*' > /dev/null; then 33 | PRG="$link" 34 | else 35 | PRG=`dirname "$PRG"`"/$link" 36 | fi 37 | done 38 | SAVED="`pwd`" 39 | cd "`dirname \"$PRG\"`/" >/dev/null 40 | APP_HOME="`pwd -P`" 41 | cd "$SAVED" >/dev/null 42 | 43 | APP_NAME="Gradle" 44 | APP_BASE_NAME=`basename "$0"` 45 | 46 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 47 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' 48 | 49 | # Use the maximum available, or set MAX_FD != -1 to use that value. 50 | MAX_FD="maximum" 51 | 52 | warn () { 53 | echo "$*" 54 | } 55 | 56 | die () { 57 | echo 58 | echo "$*" 59 | echo 60 | exit 1 61 | } 62 | 63 | # OS specific support (must be 'true' or 'false'). 64 | cygwin=false 65 | msys=false 66 | darwin=false 67 | nonstop=false 68 | case "`uname`" in 69 | CYGWIN* ) 70 | cygwin=true 71 | ;; 72 | Darwin* ) 73 | darwin=true 74 | ;; 75 | MINGW* ) 76 | msys=true 77 | ;; 78 | NONSTOP* ) 79 | nonstop=true 80 | ;; 81 | esac 82 | 83 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 84 | 85 | 86 | # Determine the Java command to use to start the JVM. 87 | if [ -n "$JAVA_HOME" ] ; then 88 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 89 | # IBM's JDK on AIX uses strange locations for the executables 90 | JAVACMD="$JAVA_HOME/jre/sh/java" 91 | else 92 | JAVACMD="$JAVA_HOME/bin/java" 93 | fi 94 | if [ ! -x "$JAVACMD" ] ; then 95 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 96 | 97 | Please set the JAVA_HOME variable in your environment to match the 98 | location of your Java installation." 99 | fi 100 | else 101 | JAVACMD="java" 102 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 103 | 104 | Please set the JAVA_HOME variable in your environment to match the 105 | location of your Java installation." 106 | fi 107 | 108 | # Increase the maximum file descriptors if we can. 109 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 110 | MAX_FD_LIMIT=`ulimit -H -n` 111 | if [ $? -eq 0 ] ; then 112 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 113 | MAX_FD="$MAX_FD_LIMIT" 114 | fi 115 | ulimit -n $MAX_FD 116 | if [ $? -ne 0 ] ; then 117 | warn "Could not set maximum file descriptor limit: $MAX_FD" 118 | fi 119 | else 120 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 121 | fi 122 | fi 123 | 124 | # For Darwin, add options to specify how the application appears in the dock 125 | if $darwin; then 126 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 127 | fi 128 | 129 | # For Cygwin or MSYS, switch paths to Windows format before running java 130 | if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then 131 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 132 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 133 | 134 | JAVACMD=`cygpath --unix "$JAVACMD"` 135 | 136 | # We build the pattern for arguments to be converted via cygpath 137 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 138 | SEP="" 139 | for dir in $ROOTDIRSRAW ; do 140 | ROOTDIRS="$ROOTDIRS$SEP$dir" 141 | SEP="|" 142 | done 143 | OURCYGPATTERN="(^($ROOTDIRS))" 144 | # Add a user-defined pattern to the cygpath arguments 145 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 146 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 147 | fi 148 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 149 | i=0 150 | for arg in "$@" ; do 151 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 152 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 153 | 154 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 155 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 156 | else 157 | eval `echo args$i`="\"$arg\"" 158 | fi 159 | i=`expr $i + 1` 160 | done 161 | case $i in 162 | 0) set -- ;; 163 | 1) set -- "$args0" ;; 164 | 2) set -- "$args0" "$args1" ;; 165 | 3) set -- "$args0" "$args1" "$args2" ;; 166 | 4) set -- "$args0" "$args1" "$args2" "$args3" ;; 167 | 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 168 | 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 169 | 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 170 | 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 171 | 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 172 | esac 173 | fi 174 | 175 | # Escape application args 176 | save () { 177 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 178 | echo " " 179 | } 180 | APP_ARGS=`save "$@"` 181 | 182 | # Collect all arguments for the java command, following the shell quoting and substitution rules 183 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 184 | 185 | exec "$JAVACMD" "$@" 186 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem https://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | 17 | @if "%DEBUG%" == "" @echo off 18 | @rem ########################################################################## 19 | @rem 20 | @rem Gradle startup script for Windows 21 | @rem 22 | @rem ########################################################################## 23 | 24 | @rem Set local scope for the variables with windows NT shell 25 | if "%OS%"=="Windows_NT" setlocal 26 | 27 | set DIRNAME=%~dp0 28 | if "%DIRNAME%" == "" set DIRNAME=. 29 | set APP_BASE_NAME=%~n0 30 | set APP_HOME=%DIRNAME% 31 | 32 | @rem Resolve any "." and ".." in APP_HOME to make it shorter. 33 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi 34 | 35 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 36 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 37 | 38 | @rem Find java.exe 39 | if defined JAVA_HOME goto findJavaFromJavaHome 40 | 41 | set JAVA_EXE=java.exe 42 | %JAVA_EXE% -version >NUL 2>&1 43 | if "%ERRORLEVEL%" == "0" goto execute 44 | 45 | echo. 46 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 47 | echo. 48 | echo Please set the JAVA_HOME variable in your environment to match the 49 | echo location of your Java installation. 50 | 51 | goto fail 52 | 53 | :findJavaFromJavaHome 54 | set JAVA_HOME=%JAVA_HOME:"=% 55 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 56 | 57 | if exist "%JAVA_EXE%" goto execute 58 | 59 | echo. 60 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 61 | echo. 62 | echo Please set the JAVA_HOME variable in your environment to match the 63 | echo location of your Java installation. 64 | 65 | goto fail 66 | 67 | :execute 68 | @rem Setup the command line 69 | 70 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 71 | 72 | 73 | @rem Execute Gradle 74 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* 75 | 76 | :end 77 | @rem End local scope for the variables with windows NT shell 78 | if "%ERRORLEVEL%"=="0" goto mainEnd 79 | 80 | :fail 81 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 82 | rem the _cmd.exe /c_ return code! 83 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 84 | exit /b 1 85 | 86 | :mainEnd 87 | if "%OS%"=="Windows_NT" endlocal 88 | 89 | :omega 90 | -------------------------------------------------------------------------------- /settings.gradle.kts: -------------------------------------------------------------------------------- 1 | rootProject.name = "kmp-fatframework-cocoa" 2 | 3 | -------------------------------------------------------------------------------- /src/main/kotlin/com/prof18/kmp/fatframework/cocoa/CocoaPodRepoDSL.kt: -------------------------------------------------------------------------------- 1 | package com.prof18.kmp.fatframework.cocoa 2 | 3 | class CocoaPodRepoDSL { 4 | var summary: String = "" 5 | var homepage: String = "" 6 | var license: String = "" 7 | var authors: String = "" 8 | var gitUrl: String = "" 9 | } -------------------------------------------------------------------------------- /src/main/kotlin/com/prof18/kmp/fatframework/cocoa/KMPFatFrameworkCocoaExtension.kt: -------------------------------------------------------------------------------- 1 | package com.prof18.kmp.fatframework.cocoa 2 | 3 | import com.prof18.kmp.fatframework.cocoa.data.CocoaPodRepoInfo 4 | import groovy.lang.Closure 5 | import org.gradle.api.Project 6 | import org.gradle.util.ConfigureUtil 7 | import org.jetbrains.kotlin.gradle.plugin.mpp.Framework 8 | import javax.inject.Inject 9 | 10 | internal const val FAT_FRAMEWORK_COCOA_EXTENSION = "fatFrameworkCocoaConfig" 11 | 12 | @Suppress("UnnecessaryAbstractClass") 13 | abstract class KMPFatFrameworkCocoaExtension @Inject constructor(project: Project) { 14 | 15 | var frameworkName: String? = null 16 | var outputPath: String? = null 17 | var versionName: String? = null 18 | var useXCFramework: Boolean = false 19 | 20 | // Internal variables 21 | internal val debugFrameworkList: MutableList = mutableListOf() 22 | internal val releaseFrameworkList: MutableList = mutableListOf() 23 | internal var cocoaPodRepoInfo: CocoaPodRepoInfo = CocoaPodRepoInfo() 24 | 25 | fun cocoaPodRepoInfo(configure: CocoaPodRepoDSL.() -> Unit) { 26 | CocoaPodRepoDSL().also { dsl -> 27 | dsl.configure() 28 | cocoaPodRepoInfo = CocoaPodRepoInfo( 29 | summary = dsl.summary, 30 | homepage = dsl.homepage, 31 | license = dsl.license, 32 | authors = dsl.authors, 33 | gitUrl = dsl.gitUrl 34 | ) 35 | 36 | } 37 | } 38 | 39 | fun cocoaPodRepoInfo(configure: Closure) { 40 | cocoaPodRepoInfo { ConfigureUtil.configure(configure, this) } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/main/kotlin/com/prof18/kmp/fatframework/cocoa/KMPFatFrameworkCocoaPlugin.kt: -------------------------------------------------------------------------------- 1 | package com.prof18.kmp.fatframework.cocoa 2 | 3 | import com.prof18.kmp.fatframework.cocoa.task.common.registerPublishPreparationTasks 4 | import com.prof18.kmp.fatframework.cocoa.task.fatframework.registerBuildDebugFatFrameworkTask 5 | import com.prof18.kmp.fatframework.cocoa.task.fatframework.registerBuildReleaseFatFrameworkTask 6 | import com.prof18.kmp.fatframework.cocoa.task.fatframework.registerPublishDebugFatFrameworkTask 7 | import com.prof18.kmp.fatframework.cocoa.task.fatframework.registerPublishReleaseFatFrameworkTask 8 | import com.prof18.kmp.fatframework.cocoa.task.registerGenerateCocoaPodRepositoryTask 9 | import com.prof18.kmp.fatframework.cocoa.task.xcframework.registerBuildDebugXCFrameworkTask 10 | import com.prof18.kmp.fatframework.cocoa.task.xcframework.registerBuildReleaseXCFrameworkTask 11 | import com.prof18.kmp.fatframework.cocoa.task.xcframework.registerPublishDebugXCFrameworkTask 12 | import com.prof18.kmp.fatframework.cocoa.task.xcframework.registerPublishReleaseXCFrameworkTask 13 | import org.gradle.api.Plugin 14 | import org.gradle.api.Project 15 | import org.gradle.kotlin.dsl.findByType 16 | import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension 17 | import org.jetbrains.kotlin.gradle.plugin.mpp.Framework 18 | import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget 19 | import org.jetbrains.kotlin.gradle.plugin.mpp.NativeBuildType 20 | import org.jetbrains.kotlin.gradle.plugin.mpp.NativeOutputKind 21 | import org.jetbrains.kotlin.konan.target.Family 22 | 23 | abstract class KMPFatFrameworkCocoaPlugin : Plugin { 24 | override fun apply(project: Project) { 25 | // Add the 'template' extension object 26 | val extension = 27 | project.extensions.create(FAT_FRAMEWORK_COCOA_EXTENSION, KMPFatFrameworkCocoaExtension::class.java, project) 28 | 29 | project.afterEvaluate { 30 | project.extensions.findByType() 31 | ?.let { kmpExtension: KotlinMultiplatformExtension -> 32 | 33 | val nativeTargetList: List = kmpExtension.targets.toList() 34 | .filterIsInstance() 35 | .filter { 36 | if (extension.useXCFramework) { 37 | it.konanTarget.family.isAppleFamily 38 | } else { 39 | it.konanTarget.family == Family.IOS 40 | } 41 | } 42 | 43 | val debugFrameworks: List = nativeTargetList 44 | .flatMap { 45 | it.binaries 46 | .filter { binary -> 47 | binary.buildType == NativeBuildType.DEBUG && binary.outputKind == NativeOutputKind.FRAMEWORK 48 | } 49 | .mapNotNull { binary -> 50 | // Nullable cast just to be safe 51 | binary as? Framework 52 | } 53 | } 54 | 55 | val releaseFrameworks: List = nativeTargetList 56 | .flatMap { 57 | it.binaries 58 | .filter { binary -> 59 | binary.buildType == NativeBuildType.RELEASE && binary.outputKind == NativeOutputKind.FRAMEWORK 60 | } 61 | .mapNotNull { binary -> 62 | // Nullable cast just to be safe 63 | binary as? Framework 64 | } 65 | } 66 | 67 | extension.debugFrameworkList.addAll(debugFrameworks) 68 | extension.releaseFrameworkList.addAll(releaseFrameworks) 69 | 70 | // Register Tasks 71 | // Cocoa Pod Repo 72 | project.registerGenerateCocoaPodRepositoryTask() 73 | 74 | project.registerPublishPreparationTasks() 75 | if (extension.useXCFramework) { 76 | // Build 77 | project.registerBuildDebugXCFrameworkTask() 78 | project.registerBuildReleaseXCFrameworkTask() 79 | 80 | // Release 81 | project.registerPublishDebugXCFrameworkTask() 82 | project.registerPublishReleaseXCFrameworkTask() 83 | } else { 84 | // Build 85 | project.registerBuildDebugFatFrameworkTask() 86 | project.registerBuildReleaseFatFrameworkTask() 87 | 88 | // Release 89 | project.registerPublishDebugFatFrameworkTask() 90 | project.registerPublishReleaseFatFrameworkTask() 91 | } 92 | } 93 | } 94 | } 95 | } 96 | 97 | 98 | 99 | -------------------------------------------------------------------------------- /src/main/kotlin/com/prof18/kmp/fatframework/cocoa/data/CocoaPodRepoInfo.kt: -------------------------------------------------------------------------------- 1 | package com.prof18.kmp.fatframework.cocoa.data 2 | 3 | import com.prof18.kmp.fatframework.cocoa.KMPFatFrameworkCocoaPlugin 4 | 5 | internal data class CocoaPodRepoInfo( 6 | var summary: String = "", 7 | var homepage: String = "", 8 | var license: String = "", 9 | var authors: String = "", 10 | var gitUrl: String = "" 11 | ) { 12 | internal companion object { 13 | internal val templateFile = 14 | KMPFatFrameworkCocoaPlugin::class.java.getResource("/template/Framework.podspec.template") 15 | } 16 | } -------------------------------------------------------------------------------- /src/main/kotlin/com/prof18/kmp/fatframework/cocoa/data/PluginConfig.kt: -------------------------------------------------------------------------------- 1 | package com.prof18.kmp.fatframework.cocoa.data 2 | 3 | import com.prof18.kmp.fatframework.cocoa.FAT_FRAMEWORK_COCOA_EXTENSION 4 | import com.prof18.kmp.fatframework.cocoa.KMPFatFrameworkCocoaExtension 5 | import org.gradle.api.InvalidUserDataException 6 | import org.gradle.api.Project 7 | import org.jetbrains.kotlin.gradle.plugin.mpp.Framework 8 | import java.io.File 9 | 10 | @Throws(InvalidUserDataException::class) 11 | internal fun Project.getConfigurationOrThrow() = PluginConfig.of( 12 | extensions.findByName(FAT_FRAMEWORK_COCOA_EXTENSION) as KMPFatFrameworkCocoaExtension 13 | ) 14 | 15 | internal class PluginConfig private constructor( 16 | val debugFatFrameworkList: List, 17 | val releaseFatFrameworkList: List, 18 | val frameworkName: String, 19 | val outputPath: String, 20 | val versionName: String, 21 | val cocoaPodRepoInfo: CocoaPodRepoInfo, 22 | val useXCFramework: Boolean 23 | ) { 24 | 25 | internal fun getPodSpecFile() = File("${outputPath}/${frameworkName}.podspec") 26 | 27 | internal companion object { 28 | fun of(extension: KMPFatFrameworkCocoaExtension): PluginConfig { 29 | 30 | val frameworkName: String = if (extension.frameworkName == null) { 31 | throw InvalidUserDataException(PluginConfigErrorMessages.FRAMEWORK_NAME_NOT_PRESENT_MESSAGE) 32 | } else { 33 | extension.frameworkName!! 34 | } 35 | val outputPath = if (extension.outputPath == null) { 36 | throw InvalidUserDataException(PluginConfigErrorMessages.OUTPUT_PATH_NOT_PRESENT_MESSAGE) 37 | } else { 38 | extension.outputPath!! 39 | } 40 | 41 | val versionName = if (extension.versionName == null) { 42 | throw InvalidUserDataException(PluginConfigErrorMessages.VERSION_NAME_NOT_PRESENT_MESSAGE) 43 | } else { 44 | extension.versionName!! 45 | } 46 | 47 | return PluginConfig( 48 | debugFatFrameworkList = extension.debugFrameworkList, 49 | releaseFatFrameworkList = extension.releaseFrameworkList, 50 | frameworkName = frameworkName, 51 | outputPath = outputPath, 52 | versionName = versionName, 53 | cocoaPodRepoInfo = extension.cocoaPodRepoInfo, 54 | useXCFramework = extension.useXCFramework 55 | ) 56 | } 57 | } 58 | } -------------------------------------------------------------------------------- /src/main/kotlin/com/prof18/kmp/fatframework/cocoa/data/PluginConfigErrorMessages.kt: -------------------------------------------------------------------------------- 1 | package com.prof18.kmp.fatframework.cocoa.data 2 | 3 | internal object PluginConfigErrorMessages { 4 | internal const val FRAMEWORK_NAME_NOT_PRESENT_MESSAGE = "You must provide the property `frameworkName`" 5 | internal const val OUTPUT_PATH_NOT_PRESENT_MESSAGE = "You must provide the property `outputPath`" 6 | internal const val VERSION_NAME_NOT_PRESENT_MESSAGE = "You must provide the property `versionName`" 7 | } -------------------------------------------------------------------------------- /src/main/kotlin/com/prof18/kmp/fatframework/cocoa/task/GenerateCocoaPodRepositoryTask.kt: -------------------------------------------------------------------------------- 1 | package com.prof18.kmp.fatframework.cocoa.task 2 | 3 | import com.prof18.kmp.fatframework.cocoa.data.CocoaPodRepoInfo 4 | import com.prof18.kmp.fatframework.cocoa.data.getConfigurationOrThrow 5 | import com.prof18.kmp.fatframework.cocoa.utils.execBashCommandThrowExecException 6 | import com.prof18.kmp.fatframework.cocoa.utils.retrieveMainBranchName 7 | import groovy.text.SimpleTemplateEngine 8 | import org.gradle.api.Project 9 | import java.io.File 10 | 11 | internal const val GENERATE_COCOA_POD_TASK_NAME = "generateCocoaPodRepo" 12 | 13 | internal fun Project.registerGenerateCocoaPodRepositoryTask() { 14 | tasks.register(GENERATE_COCOA_POD_TASK_NAME) { 15 | 16 | description = "Create a CocoaPod repository to distribute the FatFramework" 17 | 18 | doLast { 19 | val conf = getConfigurationOrThrow() 20 | val podspecFileName = "${conf.frameworkName}.podspec" 21 | 22 | val parentFile = File(conf.outputPath) 23 | 24 | val podspecFile = File("${conf.outputPath}/$podspecFileName").apply { 25 | this.parentFile.mkdirs() 26 | createNewFile() 27 | } 28 | 29 | val frameworkName = if (conf.useXCFramework) { 30 | "${conf.frameworkName}.xcframework" 31 | } else { 32 | "${conf.frameworkName}.framework" 33 | } 34 | 35 | val templateMap = mapOf( 36 | "name" to conf.frameworkName, 37 | "version" to conf.versionName, 38 | "summary" to conf.cocoaPodRepoInfo.summary, 39 | "homepage" to conf.cocoaPodRepoInfo.homepage, 40 | "license" to conf.cocoaPodRepoInfo.license, 41 | "authors" to conf.cocoaPodRepoInfo.authors, 42 | "gitUrl" to conf.cocoaPodRepoInfo.gitUrl, 43 | "frameworkName" to frameworkName 44 | ) 45 | 46 | SimpleTemplateEngine() 47 | .createTemplate(CocoaPodRepoInfo.templateFile) 48 | .make(templateMap) 49 | .writeTo(podspecFile.writer()) 50 | 51 | execBashCommandThrowExecException( 52 | output = parentFile, 53 | commandList = listOf("git", "init"), 54 | exceptionMessage = "Unable to create the git repository" 55 | ) 56 | 57 | execBashCommandThrowExecException( 58 | output = parentFile, 59 | commandList = listOf("git", "add", "."), 60 | exceptionMessage = "Unable to add changes on main" 61 | ) 62 | 63 | execBashCommandThrowExecException( 64 | output = parentFile, 65 | commandList = listOf("git", "commit", "-m", "\"First Commit\""), 66 | exceptionMessage = "Unable to commit changes on main" 67 | ) 68 | 69 | execBashCommandThrowExecException( 70 | output = parentFile, 71 | commandList = listOf("git", "checkout", "-b", "develop"), 72 | exceptionMessage = "Unable to create the develop branch" 73 | ) 74 | 75 | execBashCommandThrowExecException( 76 | output = parentFile, 77 | commandList = listOf("git", "remote", "add", "origin", conf.cocoaPodRepoInfo.gitUrl), 78 | exceptionMessage = "Unable to push on remote repository" 79 | ) 80 | 81 | val branchName = retrieveMainBranchName(conf.outputPath) 82 | println(branchName) 83 | execBashCommandThrowExecException( 84 | output = parentFile, 85 | commandList = listOf("git", "push", "origin", "develop", branchName), 86 | exceptionMessage = "Unable to push on remote repository" 87 | ) 88 | } 89 | } 90 | } -------------------------------------------------------------------------------- /src/main/kotlin/com/prof18/kmp/fatframework/cocoa/task/common/PublishDebugUtils.kt: -------------------------------------------------------------------------------- 1 | package com.prof18.kmp.fatframework.cocoa.task.common 2 | 3 | import com.prof18.kmp.fatframework.cocoa.data.PluginConfig 4 | import com.prof18.kmp.fatframework.cocoa.utils.execBashCommandInRepoAndThrowExecException 5 | import org.gradle.api.Project 6 | import org.gradle.process.internal.ExecException 7 | import java.io.File 8 | import java.io.IOException 9 | import java.text.SimpleDateFormat 10 | import java.util.* 11 | 12 | internal fun Project.publishDebugFramework(config: PluginConfig) { 13 | val podSpecFile = config.getPodSpecFile() 14 | if (!podSpecFile.exists()) { 15 | throw ExecException("podspec file does not exists!") 16 | } 17 | 18 | val tempPodSpecFile = File("${config.outputPath}/${config.frameworkName}.podspec.new") 19 | 20 | val reader = podSpecFile.bufferedReader() 21 | val writer = tempPodSpecFile.bufferedWriter() 22 | var currentLine: String? 23 | 24 | try { 25 | while (reader.readLine().also { currLine -> currentLine = currLine } != null) { 26 | if (currentLine?.startsWith("s.version") == true) { 27 | writer.write("s.version = \"${config.versionName}\"" + System.lineSeparator()) 28 | } else { 29 | writer.write(currentLine + System.lineSeparator()) 30 | } 31 | } 32 | } catch (e: IOException) { 33 | throw ExecException("Unable to update the version on the podspec file") 34 | } finally { 35 | writer.close() 36 | reader.close() 37 | } 38 | 39 | val renameSuccessful = tempPodSpecFile.renameTo(podSpecFile) 40 | if (renameSuccessful) { 41 | val dateFormatter = SimpleDateFormat("dd/MM/yyyy - HH:mm", Locale.getDefault()) 42 | 43 | execBashCommandInRepoAndThrowExecException( 44 | commandList = listOf("git", "add", "."), 45 | exceptionMessage = "Unable to add the files" 46 | ) 47 | 48 | execBashCommandInRepoAndThrowExecException( 49 | commandList = listOf( 50 | "git", 51 | "commit", 52 | "-m", 53 | "\"New debug release: ${config.versionName} - ${dateFormatter.format(Date())}\"" 54 | ), 55 | exceptionMessage = "Unable to commit the changes" 56 | ) 57 | 58 | execBashCommandInRepoAndThrowExecException( 59 | commandList = listOf("git", "push", "origin", "develop"), 60 | exceptionMessage = "Unable to push the changes to remote" 61 | ) 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src/main/kotlin/com/prof18/kmp/fatframework/cocoa/task/common/PublishPreparationTasks.kt: -------------------------------------------------------------------------------- 1 | package com.prof18.kmp.fatframework.cocoa.task.common 2 | 3 | import com.prof18.kmp.fatframework.cocoa.data.getConfigurationOrThrow 4 | import com.prof18.kmp.fatframework.cocoa.utils.execBashCommandInRepoAndThrowExecException 5 | import com.prof18.kmp.fatframework.cocoa.utils.executeBashCommand 6 | import com.prof18.kmp.fatframework.cocoa.utils.retrieveMainBranchName 7 | import org.gradle.api.InvalidUserDataException 8 | import org.gradle.api.Project 9 | import org.gradle.process.internal.ExecException 10 | 11 | internal const val PREPARE_COCOA_REPO_FOR_DEBUG_TASK_NAME = "prepareIosCocoaRepoForDebug" 12 | internal const val PREPARE_COCOA_REPO_FOR_RELEASE_TASK_NAME = "prepareIosCocoaRepoForRelease" 13 | 14 | internal fun Project.registerPublishPreparationTasks() { 15 | 16 | tasks.register(PREPARE_COCOA_REPO_FOR_DEBUG_TASK_NAME) { 17 | description = "Prepare the CocoaPod repository for debug." 18 | 19 | val config = getConfigurationOrThrow() 20 | // Check if is a git repository 21 | doLast { 22 | try { 23 | executeBashCommand( 24 | showOutput = false, 25 | workingDirPath = config.outputPath, 26 | commandList = listOf("git", "rev-parse", "--is-inside-work-tree") 27 | ) 28 | } catch (e: ExecException) { 29 | throw InvalidUserDataException("The provided output folder is not a git repository!") 30 | } 31 | 32 | // Checkout on develop 33 | execBashCommandInRepoAndThrowExecException( 34 | commandList = listOf("git", "checkout", "develop"), 35 | exceptionMessage = "Error while checking out to the develop branch. Are you sure it does exists?" 36 | ) 37 | } 38 | } 39 | 40 | tasks.register(PREPARE_COCOA_REPO_FOR_RELEASE_TASK_NAME) { 41 | description = "Prepare the CocoaPod repository for release." 42 | 43 | val config = getConfigurationOrThrow() 44 | 45 | doLast { 46 | 47 | // Check if is a git repository 48 | try { 49 | executeBashCommand( 50 | showOutput = false, 51 | workingDirPath = config.outputPath, 52 | commandList = listOf("git", "rev-parse", "--is-inside-work-tree") 53 | ) 54 | } catch (e: ExecException) { 55 | throw InvalidUserDataException("The provided output folder is not a git repository!") 56 | } 57 | 58 | // Check if master or main 59 | val branchName = retrieveMainBranchName(config.outputPath) 60 | 61 | // Checkout on selected branch 62 | execBashCommandInRepoAndThrowExecException( 63 | commandList = listOf("git", "checkout", branchName), 64 | exceptionMessage = "Error while checking out to the $branchName branch. Are you it does exists?" 65 | ) 66 | } 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /src/main/kotlin/com/prof18/kmp/fatframework/cocoa/task/common/PublishReleaseUtils.kt: -------------------------------------------------------------------------------- 1 | package com.prof18.kmp.fatframework.cocoa.task.common 2 | 3 | import com.prof18.kmp.fatframework.cocoa.data.PluginConfig 4 | import com.prof18.kmp.fatframework.cocoa.utils.execBashCommandInRepoAndThrowExecException 5 | import com.prof18.kmp.fatframework.cocoa.utils.retrieveMainBranchName 6 | import org.gradle.api.Project 7 | import org.gradle.process.internal.ExecException 8 | import java.io.File 9 | import java.io.IOException 10 | import java.text.SimpleDateFormat 11 | import java.util.* 12 | 13 | internal fun Project.publishReleaseFramework(config: PluginConfig) { 14 | val podSpecFile = config.getPodSpecFile() 15 | if (!podSpecFile.exists()) { 16 | throw ExecException("podspec file does not exists!") 17 | } 18 | 19 | val tempPodSpecFile = File("${config.outputPath}/${config.frameworkName}.podspec.new") 20 | 21 | val reader = podSpecFile.bufferedReader() 22 | val writer = tempPodSpecFile.bufferedWriter() 23 | var currentLine: String? 24 | 25 | try { 26 | while (reader.readLine().also { currLine -> currentLine = currLine } != null) { 27 | if (currentLine?.startsWith("s.version") == true) { 28 | writer.write("s.version = \"${config.versionName}\"" + System.lineSeparator()) 29 | } else { 30 | writer.write(currentLine + System.lineSeparator()) 31 | } 32 | } 33 | } catch (e: IOException) { 34 | throw ExecException("Unable to update the version on the podspec file") 35 | } finally { 36 | writer.close() 37 | reader.close() 38 | } 39 | 40 | val renameSuccessful = tempPodSpecFile.renameTo(podSpecFile) 41 | if (renameSuccessful) { 42 | val dateFormatter = SimpleDateFormat("dd/MM/yyyy - HH:mm", Locale.getDefault()) 43 | 44 | execBashCommandInRepoAndThrowExecException( 45 | commandList = listOf("git", "add", "."), 46 | exceptionMessage = "Unable to add the files" 47 | ) 48 | 49 | execBashCommandInRepoAndThrowExecException( 50 | commandList = listOf( 51 | "git", 52 | "commit", 53 | "-m", 54 | "\"New release: ${config.versionName} - ${dateFormatter.format(Date())}\"" 55 | ), 56 | exceptionMessage = "Unable to commit the changes" 57 | ) 58 | 59 | execBashCommandInRepoAndThrowExecException( 60 | commandList = listOf("git", "tag", config.versionName), 61 | exceptionMessage = "Unable to tag the commit" 62 | ) 63 | 64 | val branchName = retrieveMainBranchName(config.outputPath) 65 | execBashCommandInRepoAndThrowExecException( 66 | commandList = listOf("git", "push", "origin", branchName, "--tags"), 67 | exceptionMessage = "Unable to push the changes to remote" 68 | ) 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /src/main/kotlin/com/prof18/kmp/fatframework/cocoa/task/fatframework/BuildDebugFatFrameworkTask.kt: -------------------------------------------------------------------------------- 1 | package com.prof18.kmp.fatframework.cocoa.task.fatframework 2 | 3 | import com.prof18.kmp.fatframework.cocoa.data.getConfigurationOrThrow 4 | import org.gradle.api.Project 5 | import org.jetbrains.kotlin.gradle.tasks.FatFrameworkTask 6 | import java.io.File 7 | 8 | internal const val BUILD_DEBUG_FAT_FRAMEWORK_TASK_NAME = "buildDebugIosFatFramework" 9 | 10 | internal fun Project.registerBuildDebugFatFrameworkTask() { 11 | tasks.register(BUILD_DEBUG_FAT_FRAMEWORK_TASK_NAME, FatFrameworkTask::class.java) { 12 | description = "Create a Debug Fat Framework" 13 | 14 | val config = getConfigurationOrThrow() 15 | for (framework in config.debugFatFrameworkList) { 16 | dependsOn(framework.linkTaskName) 17 | } 18 | baseName = config.frameworkName 19 | from(config.debugFatFrameworkList) 20 | destinationDir = File(config.outputPath) 21 | } 22 | } -------------------------------------------------------------------------------- /src/main/kotlin/com/prof18/kmp/fatframework/cocoa/task/fatframework/BuildReleaseFatFrameworkTask.kt: -------------------------------------------------------------------------------- 1 | package com.prof18.kmp.fatframework.cocoa.task.fatframework 2 | 3 | import com.prof18.kmp.fatframework.cocoa.data.getConfigurationOrThrow 4 | import org.gradle.api.Project 5 | import org.jetbrains.kotlin.gradle.tasks.FatFrameworkTask 6 | import java.io.File 7 | 8 | internal const val BUILD_RELEASE_FAT_FRAMEWORK_TASK_NAME = "buildReleaseIosFatFramework" 9 | 10 | internal fun Project.registerBuildReleaseFatFrameworkTask() { 11 | tasks.register(BUILD_RELEASE_FAT_FRAMEWORK_TASK_NAME, FatFrameworkTask::class.java) { 12 | description = "Create a Release Fat Framework" 13 | 14 | val config = getConfigurationOrThrow() 15 | for (framework in config.releaseFatFrameworkList) { 16 | dependsOn(framework.linkTaskName) 17 | } 18 | baseName = config.frameworkName 19 | from(config.releaseFatFrameworkList) 20 | destinationDir = File(config.outputPath) 21 | } 22 | } -------------------------------------------------------------------------------- /src/main/kotlin/com/prof18/kmp/fatframework/cocoa/task/fatframework/PublishDebugFatFramework.kt: -------------------------------------------------------------------------------- 1 | package com.prof18.kmp.fatframework.cocoa.task.fatframework 2 | 3 | import com.prof18.kmp.fatframework.cocoa.data.getConfigurationOrThrow 4 | import com.prof18.kmp.fatframework.cocoa.task.common.PREPARE_COCOA_REPO_FOR_DEBUG_TASK_NAME 5 | import com.prof18.kmp.fatframework.cocoa.task.common.publishDebugFramework 6 | import org.gradle.api.Project 7 | 8 | internal const val PUBLISH_DEBUG_FAT_FRAMEWORK_TASK_NAME = "publishDebugIosFatFramework" 9 | 10 | internal fun Project.registerPublishDebugFatFrameworkTask() { 11 | 12 | tasks.register(PUBLISH_DEBUG_FAT_FRAMEWORK_TASK_NAME) { 13 | description = "Publish the debug FatFramework to a CocoaPod repository" 14 | 15 | val config = getConfigurationOrThrow() 16 | 17 | mustRunAfter(PREPARE_COCOA_REPO_FOR_DEBUG_TASK_NAME) 18 | dependsOn(PREPARE_COCOA_REPO_FOR_DEBUG_TASK_NAME) 19 | dependsOn(BUILD_DEBUG_FAT_FRAMEWORK_TASK_NAME) 20 | 21 | doLast { 22 | publishDebugFramework(config) 23 | } 24 | } 25 | } -------------------------------------------------------------------------------- /src/main/kotlin/com/prof18/kmp/fatframework/cocoa/task/fatframework/PublishReleaseFatFramework.kt: -------------------------------------------------------------------------------- 1 | package com.prof18.kmp.fatframework.cocoa.task.fatframework 2 | 3 | import com.prof18.kmp.fatframework.cocoa.data.getConfigurationOrThrow 4 | import com.prof18.kmp.fatframework.cocoa.task.common.PREPARE_COCOA_REPO_FOR_RELEASE_TASK_NAME 5 | import com.prof18.kmp.fatframework.cocoa.task.common.publishReleaseFramework 6 | import org.gradle.api.Project 7 | 8 | internal const val PUBLISH_RELEASE_FAT_FRAMEWORK_TASK_NAME = "publishReleaseIosFatFramework" 9 | 10 | internal fun Project.registerPublishReleaseFatFrameworkTask() { 11 | tasks.register(PUBLISH_RELEASE_FAT_FRAMEWORK_TASK_NAME) { 12 | description = "Publish the release FatFramework to a CocoaPod repository" 13 | 14 | val config = getConfigurationOrThrow() 15 | 16 | mustRunAfter(PREPARE_COCOA_REPO_FOR_RELEASE_TASK_NAME) 17 | dependsOn(PREPARE_COCOA_REPO_FOR_RELEASE_TASK_NAME) 18 | dependsOn(BUILD_RELEASE_FAT_FRAMEWORK_TASK_NAME) 19 | 20 | doLast { 21 | publishReleaseFramework(config) 22 | } 23 | } 24 | } -------------------------------------------------------------------------------- /src/main/kotlin/com/prof18/kmp/fatframework/cocoa/task/xcframework/BuildDebugXCFrameworkTask.kt: -------------------------------------------------------------------------------- 1 | package com.prof18.kmp.fatframework.cocoa.task.xcframework 2 | 3 | import com.prof18.kmp.fatframework.cocoa.data.getConfigurationOrThrow 4 | import com.prof18.kmp.fatframework.cocoa.task.xcframework.common.buildXCFramework 5 | import org.gradle.api.Project 6 | import org.gradle.api.tasks.Exec 7 | 8 | internal const val BUILD_DEBUG_XC_FRAMEWORK_TASK_NAME = "buildDebugXCFramework" 9 | 10 | internal fun Project.registerBuildDebugXCFrameworkTask() { 11 | tasks.register(BUILD_DEBUG_XC_FRAMEWORK_TASK_NAME, Exec::class.java) { 12 | description = "Create a Debug XCFramework" 13 | 14 | val config = getConfigurationOrThrow() 15 | buildXCFramework(config, config.debugFatFrameworkList) 16 | } 17 | } -------------------------------------------------------------------------------- /src/main/kotlin/com/prof18/kmp/fatframework/cocoa/task/xcframework/BuildReleaseXCFrameworkTask.kt: -------------------------------------------------------------------------------- 1 | package com.prof18.kmp.fatframework.cocoa.task.xcframework 2 | 3 | import com.prof18.kmp.fatframework.cocoa.data.getConfigurationOrThrow 4 | import com.prof18.kmp.fatframework.cocoa.task.xcframework.common.buildXCFramework 5 | import org.gradle.api.Project 6 | import org.gradle.api.tasks.Exec 7 | 8 | internal const val BUILD_RELEASE_XC_FRAMEWORK_TASK_NAME = "buildReleaseXCFramework" 9 | 10 | internal fun Project.registerBuildReleaseXCFrameworkTask() { 11 | tasks.register(BUILD_RELEASE_XC_FRAMEWORK_TASK_NAME, Exec::class.java) { 12 | description = "Create a Release XCFramework" 13 | 14 | val config = getConfigurationOrThrow() 15 | buildXCFramework(config, config.releaseFatFrameworkList) 16 | } 17 | } -------------------------------------------------------------------------------- /src/main/kotlin/com/prof18/kmp/fatframework/cocoa/task/xcframework/PublishDebugXCFramework.kt: -------------------------------------------------------------------------------- 1 | package com.prof18.kmp.fatframework.cocoa.task.xcframework 2 | 3 | import com.prof18.kmp.fatframework.cocoa.data.getConfigurationOrThrow 4 | import com.prof18.kmp.fatframework.cocoa.task.common.PREPARE_COCOA_REPO_FOR_DEBUG_TASK_NAME 5 | import com.prof18.kmp.fatframework.cocoa.task.common.publishDebugFramework 6 | import org.gradle.api.Project 7 | 8 | internal const val PUBLISH_DEBUG_XC_FRAMEWORK_TASK_NAME = "publishDebugXCFramework" 9 | 10 | internal fun Project.registerPublishDebugXCFrameworkTask() { 11 | 12 | tasks.register(PUBLISH_DEBUG_XC_FRAMEWORK_TASK_NAME) { 13 | description = "Publish the debug XCFramework to a CocoaPod repository" 14 | 15 | val config = getConfigurationOrThrow() 16 | 17 | mustRunAfter(PREPARE_COCOA_REPO_FOR_DEBUG_TASK_NAME) 18 | dependsOn(PREPARE_COCOA_REPO_FOR_DEBUG_TASK_NAME) 19 | dependsOn(BUILD_DEBUG_XC_FRAMEWORK_TASK_NAME) 20 | 21 | doLast { 22 | publishDebugFramework(config) 23 | } 24 | } 25 | } -------------------------------------------------------------------------------- /src/main/kotlin/com/prof18/kmp/fatframework/cocoa/task/xcframework/PublishReleaseXCFramework.kt: -------------------------------------------------------------------------------- 1 | package com.prof18.kmp.fatframework.cocoa.task.xcframework 2 | 3 | import com.prof18.kmp.fatframework.cocoa.data.getConfigurationOrThrow 4 | import com.prof18.kmp.fatframework.cocoa.task.common.PREPARE_COCOA_REPO_FOR_RELEASE_TASK_NAME 5 | import com.prof18.kmp.fatframework.cocoa.task.common.publishReleaseFramework 6 | import org.gradle.api.Project 7 | 8 | internal const val PUBLISH_RELEASE_XC_FRAMEWORK_TASK_NAME = "publishReleaseXCFramework" 9 | 10 | internal fun Project.registerPublishReleaseXCFrameworkTask() { 11 | tasks.register(PUBLISH_RELEASE_XC_FRAMEWORK_TASK_NAME) { 12 | description = "Publish the release XCFramework to a CocoaPod repository" 13 | 14 | val config = getConfigurationOrThrow() 15 | 16 | mustRunAfter(PREPARE_COCOA_REPO_FOR_RELEASE_TASK_NAME) 17 | dependsOn(PREPARE_COCOA_REPO_FOR_RELEASE_TASK_NAME) 18 | dependsOn(BUILD_RELEASE_XC_FRAMEWORK_TASK_NAME) 19 | 20 | doLast { 21 | publishReleaseFramework(config) 22 | } 23 | } 24 | } -------------------------------------------------------------------------------- /src/main/kotlin/com/prof18/kmp/fatframework/cocoa/task/xcframework/common/BuildXCFramework.kt: -------------------------------------------------------------------------------- 1 | package com.prof18.kmp.fatframework.cocoa.task.xcframework.common 2 | 3 | import com.prof18.kmp.fatframework.cocoa.data.PluginConfig 4 | import com.prof18.kmp.fatframework.cocoa.utils.dsymFile 5 | import org.gradle.api.tasks.Exec 6 | import org.jetbrains.kotlin.gradle.plugin.mpp.Framework 7 | import java.io.File 8 | 9 | internal fun Exec.buildXCFramework(config: PluginConfig, frameworks: List) { 10 | for (framework in frameworks) { 11 | dependsOn(framework.linkTaskName) 12 | } 13 | 14 | val xcFrameworkDest = File("${config.outputPath}/${config.frameworkName}.xcframework") 15 | 16 | // Params taken from https://github.com/ge-org/multiplatform-swiftpackage/blob/master/src/main/kotlin/com/chromaticnoise/multiplatformswiftpackage/task/CreateXCFrameworkTask.kt 17 | executable = "xcodebuild" 18 | args(mutableListOf().apply { 19 | add("-create-xcframework") 20 | add("-output") 21 | add(xcFrameworkDest.path) 22 | for (framework in frameworks) { 23 | add("-framework") 24 | add(framework.outputFile.path) 25 | 26 | framework.dsymFile().takeIf { it.exists() }?.let { dsymFile -> 27 | add("-debug-symbols") 28 | add(dsymFile.path) 29 | } 30 | } 31 | }) 32 | 33 | doFirst { 34 | xcFrameworkDest.deleteRecursively() 35 | } 36 | } -------------------------------------------------------------------------------- /src/main/kotlin/com/prof18/kmp/fatframework/cocoa/utils/Utils.kt: -------------------------------------------------------------------------------- 1 | package com.prof18.kmp.fatframework.cocoa.utils 2 | 3 | import com.prof18.kmp.fatframework.cocoa.data.getConfigurationOrThrow 4 | import org.gradle.api.Project 5 | import org.gradle.process.internal.ExecException 6 | import java.io.ByteArrayOutputStream 7 | import java.io.File 8 | import org.jetbrains.kotlin.gradle.plugin.mpp.Framework 9 | 10 | internal fun Framework.dsymFile(): File { 11 | return File(outputFile.parent, "${name}.framework.dSYM") 12 | } 13 | 14 | internal fun Project.executeBashCommand(showOutput: Boolean = true, workingDirPath: String, commandList: List): String { 15 | return ByteArrayOutputStream().use { outputStream -> 16 | project.exec { 17 | workingDir = File(workingDirPath) 18 | commandLine(commandList) 19 | standardOutput = outputStream 20 | } 21 | val output = outputStream.toString() 22 | if (showOutput) { 23 | print(output) 24 | } 25 | return@use output 26 | } 27 | } 28 | 29 | internal fun Project.executeBashCommand(showOutput: Boolean = true, workingDirFile: File, commandList: List): String { 30 | return ByteArrayOutputStream().use { outputStream -> 31 | project.exec { 32 | workingDir = workingDirFile 33 | commandLine(commandList) 34 | standardOutput = outputStream 35 | } 36 | val output = outputStream.toString() 37 | if (showOutput) { 38 | print(output) 39 | } 40 | return@use output 41 | } 42 | } 43 | 44 | internal fun Project.execBashCommandInRepoAndThrowExecException(commandList: List, exceptionMessage: String) { 45 | val config = getConfigurationOrThrow() 46 | try { 47 | executeBashCommand( 48 | workingDirPath = config.outputPath, 49 | commandList = commandList 50 | ) 51 | } catch (e: ExecException) { 52 | throw ExecException(exceptionMessage) 53 | } 54 | } 55 | 56 | internal fun Project.execBashCommandThrowExecException(output: File, commandList: List, exceptionMessage: String) { 57 | try { 58 | executeBashCommand( 59 | workingDirFile = output, 60 | commandList = commandList 61 | ) 62 | } catch (e: ExecException) { 63 | throw ExecException(exceptionMessage) 64 | } 65 | } 66 | 67 | internal fun Project.retrieveMainBranchName(outputPath: String): String { 68 | var branchName = "" 69 | try { 70 | val checkMainOutput = executeBashCommand( 71 | showOutput = false, 72 | workingDirPath = outputPath, 73 | commandList = listOf("git", "branch", "--list", "main") 74 | ) 75 | if (checkMainOutput.contains("main")) { 76 | branchName = "main" 77 | } 78 | 79 | println(branchName) 80 | 81 | if (branchName.isEmpty()) { 82 | val checkMasterOutput = executeBashCommand( 83 | showOutput = false, 84 | workingDirPath = outputPath, 85 | commandList = listOf("git", "branch", "--list", "master") 86 | ) 87 | if (checkMasterOutput.contains("master")) { 88 | branchName = "master" 89 | } 90 | } 91 | } catch (e: ExecException) { 92 | throw ExecException("Error while checking if the main or master branch exists. Are you sure it does exists?") 93 | } 94 | return branchName 95 | } -------------------------------------------------------------------------------- /src/main/resources/META-INF/gradle-plugins/com.prof18.kmp.fatframework.cocoa.properties: -------------------------------------------------------------------------------- 1 | implementationClass=com.prof18.kmp.fatframework.cocoa.KMPFatFrameworkCocoaPlugin 2 | -------------------------------------------------------------------------------- /src/main/resources/template/Framework.podspec.template: -------------------------------------------------------------------------------- 1 | Pod::Spec.new do |s| 2 | s.name = "$name" 3 | s.version = "$version" 4 | s.summary = "$summary" 5 | s.homepage = "$homepage" 6 | s.license = "$license" 7 | s.author = { $authors } 8 | s.vendored_frameworks = '$frameworkName' 9 | s.source = { :git => "$gitUrl", :tag => "#{s.version}" } 10 | s.exclude_files = "Classes/Exclude" 11 | end -------------------------------------------------------------------------------- /src/test/kotlin/com/prof18/kmp/fatframework/cocoa/task/FatFrameworkTasksWithoutFieldsTest.kt: -------------------------------------------------------------------------------- 1 | package com.prof18.kmp.fatframework.cocoa.task 2 | 3 | import com.google.common.truth.Truth.assertThat 4 | import com.prof18.kmp.fatframework.cocoa.data.PluginConfigErrorMessages 5 | import com.prof18.kmp.fatframework.cocoa.task.fatframework.BUILD_DEBUG_FAT_FRAMEWORK_TASK_NAME 6 | import com.prof18.kmp.fatframework.cocoa.testutils.TestUtils 7 | import org.gradle.testkit.runner.GradleRunner 8 | import org.junit.After 9 | import org.junit.Before 10 | import org.junit.Test 11 | import java.io.File 12 | 13 | class FatFrameworkTasksWithoutFieldsTest { 14 | 15 | private lateinit var testProject: File 16 | private lateinit var buildGradleFile: File 17 | private lateinit var gradleFileStringBuilder: StringBuilder 18 | 19 | @Before 20 | fun setup() { 21 | val testProjectName = "test-project" 22 | testProject = File("src/test/resources/$testProjectName") 23 | buildGradleFile = File("src/test/resources/$testProjectName/build.gradle.kts") 24 | 25 | gradleFileStringBuilder = StringBuilder() 26 | gradleFileStringBuilder.append(TestUtils.baseGradleFile) 27 | } 28 | 29 | @After 30 | fun cleanUp() { 31 | buildGradleFile.deleteRecursively() 32 | File("${testProject.path}/build").deleteRecursively() 33 | File("${testProject.path}/.gradle").deleteRecursively() 34 | } 35 | 36 | @Test 37 | fun `task returns error when fat framework name is not present`() { 38 | val pluginConfig = """ 39 | fatFrameworkCocoaConfig { 40 | } 41 | """.trimIndent() 42 | 43 | gradleFileStringBuilder.append("\n") 44 | gradleFileStringBuilder.append(pluginConfig) 45 | buildGradleFile.writeText(gradleFileStringBuilder.toString()) 46 | 47 | val runner = GradleRunner.create() 48 | .withProjectDir(testProject) 49 | .withPluginClasspath() 50 | 51 | val result = runner 52 | .withArguments(BUILD_DEBUG_FAT_FRAMEWORK_TASK_NAME, "--stacktrace") 53 | .buildAndFail() 54 | 55 | assertThat(result.output) 56 | .contains(PluginConfigErrorMessages.FRAMEWORK_NAME_NOT_PRESENT_MESSAGE) 57 | 58 | } 59 | 60 | @Test 61 | fun `task return error when output path is not present`() { 62 | 63 | val pluginConfig = """ 64 | fatFrameworkCocoaConfig { 65 | frameworkName = "LibraryName" 66 | } 67 | """.trimIndent() 68 | 69 | gradleFileStringBuilder.append("\n") 70 | gradleFileStringBuilder.append(pluginConfig) 71 | buildGradleFile.writeText(gradleFileStringBuilder.toString()) 72 | 73 | val runner = GradleRunner.create() 74 | .withProjectDir(testProject) 75 | .withPluginClasspath() 76 | 77 | val result = runner 78 | .withArguments(BUILD_DEBUG_FAT_FRAMEWORK_TASK_NAME, "--stacktrace") 79 | .buildAndFail() 80 | 81 | assertThat(result.output) 82 | .contains(PluginConfigErrorMessages.OUTPUT_PATH_NOT_PRESENT_MESSAGE) 83 | 84 | } 85 | 86 | @Test 87 | fun `task return error when version name is not present`() { 88 | 89 | val pluginConfig = """ 90 | fatFrameworkCocoaConfig { 91 | frameworkName = "LibraryName" 92 | outputPath = "${testProject.path}/../test-dest" 93 | } 94 | """.trimIndent() 95 | 96 | gradleFileStringBuilder.append("\n") 97 | gradleFileStringBuilder.append(pluginConfig) 98 | buildGradleFile.writeText(gradleFileStringBuilder.toString()) 99 | 100 | val runner = GradleRunner.create() 101 | .withProjectDir(testProject) 102 | .withPluginClasspath() 103 | 104 | val result = runner 105 | .withArguments(BUILD_DEBUG_FAT_FRAMEWORK_TASK_NAME, "--stacktrace") 106 | .buildAndFail() 107 | 108 | assertThat(result.output) 109 | .contains(PluginConfigErrorMessages.VERSION_NAME_NOT_PRESENT_MESSAGE) 110 | 111 | } 112 | } -------------------------------------------------------------------------------- /src/test/kotlin/com/prof18/kmp/fatframework/cocoa/task/GenerateCocoaPodTaskWithoutFieldsTest.kt: -------------------------------------------------------------------------------- 1 | package com.prof18.kmp.fatframework.cocoa.task 2 | 3 | import com.google.common.truth.Truth 4 | import com.prof18.kmp.fatframework.cocoa.data.PluginConfigErrorMessages 5 | import com.prof18.kmp.fatframework.cocoa.testutils.TestUtils 6 | import org.gradle.testkit.runner.GradleRunner 7 | import org.junit.After 8 | import org.junit.Before 9 | import org.junit.Test 10 | import java.io.File 11 | 12 | class GenerateCocoaPodTaskWithoutFieldsTest { 13 | 14 | private lateinit var testProject: File 15 | private lateinit var buildGradleFile: File 16 | private lateinit var gradleFileStringBuilder: StringBuilder 17 | 18 | @Before 19 | fun setup() { 20 | val testProjectName = "test-project" 21 | testProject = File("src/test/resources/$testProjectName") 22 | buildGradleFile = File("src/test/resources/$testProjectName/build.gradle.kts") 23 | 24 | gradleFileStringBuilder = StringBuilder() 25 | gradleFileStringBuilder.append(TestUtils.baseGradleFile) 26 | } 27 | 28 | @After 29 | fun cleanUp() { 30 | buildGradleFile.deleteRecursively() 31 | } 32 | 33 | @Test 34 | fun `generate cocoa repo returns error when fat framework name is not present`() { 35 | val pluginConfig = """ 36 | fatFrameworkCocoaConfig { 37 | } 38 | """.trimIndent() 39 | 40 | gradleFileStringBuilder.append("\n") 41 | gradleFileStringBuilder.append(pluginConfig) 42 | buildGradleFile.writeText(gradleFileStringBuilder.toString()) 43 | 44 | val runner = GradleRunner.create() 45 | .withProjectDir(testProject) 46 | .withPluginClasspath() 47 | 48 | val result = runner 49 | .withArguments(GENERATE_COCOA_POD_TASK_NAME, "--stacktrace") 50 | .buildAndFail() 51 | 52 | Truth.assertThat(result.output) 53 | .contains(PluginConfigErrorMessages.FRAMEWORK_NAME_NOT_PRESENT_MESSAGE) 54 | 55 | } 56 | 57 | @Test 58 | fun `generate cocoa repo return error when output path is not present`() { 59 | 60 | val pluginConfig = """ 61 | fatFrameworkCocoaConfig { 62 | frameworkName = "LibraryName" 63 | } 64 | """.trimIndent() 65 | 66 | gradleFileStringBuilder.append("\n") 67 | gradleFileStringBuilder.append(pluginConfig) 68 | buildGradleFile.writeText(gradleFileStringBuilder.toString()) 69 | 70 | val runner = GradleRunner.create() 71 | .withProjectDir(testProject) 72 | .withPluginClasspath() 73 | 74 | val result = runner 75 | .withArguments(GENERATE_COCOA_POD_TASK_NAME, "--stacktrace") 76 | .buildAndFail() 77 | 78 | Truth.assertThat(result.output) 79 | .contains(PluginConfigErrorMessages.OUTPUT_PATH_NOT_PRESENT_MESSAGE) 80 | 81 | } 82 | 83 | @Test 84 | fun `generate cocoa repo return error when version name is not present`() { 85 | 86 | val pluginConfig = """ 87 | fatFrameworkCocoaConfig { 88 | frameworkName = "LibraryName" 89 | outputPath = "${testProject.path}/../test-dest" 90 | } 91 | """.trimIndent() 92 | 93 | gradleFileStringBuilder.append("\n") 94 | gradleFileStringBuilder.append(pluginConfig) 95 | buildGradleFile.writeText(gradleFileStringBuilder.toString()) 96 | 97 | val runner = GradleRunner.create() 98 | .withProjectDir(testProject) 99 | .withPluginClasspath() 100 | 101 | val result = runner 102 | .withArguments(GENERATE_COCOA_POD_TASK_NAME, "--stacktrace") 103 | .buildAndFail() 104 | 105 | Truth.assertThat(result.output) 106 | .contains(PluginConfigErrorMessages.VERSION_NAME_NOT_PRESENT_MESSAGE) 107 | 108 | } 109 | } -------------------------------------------------------------------------------- /src/test/kotlin/com/prof18/kmp/fatframework/cocoa/testutils/TestUtils.kt: -------------------------------------------------------------------------------- 1 | package com.prof18.kmp.fatframework.cocoa.testutils 2 | 3 | object TestUtils { 4 | 5 | val baseGradleFile = """ 6 | plugins { 7 | kotlin("multiplatform") version "1.5.20" 8 | id("com.prof18.kmp.fatframework.cocoa") 9 | } 10 | 11 | repositories { 12 | mavenCentral() 13 | jcenter() 14 | } 15 | 16 | kotlin { 17 | ios() { 18 | binaries.framework("aronne") 19 | } 20 | sourceSets { 21 | val commonMain by getting 22 | val iosMain by getting 23 | } 24 | } 25 | """.trimIndent() 26 | 27 | } 28 | 29 | 30 | /* 31 | 32 | 33 | fatFrameworkCocoaConfig { 34 | frameworkName = "LibraryName" 35 | outputPath = "$rootDir/../test-dest" 36 | namePrefix = "LibraryName" 37 | versionName = "1.2-SNAPSHOT" 38 | 39 | cocoaPodRepoInfo { 40 | summary = "This is a test KMP framework" 41 | homepage = "https://github.com/prof18/ccoca-repo-test" 42 | license = "Apache" 43 | authors = "\"Revelop Team\" => \"team@uniwhere.com\"" 44 | gitUrl = "git@github.com:prof18/ccoca-repo-test.git" 45 | } 46 | 47 | } 48 | 49 | */ -------------------------------------------------------------------------------- /src/test/resources/test-project/settings.gradle: -------------------------------------------------------------------------------- 1 | pluginManagement { 2 | resolutionStrategy { 3 | eachPlugin { 4 | if (requested.id.id == "kotlin-multiplatform") { 5 | useModule("org.jetbrains.kotlin:kotlin-gradle-plugin:${'$'}{requested.version}") 6 | } 7 | } 8 | } 9 | 10 | repositories { 11 | mavenCentral() 12 | jcenter() 13 | maven { url 'https://plugins.gradle.org/m2/' } 14 | } 15 | } -------------------------------------------------------------------------------- /src/test/resources/test-project/src/commonMain/kotlin/com/prof18/example/Greeting.kt: -------------------------------------------------------------------------------- 1 | package com.prof18.example 2 | 3 | 4 | class Greeting { 5 | fun greeting(): String { 6 | return "Hello, World!" 7 | } 8 | } 9 | --------------------------------------------------------------------------------