Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial KMP Restructure #15

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
143 changes: 91 additions & 52 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,70 +1,109 @@
import kotlinx.validation.ApiValidationExtension
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import org.jlleitschuh.gradle.ktlint.KtlintExtension
import org.jlleitschuh.gradle.ktlint.reporter.ReporterType
plugins {
kotlin("multiplatform") version "1.6.20"
id("com.android.library")
}

println("Building with Kotlin compiler version ${Versions.KotlinCompiler}")
group = "logcatx"
version = "1.0-SNAPSHOT"

buildscript {
repositories {
repositories {
mavenCentral()
gradlePluginPortal()
google()
// For binary compatibility validator.
maven { url = uri("https://kotlin.bintray.com/kotlinx") }
}

dependencies {
classpath(Dependencies.Build.Android)
classpath(Dependencies.Build.MavenPublish)
classpath(Dependencies.Build.Kotlin)
classpath(Dependencies.Build.Ktlint)
classpath(Dependencies.Build.BinaryCompatibility)
}
}

// We use JetBrain's Kotlin Binary Compatibility Validator to track changes to our public binary
// APIs.
// When making a change that results in a public ABI change, the apiCheck task will fail. When this
// happens, run ./gradlew apiDump to generate updated *.api files, and add those to your commit.
// See https://github.com/Kotlin/binary-compatibility-validator
apply(plugin = "binary-compatibility-validator")
kotlin {
jvm {
compilations.all {
kotlinOptions.jvmTarget = "1.8"
}
// withJava()
// testRuns["test"].executionTask.configure {
// useJUnitPlatform()
// }
}
js(IR) {
browser {
commonWebpackConfig {
cssSupport.enabled = true
}
}
binaries.executable()
}
macosX64("native") {
binaries {
sharedLib {
baseName = "logcat" // on Linux and macOS
// baseName = "libnative" // on Windows
frenziedherring marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
val hostOs = System.getProperty("os.name")
val isMingwX64 = hostOs.startsWith("Windows")
val nativeTarget = when {
hostOs == "Mac OS X" -> macosX64("native")
hostOs == "Linux" -> linuxX64("native")
isMingwX64 -> mingwX64("native")
else -> throw GradleException("Host OS is not supported in Kotlin/Native.")
}

extensions.configure<ApiValidationExtension> {
// Ignore all sample projects, since they're not part of our API.
// Only leaf project name is valid configuration, and every project must be individually ignored.
// See https://github.com/Kotlin/binary-compatibility-validator/issues/3
ignoredProjects = mutableSetOf(
"sample"
)
android()
sourceSets {
val commonMain by getting {
dependencies {
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.1")
}
}
val commonTest by getting {
dependencies {
implementation(kotlin("test"))
}
}
val jvmMain by getting
val jvmTest by getting {
dependencies {
implementation("com.google.truth:truth:1.1.3")
}
}
val jsMain by getting
val jsTest by getting
val nativeMain by getting
val nativeTest by getting
val androidMain by getting {
dependencies {
implementation("com.google.android.material:material:1.2.1")
}
}
val androidTest by getting {
dependencies {
implementation("junit:junit:4.13")
}
}
}
}

val isRunningLocally get() = (System.getenv("CI") ?: "false").toBoolean()
android {
compileSdkVersion(30)
sourceSets["main"].manifest.srcFile("src/androidMain/AndroidManifest.xml")

subprojects {
repositories {
google()
mavenCentral()
compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}

apply(plugin = "org.jlleitschuh.gradle.ktlint")

tasks.withType<KotlinCompile> {
kotlinOptions {
// Allow warnings when running from IDE, makes it easier to experiment.
allWarningsAsErrors = !isRunningLocally
defaultConfig {
minSdkVersion(14)
targetSdkVersion(30)
versionCode = 1
versionName = "1.0"
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}

jvmTarget = "1.8"
}
buildFeatures {
buildConfig = false
}

// Configuration documentation: https://github.com/JLLeitschuh/ktlint-gradle#configuration
configure<KtlintExtension> {
// Prints the name of failed rules.
verbose.set(true)
reporters {
// Default "plain" reporter is actually harder to read.
reporter(ReporterType.JSON)
}
testOptions {
execution = "ANDROIDX_TEST_ORCHESTRATOR"
}
}
8 changes: 7 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
org.gradle.jvmargs='-Dfile.encoding=UTF-8'
kotlin.code.style=official

Choose a reason for hiding this comment

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

Seems off-topic.

#kotlin.mpp.enableGranularSourceSetsMetadata=true
#kotlin.native.enableDependencyPropagation=false
kotlin.js.generate.executable.default=false
android.useAndroidX=true

# Required to publish to Nexus (see https://github.com/gradle/gradle/issues/11308)
Expand All @@ -20,3 +23,6 @@ POM_LICENCE_DIST=repo

POM_DEVELOPER_ID=square
POM_DEVELOPER_NAME=Square, Inc.
Copy link
Member

Choose a reason for hiding this comment

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

I'm a bit surprised you had to add all this, we've published releases just fine in the past, what's changed?

Copy link
Author

Choose a reason for hiding this comment

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

I used a skeleton KMP project to help get the Android source setup with the build files - this must have come over with it. I'll remove these extra lines.

I have no experience publishing an AAR, so I'll have to dig in to learn about the publishing process.

Copy link
Author

Choose a reason for hiding this comment

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

These have been removed and I was able to run the Android build and sample project on the emulator. The publishing plugin was re-added when I restructured in 3c402d1 so I think the AAR publishing should be OK now

POM_ARTIFACT_ID=logcat
POM_NAME=Logcat
POM_PACKAGING=aar
Empty file modified gradle/wrapper/gradle-wrapper.jar
100755 → 100644
Empty file.
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.1-bin.zip
frenziedherring marked this conversation as resolved.
Show resolved Hide resolved
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Loading