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"
}
}
27 changes: 7 additions & 20 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,22 +1,9 @@
org.gradle.jvmargs='-Dfile.encoding=UTF-8'
kotlin.code.style=official
Copy link
Member

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)
systemProp.org.gradle.internal.publish.checksums.insecure=true

GROUP=com.squareup.logcat
VERSION_NAME=1.0-SNAPSHOT

POM_DESCRIPTION=A tiny Kotlin API for cheap logging on top of Android's normal Log class.

POM_URL=https://github.com/square/logcat/
POM_SCM_URL=https://github.com/square/logcat/
POM_SCM_CONNECTION=scm:git:git://github.com/square/logcat.git
POM_SCM_DEV_CONNECTION=scm:git:ssh://git@github.com/square/logcat.git

POM_LICENCE_NAME=The Apache Software License, Version 2.0
POM_LICENCE_URL=http://www.apache.org/licenses/LICENSE-2.0.txt
POM_LICENCE_DIST=repo

POM_DEVELOPER_ID=square
POM_DEVELOPER_NAME=Square, Inc.
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