[Gradle] Migrate new-mpp-android from Groovy to Kotlin Script
This commit is contained in:
committed by
Space Team
parent
20bb6b0ea8
commit
b13b27a715
+90
-67
@@ -161,11 +161,10 @@ class KotlinAndroidMppIT : KGPBaseTest() {
|
|||||||
groupDir.deleteRecursively()
|
groupDir.deleteRecursively()
|
||||||
|
|
||||||
// Choose a single variant to publish, check that it's there:
|
// Choose a single variant to publish, check that it's there:
|
||||||
subProject("lib").buildGradle.appendText(
|
subProject("lib").buildGradleKts.appendText(
|
||||||
//language=Gradle
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
kotlin.android('androidLib').publishLibraryVariants = ['release']
|
kotlin.androidTarget("androidLib").publishLibraryVariants("release")
|
||||||
""".trimIndent()
|
""".trimIndent()
|
||||||
)
|
)
|
||||||
build("publish") {
|
build("publish") {
|
||||||
@@ -182,11 +181,10 @@ class KotlinAndroidMppIT : KGPBaseTest() {
|
|||||||
groupDir.deleteRecursively()
|
groupDir.deleteRecursively()
|
||||||
|
|
||||||
// Enable publishing for all Android variants:
|
// Enable publishing for all Android variants:
|
||||||
subProject("lib").buildGradle.appendText(
|
subProject("lib").buildGradleKts.appendText(
|
||||||
//language=Gradle
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
kotlin.android('androidLib') { publishAllLibraryVariants() }
|
kotlin.androidTarget("androidLib") { publishAllLibraryVariants() }
|
||||||
""".trimIndent()
|
""".trimIndent()
|
||||||
)
|
)
|
||||||
build("publish") {
|
build("publish") {
|
||||||
@@ -214,11 +212,10 @@ class KotlinAndroidMppIT : KGPBaseTest() {
|
|||||||
groupDir.deleteRecursively()
|
groupDir.deleteRecursively()
|
||||||
|
|
||||||
// Then group the variants by flavor and check that only one publication is created:
|
// Then group the variants by flavor and check that only one publication is created:
|
||||||
subProject("lib").buildGradle.appendText(
|
subProject("lib").buildGradleKts.appendText(
|
||||||
//language=Gradle
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
kotlin.android('androidLib').publishLibraryVariantsGroupedByFlavor = true
|
kotlin.androidTarget("androidLib").publishLibraryVariantsGroupedByFlavor = true
|
||||||
""".trimIndent()
|
""".trimIndent()
|
||||||
)
|
)
|
||||||
build("publish") {
|
build("publish") {
|
||||||
@@ -246,11 +243,21 @@ class KotlinAndroidMppIT : KGPBaseTest() {
|
|||||||
groupDir.deleteRecursively()
|
groupDir.deleteRecursively()
|
||||||
|
|
||||||
// Add one flavor dimension with two flavors, check that the flavors produce grouped publications:
|
// Add one flavor dimension with two flavors, check that the flavors produce grouped publications:
|
||||||
subProject("lib").buildGradle.appendText(
|
subProject("lib").buildGradleKts.appendText(
|
||||||
//language=Gradle
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
android { flavorDimensions('foo'); productFlavors { fooBar { dimension 'foo' }; fooBaz { dimension 'foo' } } }
|
android {
|
||||||
|
flavorDimensions("foo")
|
||||||
|
productFlavors {
|
||||||
|
create("fooBar") {
|
||||||
|
dimension = "foo"
|
||||||
|
}
|
||||||
|
|
||||||
|
create("fooBaz") {
|
||||||
|
dimension = "foo"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
""".trimIndent()
|
""".trimIndent()
|
||||||
)
|
)
|
||||||
build("publish") {
|
build("publish") {
|
||||||
@@ -291,11 +298,10 @@ class KotlinAndroidMppIT : KGPBaseTest() {
|
|||||||
groupDir.deleteRecursively()
|
groupDir.deleteRecursively()
|
||||||
|
|
||||||
// Disable the grouping and check that all the variants are published under separate artifactIds:
|
// Disable the grouping and check that all the variants are published under separate artifactIds:
|
||||||
subProject("lib").buildGradle.appendText(
|
subProject("lib").buildGradleKts.appendText(
|
||||||
//language=Gradle
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
kotlin.android('androidLib') { publishLibraryVariantsGroupedByFlavor = false }
|
kotlin.androidTarget("androidLib") { publishLibraryVariantsGroupedByFlavor = false }
|
||||||
""".trimIndent()
|
""".trimIndent()
|
||||||
)
|
)
|
||||||
build("publish") {
|
build("publish") {
|
||||||
@@ -352,13 +358,12 @@ class KotlinAndroidMppIT : KGPBaseTest() {
|
|||||||
buildOptions = defaultBuildOptions.copy(androidVersion = agpVersion),
|
buildOptions = defaultBuildOptions.copy(androidVersion = agpVersion),
|
||||||
buildJdk = jdkVersion.location
|
buildJdk = jdkVersion.location
|
||||||
) {
|
) {
|
||||||
subProject("lib").buildGradle.appendText(
|
subProject("lib").buildGradleKts.appendText(
|
||||||
//language=Gradle
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
kotlin.android('androidLib') {
|
kotlin.androidTarget("androidLib") {
|
||||||
withSourcesJar(false)
|
withSourcesJar(publish = false)
|
||||||
publishLibraryVariants = ['release']
|
publishLibraryVariants("release")
|
||||||
}
|
}
|
||||||
""".trimIndent()
|
""".trimIndent()
|
||||||
)
|
)
|
||||||
@@ -393,26 +398,55 @@ class KotlinAndroidMppIT : KGPBaseTest() {
|
|||||||
// check that the dependencies in the POMs are correctly rewritten:
|
// check that the dependencies in the POMs are correctly rewritten:
|
||||||
val appGroupDir = subProject("app").projectPath.resolve("build/repo/com/example")
|
val appGroupDir = subProject("app").projectPath.resolve("build/repo/com/example")
|
||||||
|
|
||||||
subProject("lib").buildGradle.appendText(
|
subProject("lib").buildGradleKts.appendText(
|
||||||
//language=Gradle
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
android { flavorDimensions('foo'); productFlavors { fooBar { dimension 'foo' }; fooBaz { dimension 'foo' } } }
|
android {
|
||||||
|
flavorDimensions("foo")
|
||||||
|
productFlavors {
|
||||||
|
create("fooBar") {
|
||||||
|
dimension = "foo"
|
||||||
|
}
|
||||||
|
|
||||||
|
create("fooBaz") {
|
||||||
|
dimension = "foo"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
""".trimIndent()
|
""".trimIndent()
|
||||||
)
|
)
|
||||||
|
|
||||||
subProject("app").buildGradle.modify {
|
subProject("app").buildGradleKts.modify {
|
||||||
it.replace("com.android.application", "com.android.library")
|
it.replace("com.android.application", "com.android.library")
|
||||||
.replace("applicationId", "//") +
|
.replace("applicationId", "//")
|
||||||
//language=Gradle
|
.replace("versionCode", "//")
|
||||||
|
.replace("versionName", "//")
|
||||||
|
.replace("plugins {\n", "plugins {\n `maven-publish`\n") +
|
||||||
"""
|
"""
|
||||||
|
|
||||||
apply plugin: 'maven-publish'
|
publishing {
|
||||||
publishing { repositories { maven { url = uri("${'$'}buildDir/repo") } } }
|
repositories {
|
||||||
kotlin.android('androidApp') { publishAllLibraryVariants() }
|
maven {
|
||||||
android { flavorDimensions('foo'); productFlavors { fooBar { dimension 'foo' }; fooBaz { dimension 'foo' } } }
|
url = uri("${'$'}buildDir/repo")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
kotlin.androidTarget("androidApp") { publishAllLibraryVariants() }
|
||||||
|
android {
|
||||||
|
flavorDimensions("foo")
|
||||||
|
productFlavors {
|
||||||
|
create("fooBar") {
|
||||||
|
dimension = "foo"
|
||||||
|
}
|
||||||
|
|
||||||
|
create("fooBaz") {
|
||||||
|
dimension = "foo"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
""".trimIndent()
|
""".trimIndent()
|
||||||
}
|
}
|
||||||
|
makeSnapshotTo("/tmp/111")
|
||||||
build("publish") {
|
build("publish") {
|
||||||
listOf("foobar", "foobaz").forEach { flavor ->
|
listOf("foobar", "foobaz").forEach { flavor ->
|
||||||
listOf("-debug", "").forEach { buildType ->
|
listOf("-debug", "").forEach { buildType ->
|
||||||
@@ -431,13 +465,12 @@ class KotlinAndroidMppIT : KGPBaseTest() {
|
|||||||
appGroupDir.deleteRecursively()
|
appGroupDir.deleteRecursively()
|
||||||
|
|
||||||
// Also check that api and runtimeOnly MPP dependencies get correctly published with the appropriate scope, KT-29476:
|
// Also check that api and runtimeOnly MPP dependencies get correctly published with the appropriate scope, KT-29476:
|
||||||
subProject("app").buildGradle.modify {
|
subProject("app").buildGradleKts.modify {
|
||||||
it.replace("implementation project(':lib')", "api project(':lib')") +
|
it.replace("implementation(project(\":lib\")", "api(project(\":lib\")") +
|
||||||
//language=Gradle
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
kotlin.sourceSets.commonMain.dependencies {
|
kotlin.sourceSets.getByName("commonMain").dependencies {
|
||||||
runtimeOnly(kotlin('reflect'))
|
runtimeOnly(kotlin("reflect"))
|
||||||
}
|
}
|
||||||
""".trimIndent()
|
""".trimIndent()
|
||||||
}
|
}
|
||||||
@@ -521,24 +554,23 @@ class KotlinAndroidMppIT : KGPBaseTest() {
|
|||||||
buildJdk = jdkVersion.location
|
buildJdk = jdkVersion.location
|
||||||
) {
|
) {
|
||||||
// Test the fix for KT-29343
|
// Test the fix for KT-29343
|
||||||
subProject("lib").buildGradle.appendText(
|
subProject("lib").buildGradleKts.appendText(
|
||||||
//language=Gradle
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
kotlin.sourceSets {
|
kotlin.sourceSets {
|
||||||
commonMain {
|
commonMain {
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation kotlin("stdlib-common")
|
implementation(kotlin("stdlib-common"))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
androidLibDebug {
|
val androidLibDebug by creating {
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation kotlin("reflect")
|
implementation(kotlin("reflect"))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
androidLibRelease {
|
val androidLibRelease by creating {
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation kotlin("test-junit")
|
implementation(kotlin("test-junit"))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -577,15 +609,14 @@ class KotlinAndroidMppIT : KGPBaseTest() {
|
|||||||
buildOptions = defaultBuildOptions.copy(androidVersion = agpVersion),
|
buildOptions = defaultBuildOptions.copy(androidVersion = agpVersion),
|
||||||
buildJdk = jdkVersion.location
|
buildJdk = jdkVersion.location
|
||||||
) {
|
) {
|
||||||
val libBuildScript = subProject("lib").buildGradle
|
val libBuildScript = subProject("lib").buildGradleKts
|
||||||
val appBuildScript = subProject("app").buildGradle
|
val appBuildScript = subProject("app").buildGradleKts
|
||||||
|
|
||||||
// Enable publishing for all Android variants:
|
// Enable publishing for all Android variants:
|
||||||
libBuildScript.appendText(
|
libBuildScript.appendText(
|
||||||
//language=Gradle
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
kotlin.android('androidLib') { publishAllLibraryVariants() }
|
kotlin.androidTarget("androidLib") { publishAllLibraryVariants() }
|
||||||
""".trimIndent()
|
""".trimIndent()
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -608,25 +639,24 @@ class KotlinAndroidMppIT : KGPBaseTest() {
|
|||||||
|
|
||||||
// Check that the consumer side uses custom attributes specified in the target and compilations:
|
// Check that the consumer side uses custom attributes specified in the target and compilations:
|
||||||
val appBuildScriptBackup = appBuildScript.readText()
|
val appBuildScriptBackup = appBuildScript.readText()
|
||||||
|
val libBuildScriptBackup = libBuildScript.readText()
|
||||||
|
|
||||||
libBuildScript.appendText(
|
libBuildScript.appendText(
|
||||||
//language=Gradle
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
kotlin.targets.all {
|
kotlin.targets.all {
|
||||||
attributes.attribute(
|
attributes.attribute(
|
||||||
Attribute.of("com.example.target", String),
|
Attribute.of("com.example.target", String::class.java),
|
||||||
targetName
|
targetName
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
""".trimIndent()
|
""".trimIndent()
|
||||||
)
|
)
|
||||||
appBuildScript.appendText(
|
appBuildScript.appendText(
|
||||||
//language=Gradle
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
kotlin.targets.androidApp.attributes.attribute(
|
kotlin.targets.getByName("androidApp").attributes.attribute(
|
||||||
Attribute.of("com.example.target", String),
|
Attribute.of("com.example.target", String::class.java),
|
||||||
"notAndroidLib"
|
"notAndroidLib"
|
||||||
)
|
)
|
||||||
""".trimIndent()
|
""".trimIndent()
|
||||||
@@ -641,18 +671,14 @@ class KotlinAndroidMppIT : KGPBaseTest() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
libBuildScript.writeText(
|
libBuildScript.writeText(
|
||||||
appBuildScriptBackup +
|
libBuildScriptBackup +
|
||||||
//language=Gradle
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
android {
|
|
||||||
namespace 'app.example.com.lib'
|
|
||||||
}
|
|
||||||
kotlin.targets.all {
|
kotlin.targets.all {
|
||||||
compilations.all {
|
compilations.all {
|
||||||
attributes.attribute(
|
attributes.attribute(
|
||||||
Attribute.of("com.example.compilation", String),
|
Attribute.of("com.example.compilation", String::class.java),
|
||||||
targetName + compilationName.capitalize()
|
target.name + compilationName.capitalize()
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -660,15 +686,11 @@ class KotlinAndroidMppIT : KGPBaseTest() {
|
|||||||
)
|
)
|
||||||
appBuildScript.writeText(
|
appBuildScript.writeText(
|
||||||
appBuildScriptBackup +
|
appBuildScriptBackup +
|
||||||
//language=Gradle
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
android {
|
kotlin.targets.getByName("androidApp").compilations.all {
|
||||||
namespace 'app.example.com.app_sample'
|
|
||||||
}
|
|
||||||
kotlin.targets.androidApp.compilations.all {
|
|
||||||
attributes.attribute(
|
attributes.attribute(
|
||||||
Attribute.of("com.example.compilation", String),
|
Attribute.of("com.example.compilation", String::class.java),
|
||||||
"notDebug"
|
"notDebug"
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -938,4 +960,5 @@ class KotlinAndroidMppIT : KGPBaseTest() {
|
|||||||
build("assemble")
|
build("assemble")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-3
@@ -142,9 +142,9 @@ abstract class AndroidAndJavaConsumeMppLibIT : BaseGradleIT() {
|
|||||||
if (useFlavors) {
|
if (useFlavors) {
|
||||||
it + "\n" + """
|
it + "\n" + """
|
||||||
android {
|
android {
|
||||||
flavorDimensions "myFlavor"
|
flavorDimensions("myFlavor")
|
||||||
productFlavors {
|
productFlavors {
|
||||||
flavor1 { dimension "myFlavor" }
|
create("flavor1") { dimension = "myFlavor" }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
""".trimIndent()
|
""".trimIndent()
|
||||||
@@ -153,7 +153,7 @@ abstract class AndroidAndJavaConsumeMppLibIT : BaseGradleIT() {
|
|||||||
// Simulate the behavior with user-defined consumable configuration added with no proper attributes:
|
// Simulate the behavior with user-defined consumable configuration added with no proper attributes:
|
||||||
it + "\n" + """
|
it + "\n" + """
|
||||||
configurations.create("legacyConfiguration") {
|
configurations.create("legacyConfiguration") {
|
||||||
def bundlingAttribute = Attribute.of("org.gradle.dependency.bundling", String)
|
val bundlingAttribute = Attribute.of("org.gradle.dependency.bundling", String::class.java)
|
||||||
attributes.attribute(bundlingAttribute, "external")
|
attributes.attribute(bundlingAttribute, "external")
|
||||||
}
|
}
|
||||||
""".trimIndent()
|
""".trimIndent()
|
||||||
|
|||||||
+1
-1
@@ -33,7 +33,7 @@ fun BuildResult.assertOutputContainsAny(
|
|||||||
) {
|
) {
|
||||||
assert(expectedSubStrings.any { output.contains(it) }) {
|
assert(expectedSubStrings.any { output.contains(it) }) {
|
||||||
printBuildOutput()
|
printBuildOutput()
|
||||||
"Build output does not contain any of \"$expectedSubStrings\""
|
"Build output does not contain any of \"${expectedSubStrings.toList()}\""
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
-82
@@ -1,82 +0,0 @@
|
|||||||
apply plugin: 'com.android.application'
|
|
||||||
apply plugin: 'kotlin-multiplatform'
|
|
||||||
|
|
||||||
group 'com.example'
|
|
||||||
version '1.0'
|
|
||||||
|
|
||||||
java {
|
|
||||||
toolchain.languageVersion.set(JavaLanguageVersion.of(8))
|
|
||||||
}
|
|
||||||
|
|
||||||
android {
|
|
||||||
compileSdkVersion 33
|
|
||||||
namespace 'app.example.com.app_sample'
|
|
||||||
defaultConfig {
|
|
||||||
applicationId "app.example.com.app_sample"
|
|
||||||
minSdkVersion 26
|
|
||||||
targetSdkVersion 33
|
|
||||||
versionCode 1
|
|
||||||
versionName "1.0"
|
|
||||||
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
|
|
||||||
}
|
|
||||||
buildTypes {
|
|
||||||
release {
|
|
||||||
minifyEnabled false
|
|
||||||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
compileOptions {
|
|
||||||
sourceCompatibility 1.8
|
|
||||||
targetCompatibility 1.8
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
dependencies {
|
|
||||||
implementation fileTree(dir: 'libs', include: ['*.jar'])
|
|
||||||
implementation 'com.android.support:appcompat-v7:27.1.1'
|
|
||||||
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
|
|
||||||
testImplementation 'junit:junit:4.13.2'
|
|
||||||
androidTestImplementation 'com.android.support.test:runner:1.0.2'
|
|
||||||
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
|
|
||||||
|
|
||||||
implementation 'org.jetbrains.kotlin:kotlin-stdlib'
|
|
||||||
}
|
|
||||||
|
|
||||||
kotlin {
|
|
||||||
sourceSets {
|
|
||||||
commonMain {
|
|
||||||
dependencies {
|
|
||||||
implementation project(':lib')
|
|
||||||
implementation 'org.jetbrains.kotlin:kotlin-stdlib-common'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
jvmAppMain {
|
|
||||||
dependencies {
|
|
||||||
implementation 'org.jetbrains.kotlin:kotlin-stdlib'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
jsAppMain {
|
|
||||||
dependencies {
|
|
||||||
implementation 'org.jetbrains.kotlin:kotlin-stdlib-js'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
targets {
|
|
||||||
fromPreset(presets.android, 'androidApp')
|
|
||||||
fromPreset(presets.jvm, 'jvmApp')
|
|
||||||
fromPreset(presets.js, 'jsApp')
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// test diagnostic task, not needed by the build
|
|
||||||
task printCompilerPluginOptions {
|
|
||||||
doFirst {
|
|
||||||
kotlin.sourceSets.each { sourceSet ->
|
|
||||||
def args = sourceSet.languageSettings.compilerPluginArguments
|
|
||||||
def cp = sourceSet.languageSettings.compilerPluginClasspath.files
|
|
||||||
println sourceSet.name + '=args=>' + args
|
|
||||||
println sourceSet.name + '=cp=>' + cp
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+86
@@ -0,0 +1,86 @@
|
|||||||
|
import org.jetbrains.kotlin.gradle.tasks.AbstractKotlinCompile
|
||||||
|
import org.jetbrains.kotlin.gradle.tasks.CompilerPluginOptions
|
||||||
|
|
||||||
|
|
||||||
|
plugins {
|
||||||
|
id("com.android.application")
|
||||||
|
kotlin("multiplatform")
|
||||||
|
}
|
||||||
|
|
||||||
|
group = "com.example"
|
||||||
|
version = "1.0"
|
||||||
|
|
||||||
|
java {
|
||||||
|
toolchain.languageVersion.set(JavaLanguageVersion.of(8))
|
||||||
|
}
|
||||||
|
|
||||||
|
kotlin {
|
||||||
|
androidTarget("androidApp")
|
||||||
|
jvm("jvmApp")
|
||||||
|
js("jsApp")
|
||||||
|
|
||||||
|
sourceSets {
|
||||||
|
commonMain {
|
||||||
|
dependencies {
|
||||||
|
implementation(project(":lib"))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
android {
|
||||||
|
compileSdk = 33
|
||||||
|
namespace = "app.example.com.app_sample"
|
||||||
|
defaultConfig {
|
||||||
|
applicationId = "app.example.com.app_sample"
|
||||||
|
minSdk = 26
|
||||||
|
targetSdk = 33
|
||||||
|
versionCode = 1
|
||||||
|
versionName = "1.0"
|
||||||
|
testInstrumentationRunner = "android.support.test.runner.AndroidJUnitRunner"
|
||||||
|
}
|
||||||
|
buildTypes {
|
||||||
|
release {
|
||||||
|
isMinifyEnabled = false
|
||||||
|
proguardFiles(getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
compileOptions {
|
||||||
|
sourceCompatibility = JavaVersion.VERSION_1_8
|
||||||
|
targetCompatibility = JavaVersion.VERSION_1_8
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
implementation(fileTree(mapOf("dir" to "libs", "include" to listOf("*.jar"))))
|
||||||
|
implementation("com.android.support:appcompat-v7:27.1.1")
|
||||||
|
implementation("com.android.support.constraint:constraint-layout:1.1.2")
|
||||||
|
testImplementation("junit:junit:4.13.2")
|
||||||
|
androidTestImplementation("com.android.support.test:runner:1.0.2")
|
||||||
|
androidTestImplementation("com.android.support.test.espresso:espresso-core:3.0.2")
|
||||||
|
}
|
||||||
|
|
||||||
|
// test diagnostic task, not needed by the build
|
||||||
|
tasks.register("printCompilerPluginOptions") {
|
||||||
|
doFirst {
|
||||||
|
kotlin.targets.flatMap { it.compilations }.forEach { compilation ->
|
||||||
|
val sourceSetName = compilation.defaultSourceSet.name
|
||||||
|
val compileTask = compilation.compileTaskProvider.get()
|
||||||
|
val args: List<String>
|
||||||
|
val cp: Set<File>
|
||||||
|
when (compileTask) {
|
||||||
|
is AbstractKotlinCompile<*> -> {
|
||||||
|
args = compileTask
|
||||||
|
.pluginOptions
|
||||||
|
.get()
|
||||||
|
.fold(CompilerPluginOptions()) { options, option -> options.plus(option) }
|
||||||
|
.arguments
|
||||||
|
cp = compileTask.pluginClasspath.files
|
||||||
|
}
|
||||||
|
else -> return@forEach
|
||||||
|
}
|
||||||
|
println(sourceSetName + "=args=>" + args)
|
||||||
|
println(sourceSetName + "=cp=>" + cp)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
-100
@@ -1,100 +0,0 @@
|
|||||||
apply plugin: 'com.android.library'
|
|
||||||
apply plugin: 'kotlin-multiplatform'
|
|
||||||
apply plugin: 'maven-publish'
|
|
||||||
|
|
||||||
group 'com.example'
|
|
||||||
version '1.0'
|
|
||||||
|
|
||||||
java {
|
|
||||||
toolchain.languageVersion.set(JavaLanguageVersion.of(8))
|
|
||||||
}
|
|
||||||
|
|
||||||
android {
|
|
||||||
compileSdkVersion 31
|
|
||||||
namespace 'app.example.com.lib'
|
|
||||||
|
|
||||||
defaultConfig {
|
|
||||||
minSdkVersion 26
|
|
||||||
targetSdkVersion 31
|
|
||||||
versionCode 1
|
|
||||||
versionName "1.0"
|
|
||||||
|
|
||||||
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
buildTypes {
|
|
||||||
release {
|
|
||||||
minifyEnabled false
|
|
||||||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
compileOptions {
|
|
||||||
targetCompatibility = JavaVersion.VERSION_1_8
|
|
||||||
sourceCompatibility = JavaVersion.VERSION_1_8
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
dependencies {
|
|
||||||
implementation fileTree(dir: 'libs', include: ['*.jar'])
|
|
||||||
|
|
||||||
implementation 'com.android.support:appcompat-v7:27.1.1'
|
|
||||||
testImplementation 'junit:junit:4.13.2'
|
|
||||||
androidTestImplementation 'com.android.support.test:runner:1.0.2'
|
|
||||||
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
|
|
||||||
}
|
|
||||||
|
|
||||||
kotlin.targets.all {
|
|
||||||
compilations.all {
|
|
||||||
// KT-29964: check that Android compilations can be configured with an `all { ... }` handler:
|
|
||||||
kotlinOptions {
|
|
||||||
verbose = true
|
|
||||||
}
|
|
||||||
compileKotlinTask.doFirst {
|
|
||||||
if (!compileKotlinTask.kotlinOptions.verbose) {
|
|
||||||
throw new AssertionError("kotlinOptions were not configured properly")
|
|
||||||
}
|
|
||||||
println "KT-29964 OK"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
kotlin {
|
|
||||||
sourceSets {
|
|
||||||
jvmLibMain {
|
|
||||||
dependencies {
|
|
||||||
implementation 'org.jetbrains.kotlin:kotlin-stdlib'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
jsLibMain {
|
|
||||||
dependencies {
|
|
||||||
implementation 'org.jetbrains.kotlin:kotlin-stdlib-js'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
targets {
|
|
||||||
fromPreset(presets.android, 'androidLib') {
|
|
||||||
attributes {
|
|
||||||
attribute(Attribute.of("com.example.target", String), "androidLib")
|
|
||||||
}
|
|
||||||
compilations.all {
|
|
||||||
attributes {
|
|
||||||
attribute(Attribute.of("com.example.compilation", String), compilationName)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
publishAllLibraryVariants()
|
|
||||||
}
|
|
||||||
fromPreset(presets.jvm, 'jvmLib')
|
|
||||||
fromPreset(presets.js, 'jsLib')
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
publishing {
|
|
||||||
repositories {
|
|
||||||
maven {
|
|
||||||
url = uri("$buildDir/repo")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+85
@@ -0,0 +1,85 @@
|
|||||||
|
plugins {
|
||||||
|
id("com.android.library")
|
||||||
|
kotlin("multiplatform")
|
||||||
|
`maven-publish`
|
||||||
|
}
|
||||||
|
|
||||||
|
group = "com.example"
|
||||||
|
version = "1.0"
|
||||||
|
|
||||||
|
java {
|
||||||
|
toolchain.languageVersion.set(JavaLanguageVersion.of(8))
|
||||||
|
}
|
||||||
|
|
||||||
|
android {
|
||||||
|
compileSdk = 31
|
||||||
|
namespace = "app.example.com.lib"
|
||||||
|
|
||||||
|
defaultConfig {
|
||||||
|
minSdk = 26
|
||||||
|
targetSdk = 31
|
||||||
|
|
||||||
|
testInstrumentationRunner = "android.support.test.runner.AndroidJUnitRunner"
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
buildTypes {
|
||||||
|
release {
|
||||||
|
isMinifyEnabled = false
|
||||||
|
proguardFiles(getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
compileOptions {
|
||||||
|
sourceCompatibility = JavaVersion.VERSION_1_8
|
||||||
|
targetCompatibility = JavaVersion.VERSION_1_8
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
implementation(fileTree(mapOf("dir" to "libs", "include" to listOf("*.jar"))))
|
||||||
|
|
||||||
|
implementation("com.android.support:appcompat-v7:27.1.1")
|
||||||
|
testImplementation("junit:junit:4.13.2")
|
||||||
|
androidTestImplementation("com.android.support.test:runner:1.0.2")
|
||||||
|
androidTestImplementation("com.android.support.test.espresso:espresso-core:3.0.2")
|
||||||
|
}
|
||||||
|
|
||||||
|
kotlin.targets.all {
|
||||||
|
compilations.all {
|
||||||
|
// KT-29964: check that Android compilations can be configured with an `all { ... }` handler:
|
||||||
|
kotlinOptions {
|
||||||
|
verbose = true
|
||||||
|
}
|
||||||
|
compileKotlinTask.doFirst {
|
||||||
|
if (!compileKotlinTask.kotlinOptions.verbose) {
|
||||||
|
throw AssertionError("kotlinOptions were not configured properly")
|
||||||
|
}
|
||||||
|
println("KT-29964 OK")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
kotlin {
|
||||||
|
androidTarget("androidLib") {
|
||||||
|
attributes {
|
||||||
|
attribute(Attribute.of("com.example.target", String::class.java), "androidLib")
|
||||||
|
}
|
||||||
|
|
||||||
|
compilations.all {
|
||||||
|
attributes {
|
||||||
|
attribute(Attribute.of("com.example.compilation", String::class.java), compilationName)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
publishAllLibraryVariants()
|
||||||
|
}
|
||||||
|
|
||||||
|
jvm("jvmLib")
|
||||||
|
js("jsLib")
|
||||||
|
}
|
||||||
|
|
||||||
|
publishing {
|
||||||
|
repositories {
|
||||||
|
maven("$buildDir/repo")
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user