diff --git a/.github/workflows/code-quality.yml b/.github/workflows/code-quality.yml index 3c6b1dd..001ee3f 100644 --- a/.github/workflows/code-quality.yml +++ b/.github/workflows/code-quality.yml @@ -31,7 +31,7 @@ jobs: continue-on-error: true - name: Check for compilation warnings - run: ./gradlew compileKotlin --no-daemon -Dorg.gradle.warning.mode=all + run: ./gradlew compileDebugKotlin --no-daemon -Dorg.gradle.warning.mode=all - name: Run dependency check run: ./gradlew dependencyCheck --no-daemon diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index f120df7..befbae3 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -2,14 +2,18 @@ # https://docs.gradle.org/current/userguide/platforms.html#sub::toml-dependencies-format [versions] +android-gradle-plugin = "8.7.3" commons-math3 = "3.6.1" guava = "33.4.6-jre" junit-jupiter-engine = "5.12.1" +kotlin = "2.2.20" [libraries] -commons-math3 = { module = "org.apache.commons:commons-math3", version.ref = "commons-math3" } +commons-math = { module = "org.apache.commons:commons-math3", version.ref = "commons-math3" } guava = { module = "com.google.guava:guava", version.ref = "guava" } junit-jupiter-engine = { module = "org.junit.jupiter:junit-jupiter-engine", version.ref = "junit-jupiter-engine" } [plugins] -kotlin-jvm = { id = "org.jetbrains.kotlin.jvm", version = "2.2.20" } +android-library = { id = "com.android.library", version.ref = "android-gradle-plugin" } +kotlin-android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" } +kotlin-jvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" } diff --git a/lib/build.gradle.kts b/lib/build.gradle.kts index f102b87..04c6320 100644 --- a/lib/build.gradle.kts +++ b/lib/build.gradle.kts @@ -6,21 +6,63 @@ */ plugins { - // Apply the org.jetbrains.kotlin.jvm Plugin to add support for Kotlin. - alias(libs.plugins.kotlin.jvm) - - // Apply the java-library plugin for API and implementation separation. - `java-library` + alias(libs.plugins.android.library) + alias(libs.plugins.kotlin.android) id("com.squareup.wire") version "5.4.0" // JaCoCo for code coverage jacoco + + `maven-publish` +} + +android { + namespace = "org.flex" + compileSdk = 35 + + defaultConfig { + minSdk = 21 + + testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" + } + + testOptions { + unitTests.all { + it.useJUnitPlatform() + } + } + + buildTypes { + release { + isMinifyEnabled = false + proguardFiles( + getDefaultProguardFile("proguard-android-optimize.txt"), + "proguard-rules.pro" + ) + } + } + compileOptions { + sourceCompatibility = JavaVersion.VERSION_21 + targetCompatibility = JavaVersion.VERSION_21 + } + + kotlin { + compilerOptions { + jvmTarget.set(org.jetbrains.kotlin.gradle.dsl.JvmTarget.JVM_21) + } + } + + publishing { + singleVariant("release") { + withSourcesJar() + } + } } -repositories { - // Use Maven Central for resolving dependencies. - mavenCentral() +// Apply a specific Java toolchain to ensure we use Java 21 +kotlin { + jvmToolchain(21) } wire { @@ -39,6 +81,7 @@ val coroutinesVersion = "1.7.3" dependencies { // Kotlin Coroutines - Android compatible api("org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutinesVersion") + api("org.jetbrains.kotlinx:kotlinx-coroutines-android:$coroutinesVersion") testImplementation("org.jetbrains.kotlinx:kotlinx-coroutines-test:$coroutinesVersion") // Use the Kotlin Test integration. @@ -53,7 +96,7 @@ dependencies { testImplementation("io.mockk:mockk:1.13.8") // This dependency is exported to consumers, that is to say found on their compile classpath. - api(libs.commons.math3) + api(libs.commons.math) // This dependency is used internally, and not exposed to consumers on their own compile classpath. implementation(libs.guava) @@ -63,40 +106,41 @@ dependencies { implementation("com.squareup.wire:wire-grpc-client:5.4.0") } -// Apply a specific Java toolchain to ease working on different environments. -java { - toolchain { - languageVersion = JavaLanguageVersion.of(21) - } -} - -tasks.named("test") { - // Use JUnit Platform for unit tests. - useJUnitPlatform() - - // Generate JaCoCo coverage data - finalizedBy(tasks.jacocoTestReport) -} - // Configure JaCoCo code coverage jacoco { - toolVersion = "0.8.10" + toolVersion = "0.8.12" } -tasks.jacocoTestReport { - dependsOn(tasks.test) +tasks.register("jacocoTestReport") { + dependsOn(tasks.named("testDebugUnitTest")) + dependsOn(tasks.named("testReleaseUnitTest")) reports { - xml.required = true - html.required = true - csv.required = false + xml.required.set(true) + html.required.set(true) } - classDirectories.setFrom(files( - fileTree("${layout.buildDirectory.get()}/classes/kotlin/main") { - exclude("**/*Test*") + val debugTree = fileTree(layout.buildDirectory.dir("tmp/kotlin-classes/debug")) + val mainSrc = "src/main/kotlin" + + sourceDirectories.setFrom(files(mainSrc)) + classDirectories.setFrom(debugTree) + executionData.setFrom(fileTree(layout.buildDirectory.dir("jacoco")).include("*.exec")) +} + +publishing { + publications { + register("release") { + groupId = "org.flex" + artifactId = "flexible" + version = "0.0.1" + + afterEvaluate { + from(components["release"]) + } } - )) - sourceDirectories.setFrom(files("src/main/kotlin")) - executionData.setFrom(files("${layout.buildDirectory.get()}/jacoco/test.exec")) + } + repositories { + mavenLocal() + } } diff --git a/lib/src/main/AndroidManifest.xml b/lib/src/main/AndroidManifest.xml new file mode 100644 index 0000000..8072ee0 --- /dev/null +++ b/lib/src/main/AndroidManifest.xml @@ -0,0 +1,2 @@ + + diff --git a/lib/src/main/kotlin/org/flex/FlexClient.kt b/lib/src/main/kotlin/org/flex/FlexClient.kt index e497b9a..f843546 100644 --- a/lib/src/main/kotlin/org/flex/FlexClient.kt +++ b/lib/src/main/kotlin/org/flex/FlexClient.kt @@ -558,7 +558,7 @@ abstract class FlexClient( } private fun updateStats(update: (SessionStats) -> SessionStats) { - _stats.updateAndGet(update) + _stats.set(update(_stats.get())) listener.onStatsUpdated(_stats.get()) } } diff --git a/lib/src/main/proto/org/flex/tensor.proto b/lib/src/main/proto/org/flex/tensor.proto index eedf36b..c5a768f 100644 --- a/lib/src/main/proto/org/flex/tensor.proto +++ b/lib/src/main/proto/org/flex/tensor.proto @@ -1,7 +1,8 @@ syntax = "proto3"; +package flexible; -package org.flex.flexible; - +option java_package = "org.flex.flexible"; +option java_multiple_files = true; message Tensor { repeated int32 shape = 1; bytes data = 2; diff --git a/lib/src/main/proto/org/flex/transport.proto b/lib/src/main/proto/org/flex/transport.proto index ce48274..900c9a3 100644 --- a/lib/src/main/proto/org/flex/transport.proto +++ b/lib/src/main/proto/org/flex/transport.proto @@ -1,6 +1,10 @@ syntax = "proto3"; +package flexible; + +// This defines where the generated Java classes will live +option java_package = "org.flex.flexible"; +option java_multiple_files = true; -package org.flex.flexible; import "org/flex/tensor.proto"; diff --git a/settings.gradle.kts b/settings.gradle.kts index a9e0463..150106d 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -5,6 +5,21 @@ * For more detailed information on multi-project builds, please refer to https://docs.gradle.org/9.2.0/userguide/multi_project_builds.html in the Gradle documentation. */ +pluginManagement { + repositories { + google() + mavenCentral() + gradlePluginPortal() + } +} +dependencyResolutionManagement { + repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS) + repositories { + google() + mavenCentral() + } +} + plugins { // Apply the foojay-resolver plugin to allow automatic download of JDKs id("org.gradle.toolchains.foojay-resolver-convention") version "1.0.0"