Skip to content

Commit

Permalink
Support for android source-set layout version 2 (fixes #53)
Browse files Browse the repository at this point in the history
  • Loading branch information
SalomonBrys committed May 7, 2023
1 parent 212386d commit 699a2c4
Show file tree
Hide file tree
Showing 11 changed files with 145 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ jobs:
working-directory: tests-projects/tests-android-old
run: ../../gradlew --stacktrace check
shell: bash
- name: Check plugin with Android new layout (ubuntu)
if: matrix.os == 'ubuntu-latest'
working-directory: tests-projects/tests-android-new
run: ../../gradlew --stacktrace check
shell: bash
- name: Upload (macos / windows)
if: matrix.os != 'ubuntu-latest'
run: ./gradlew --stacktrace hostOnlyPublish -Porg.kodein.sonatype.repositoryId=${{ needs.create-staging-repository.outputs.repository_id }}
Expand Down
5 changes: 5 additions & 0 deletions .github/workflows/snapshot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ jobs:
working-directory: tests-projects/tests-android-old
run: ../../gradlew --stacktrace check
shell: bash
- name: Check plugin with Android new layout (ubuntu)
if: matrix.os == 'ubuntu-latest'
working-directory: tests-projects/tests-android-new
run: ../../gradlew --stacktrace check
shell: bash
- name: Upload (macos / windows)
if: matrix.os != 'ubuntu-latest'
run: ./gradlew --stacktrace hostOnlyPublish -PgitRef=${{ github.ref }} -Psnapshot=true
Expand Down
5 changes: 5 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,8 @@ jobs:
working-directory: tests-projects/tests-android-old
run: ../../gradlew --stacktrace check
shell: bash
- name: Check plugin with Android new layout (ubuntu)
if: matrix.os == 'ubuntu-latest'
working-directory: tests-projects/tests-android-new
run: ../../gradlew --stacktrace check
shell: bash
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,10 @@ class MocKMPGradlePlugin : Plugin<Project> {
// Adding KSP JVM result to COMMON source set
when (jvmTarget.preset!!.name) {
"jvm" -> commonTest.kotlin.srcDir("${project.buildDir}/generated/ksp/${jvmTarget.name}/${jvmTarget.name}Test/kotlin")
"android" -> commonTest.kotlin.srcDir("${project.buildDir}/generated/ksp/${jvmTarget.name}/${jvmTarget.name}DebugUnitTest/kotlin")
"android" -> {
commonTest.kotlin.srcDir("${project.buildDir}/generated/ksp/${jvmTarget.name}/${jvmTarget.name}DebugUnitTest/kotlin")
commonTest.kotlin.srcDir("${project.buildDir}/generated/ksp/${jvmTarget.name}/${jvmTarget.name}UnitTestDebug/kotlin")
}
}

configureKsp(project, ext)
Expand Down
68 changes: 68 additions & 0 deletions tests-projects/tests-android-new/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
plugins {
alias(kodeinGlobals.plugins.android.library)
alias(kodeinGlobals.plugins.kotlin.multiplatform)
id("org.kodein.mock.mockmp")
}

repositories {
mavenLocal()
google()
mavenCentral()
}

android {
namespace = "org.kodein.mock.tests_android"
compileSdk = 32

defaultConfig {
minSdk = 21
targetSdk = 32
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}

compileOptions {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}
}

kotlin {
android()
ios()

sourceSets {
val commonMain by getting {
kotlin.srcDir("$rootDir/../../tests/tests-junit4/src/commonMain/kotlin")
dependencies {
implementation(libs.datetime)
}
}
val commonTest by getting {
kotlin.srcDir("$rootDir/../../tests/tests-junit4/src/commonTest/kotlin")
dependencies {
implementation(libs.coroutines.test)
}
}

val androidUnitTest by getting {
dependencies {
implementation(kodeinGlobals.kotlin.test.junit)
}
}
}
}

mockmp {
usesHelper = true
}

// Showing tests in Gradle command line
afterEvaluate {
tasks.withType<AbstractTestTask> {
testLogging {
events("passed", "skipped", "failed", "standard_out", "standard_error")
showExceptions = true
showStackTraces = true
}
}
}
5 changes: 5 additions & 0 deletions tests-projects/tests-android-new/gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8

android.useAndroidX=true
android.nonTransitiveRClass=true
kotlin.mpp.androidSourceSetLayoutVersion=2
44 changes: 44 additions & 0 deletions tests-projects/tests-android-new/settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
pluginManagement {
repositories {
mavenLocal()
gradlePluginPortal()
google()
mavenCentral()
}

resolutionStrategy.eachPlugin {
if (target.id.id == "org.kodein.mock.mockmp") {
val rx = Regex("version = \"(.+)\"")
val match = file("$rootDir/../../build.gradle.kts").useLines { lines ->
lines.mapNotNull { rx.matchEntire(it.trim()) }.firstOrNull()
} ?: error("Could not find parent project version")
val mockmpVersion = match.groupValues[1]

useModule("org.kodein.mock:mockmp-gradle-plugin:$mockmpVersion")
}
}
}

@Suppress("UnstableApiUsage")
dependencyResolutionManagement {
repositories {
mavenLocal()
mavenCentral()
maven(url = "https://raw.githubusercontent.com/kosi-libs/kodein-internal-gradle-plugin/mvn-repo")
}

versionCatalogs {
create("kodeinGlobals") {
val rx = Regex("classpath\\(\"org.kodein.internal.gradle:kodein-internal-gradle-settings:(.+)\"\\)")
val match = file("$rootDir/../../settings.gradle.kts").useLines { lines ->
lines.mapNotNull { rx.matchEntire(it.trim()) }.firstOrNull()
} ?: error("Could not find parent KIGP version")
val kigpVersion = match.groupValues[1]

from("org.kodein.internal.gradle:kodein-internal-gradle-version-catalog:$kigpVersion")
}
create("libs") {
from(files("../../gradle/libs.versions.toml"))
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

<application android:icon="@mipmap/ic_launcher" />

</manifest>
Binary file not shown.
4 changes: 2 additions & 2 deletions tests-projects/tests-android-old/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ android {
}

compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}
}

Expand Down
1 change: 1 addition & 0 deletions tests-projects/tests-android-old/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8

android.useAndroidX=true
android.nonTransitiveRClass=true
kotlin.mpp.androidSourceSetLayoutVersion1.nowarn=true

0 comments on commit 699a2c4

Please sign in to comment.