-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
create support of android library for multiplatform and just android …
…library, and updated logic faced with defaults
- Loading branch information
Showing
7 changed files
with
100 additions
and
7 deletions.
There are no files selected for viewing
37 changes: 37 additions & 0 deletions
37
src/main/kotlin/com/sliderzxc/gradle/android/SetupAndroid.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package com.sliderzxc.gradle.android | ||
|
||
import com.android.build.gradle.BaseExtension | ||
import com.sliderzxc.gradle.android.config.AndroidConfig | ||
import com.sliderzxc.gradle.defaults.requireDefaults | ||
import org.gradle.api.JavaVersion | ||
import org.gradle.api.Project | ||
import org.gradle.kotlin.dsl.configure | ||
import org.gradle.kotlin.dsl.withType | ||
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile | ||
|
||
fun Project.setupAndroidLibrary( | ||
config: AndroidConfig = requireDefaults() | ||
) = setupAndroidCommon(config) | ||
|
||
internal fun Project.setupAndroidCommon(config: AndroidConfig) { | ||
extensions.configure<BaseExtension> { | ||
namespace = config.namespace | ||
compileSdkVersion(config.compileSdkVersion) | ||
|
||
defaultConfig { | ||
minSdk = config.minSdkVersion | ||
targetSdk = config.targetSdkVersion | ||
} | ||
|
||
compileOptions { | ||
sourceCompatibility(JavaVersion.VERSION_11) | ||
targetCompatibility(JavaVersion.VERSION_11) | ||
} | ||
} | ||
|
||
tasks.withType<KotlinCompile> { | ||
kotlinOptions { | ||
jvmTarget = "11" | ||
} | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
src/main/kotlin/com/sliderzxc/gradle/android/config/AndroidConfig.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.sliderzxc.gradle.android.config | ||
|
||
data class AndroidConfig( | ||
val minSdkVersion: Int, | ||
val compileSdkVersion: Int, | ||
val targetSdkVersion: Int, | ||
val namespace: String | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
src/main/kotlin/com/sliderzxc/gradle/defaults/SetupDefaults.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package com.sliderzxc.gradle.defaults | ||
|
||
import com.sliderzxc.gradle.android.config.AndroidConfig | ||
import com.sliderzxc.gradle.multiplatform.config.MultiplatformConfig | ||
import com.sliderzxc.gradle.multiplatform.platforms.Platform | ||
import org.gradle.api.Project | ||
import org.gradle.kotlin.dsl.extra | ||
|
||
fun Project.setupDefaults( | ||
multiplatformConfig: MultiplatformConfig? = null, | ||
androidConfig: AndroidConfig? = null, | ||
) { | ||
extra.set( | ||
DEFAULTS_KEY, | ||
listOfNotNull( | ||
androidConfig, | ||
multiplatformConfig | ||
) | ||
) | ||
} | ||
|
||
fun setupDef( | ||
multiplatformConfig: MultiplatformConfig? = null, | ||
androidConfig: AndroidConfig? = null, | ||
) { | ||
println(multiplatformConfig?.platforms?.joinToString(" | ")) | ||
} | ||
|
||
fun main() { | ||
setupDef( | ||
multiplatformConfig = MultiplatformConfig( | ||
setOf(Platform.Android, Platform.Js, Platform.Android) | ||
) | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
src/main/kotlin/com/sliderzxc/gradle/multiplatform/config/MultiplatformConfig.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.sliderzxc.gradle.multiplatform.config | ||
|
||
import com.sliderzxc.gradle.multiplatform.platforms.Platform | ||
|
||
data class MultiplatformConfig( | ||
val platforms: Set<Platform> | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters