Created
November 29, 2019 08:26
-
-
Save StefMa/6c3e512b995c45daf535e4fd59805765 to your computer and use it in GitHub Desktop.
Apple Framework publishing via Gradle and the jfrog CLI
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class FrameworkPlugin : Plugin<Project> { | |
override fun apply(project: Project): Unit = with(project) { | |
val zipFramework = tasks.register("zipFatFramework", Zip::class.java) { | |
it.dependsOn(tasks.named("releaseFatFramework")) | |
it.from("$buildDir/fat-framework") | |
it.archiveFileName.set("SomeFramework.framework.zip") | |
it.destinationDirectory.set(file("$buildDir/fat-framework-zip")) | |
} | |
tasks.register("publishFatFrameworkToArtifactory", Exec::class.java) { | |
it.dependsOn(tasks.named("releaseFatFramework"), zipFramework) | |
it.commandLine("jfrog", "rt", "u", "$buildDir/fat-framework-zip/SomeFramework.framework.zip", "maven-playground/$groupAsPath/SomeFramework/$version/") | |
} | |
val downloadAndModifyJson = tasks.register("downloadAndModifyFrameworkJson", Exec::class.java) { | |
it.commandLine("jfrog", "rt", "dl", "maven-playground/$groupAsPath/SomeFramework/SomeFramework.json", "$buildDir/") | |
it.doLast { | |
file("$buildDir/$groupAsPath/SomeFramework/SomeFramework.json").apply { | |
if (exists()) { | |
val currentContent = readText() | |
if(currentContent.contains("\"$version\"")) return@apply | |
val replace = currentContent.replace("{", "").replace("}", "") | |
val newContent = "$replace, \"$version\" : \"https://artifactory.url/maven-playground/$groupAsPath/SomeFramework/$version/SomeFramework.framework.zip\"" | |
writeText("{ $newContent }") | |
} else { | |
parentFile.mkdirs() | |
createNewFile() | |
writeText(""" | |
{ "$version" : "https://artifactory.url/maven-playground/$groupAsPath/SomeFramework/$version/SomeFramework.framework.zip" } | |
""".trimIndent()) | |
} | |
} | |
} | |
} | |
tasks.register("publishFrameworkJsonToArtifactory", Exec::class.java) { | |
it.dependsOn(downloadAndModifyJson) | |
it.commandLine("jfrog", "rt", "u", "$buildDir/$groupAsPath/SomeFramework/SomeFramework.json", "maven-playground/$groupAsPath/SomeFramework/") | |
} | |
} | |
private val Project.groupAsPath | |
get() = (group as String).replace(".", "/") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment