Skip to content

Instantly share code, notes, and snippets.

@petrukhnov
Created September 10, 2019 11:09
Show Gist options
  • Select an option

  • Save petrukhnov/92b9475ce2c8ac6aeb2b8450e9dc268c to your computer and use it in GitHub Desktop.

Select an option

Save petrukhnov/92b9475ce2c8ac6aeb2b8450e9dc268c to your computer and use it in GitHub Desktop.
Multiplatform Project (MPP) Kotlin 1.3.50 K/N iOS/jvm project template (+gradle5, junit5, release)
import org.jetbrains.kotlin.gradle.tasks.FatFrameworkTask
buildscript {
ext.kotlin_version = '1.3.50'
repositories {
mavenCentral()
google()
jcenter()
maven { url "https://dl.bintray.com/kotlin/kotlin-eap" }
maven { url 'https://dl.bintray.com/kotlin/kotlin-dev' }
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
plugins {
//kotlin MPP
id 'org.jetbrains.kotlin.multiplatform' version '1.3.50'
//cocoa pods required to assemble framework. 'cocoapods.podspec' gradle task is not used in this project.
//podspec is generated once, and usually don't change, except version, and included resources
id 'org.jetbrains.kotlin.native.cocoapods' version '1.3.50'
id 'idea'
//static code analyzer
id 'org.sonarqube' version '2.7.1'
//publish and release
id 'maven-publish'
id 'net.researchgate.release' version '2.8.1'
}
group 'com.ekahau.templateproject'
repositories {
mavenCentral()
maven { url "https://dl.bintray.com/kotlin/kotlin-dev" }
maven { url "https://dl.bintray.com/kotlin/kotlin-eap" }
}
kotlin {
/*
=== DEPENDENCIES ===
*/
sourceSets {
//lib contain only common, platform independent code
commonMain {
dependencies {
implementation 'org.jetbrains.kotlin:kotlin-stdlib'
implementation 'org.jetbrains.kotlin:kotlin-stdlib-common'
}
}
commonTest {
}
//because java have great tools for testing
jvmTest {
dependencies {
implementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk8'
implementation 'org.jetbrains.kotlin:kotlin-test-common'
implementation 'org.jetbrains.kotlin:kotlin-test-annotations-common'
//tests
implementation 'org.jetbrains.kotlin:kotlin-test'
implementation 'org.jetbrains.kotlin:kotlin-test-junit5'
implementation 'org.junit.jupiter:junit-jupiter-api:5.5.1'
implementation 'org.junit.jupiter:junit-jupiter-params:5.5.1'
implementation 'org.junit.jupiter:junit-jupiter-engine:5.5.1'
//logging
implementation 'io.github.microutils:kotlin-logging:1.7.6'
implementation 'ch.qos.logback:logback-classic:1.2.3'
implementation 'org.slf4j:slf4j-api:1.7.28'
}
}
} //sourceSets
/*
=== builds ===
*/
targets {
//jvm
fromPreset(presets.jvm, 'jvm')
//ios (most probably there is better way to do it with cocoapods plugin)
iosArm64("ios64")
iosX64("emulator")
configure([ios64, emulator]) {
binaries.framework('TemplateProject')
}
}
// Create a task building a fat framework.
task fatFramework(type: FatFrameworkTask) {
// The fat framework must have the same base name as the initial frameworks.
baseName = 'TemplateProject'
// The default destination directory is '<build directory>/fat-framework'.
final File frameworkDir = new File(buildDir, 'fat-framework')
destinationDir = frameworkDir
// Specify the frameworks to be merged.
from(
targets.ios64.binaries.getFramework("RELEASE"),
targets.emulator.binaries.getFramework("RELEASE")
)
doLast {
copyFrameworkExtraFiles
}
}
}
jvmTest {
useJUnitPlatform()
}
/*
copy extra files
fat-framework will have following structure:
TemplateProject.framework
Headers
TemplateProject.h
Modules
module.modulemap
info.plist
TemplateProject
TemplateProject.podspec
resources
somefiles
file.a
file.b
*/
task copyFrameworkExtraFiles {
dependsOn build
def targetDir = 'build/fat-framework'
/*
podspec is not changed, only version is updated
*/
copy {
from 'TemplateProject.podspec'
into targetDir
filter{ it.replaceAll('VERSION', version)}
}
copy {
from 'src/commonMain/resources'
into targetDir+'/resources'
}
}
tasks.build.dependsOn fatFramework
/*
=== publish jar to nexus ===
*/
publishing {
publications {
jvm {
artifactId "templateproject"
}
metadata {
}
}
repositories {
maven {
//destination and credentials
}
}
}
/*
=== publish framework to binary repository ===
*/
//upload iOs framework and podspec files to binary repository
task deployFramework {
//some code here depends on destination
}
/*
=== release lib for jvm and ios ===
if building artifact for jvm or iOS failed, then release reverted
On your CI:
./gradlew release -Prelease.useAutomaticVersion=true
*/
release {
beforeReleaseBuild.dependsOn allTests
//explicit git branch is required fore gradle debug
git {
requireBranch = '(master|\\d+\\.\\d+)'
}
afterReleaseBuild.dependsOn publish
afterReleaseBuild.dependsOn deployFramework
}
version=3.2.1-SNAPSHOT
enableFeaturePreview('GRADLE_METADATA')
rootProject.name = 'TemplateProject'
Pod::Spec.new do |s|
s.name = 'TemplateProject'
s.version = 'VERSION'
s.authors = {
'name1' => 'email1',
'name2' => 'email2'
}
s.license = 'Proprietary'
s.homepage = 'https://github.com/Ekahau/TemplateProject'
s.summary = 'Project description may appear here'
s.platform = :ios
s.ios.deployment_target = '11.0'
s.ios.vendored_frameworks = 'TemplateProject.framework'
s.source = {
:git => 'https://github.com/Ekahau/TemplateProject.git',
:tag => s.version
}
s.ios.resource_bundle = { 'TemplateProject' => 'resources/somefiles/*' }
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment