diff --git a/android-ktx/gradle.properties b/android-ktx/gradle.properties index d6ac4b8c..47acd4fe 100644 --- a/android-ktx/gradle.properties +++ b/android-ktx/gradle.properties @@ -27,3 +27,4 @@ android.useAndroidX=true android.enableJetifier=false android.disableAutomaticComponentCreation=true +kotlin.stdlib.default.dependency=false diff --git a/android-ktx/lib/build.gradle b/android-ktx/lib/build.gradle index 2f4b30ea..8cee4160 100644 --- a/android-ktx/lib/build.gradle +++ b/android-ktx/lib/build.gradle @@ -185,10 +185,10 @@ dependencies { // androidx.work:work-runtime-ktx:2.8.0 requires 1.3.0 compileOnly 'androidx.annotation:annotation:1.3.0' - implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.4" + compileOnly "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.4" // Work Manager support - implementation "androidx.work:work-runtime-ktx:2.8.1" + compileOnly "androidx.work:work-runtime-ktx:2.8.1" implementation("com.couchbase.lite:${CBL_ANDROID_LIB}:${BUILD_VERSION}") { changing = true } @@ -199,7 +199,10 @@ dependencies { androidTestImplementation 'androidx.test:rules:1.5.0' androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1' + androidTestImplementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.4" + // Work Manager Test support + androidTestImplementation "androidx.work:work-runtime-ktx:2.8.1" androidTestImplementation "androidx.work:work-testing:2.8.1" } @@ -317,7 +320,7 @@ project.afterEvaluate { artifactId CBL_ARTIFACT_ID version BUILD_VERSION - artifact bundleReleaseAar + from components.release artifact dokkaJar artifact sourcesJar @@ -327,12 +330,14 @@ project.afterEvaluate { root.appendNode('description', CBL_DESCRIPTION) root.children().last() + pomConfig - def dependenciesNode = root.appendNode('dependencies') - def dep = dependenciesNode.appendNode('dependency') - dep.appendNode('groupId', CBL_GROUP) - dep.appendNode('artifactId', CBL_ANDROID_LIB) - dep.appendNode('version', BUILD_VERSION) - dep.appendNode('type', CBL_ANDROID_TYPE) + def dependencies = root.dependencies.dependency + + // Include only configured dependencies + dependencies.each { + if (CBL_ANDROID_LIB != it.artifactId.last().value().last()) { + it.parent().remove(it) + } + } } } @@ -341,7 +346,7 @@ project.afterEvaluate { artifactId CBL_ARTIFACT_ID version BUILD_VERSION - artifact bundleDebugAar + from components.debug artifact dokkaJar artifact sourcesJar @@ -351,12 +356,14 @@ project.afterEvaluate { root.appendNode('description', CBL_DESCRIPTION) root.children().last() + pomConfig - def dependenciesNode = root.appendNode('dependencies') - def dep = dependenciesNode.appendNode('dependency') - dep.appendNode('groupId', CBL_GROUP) - dep.appendNode('artifactId', CBL_ANDROID_LIB) - dep.appendNode('version', BUILD_VERSION) - dep.appendNode('type', CBL_ANDROID_TYPE) + def dependencies = root.dependencies.dependency + + // Include only configured dependencies + dependencies.each { + if (CBL_ANDROID_LIB != it.artifactId.last().value().last()) { + it.parent().remove(it) + } + } } } } diff --git a/android/gradle.properties b/android/gradle.properties index d6ac4b8c..47acd4fe 100644 --- a/android/gradle.properties +++ b/android/gradle.properties @@ -27,3 +27,4 @@ android.useAndroidX=true android.enableJetifier=false android.disableAutomaticComponentCreation=true +kotlin.stdlib.default.dependency=false diff --git a/android/lib/build.gradle b/android/lib/build.gradle index eb5fdb2d..b07790ac 100644 --- a/android/lib/build.gradle +++ b/android/lib/build.gradle @@ -17,6 +17,10 @@ // Please try to keep this build file as similar to the other family build files // as is possible. // + +import org.gradle.api.attributes.java.TargetJvmEnvironment +import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType + import java.time.Instant import java.util.regex.Pattern @@ -501,6 +505,54 @@ publishing { } project.afterEvaluate { + // Include Java variant definition in Gradle Module Metadata + def javaApiConfig = configurations.create("javaApi").tap { + canBeResolved = false + canBeConsumed = true + attributes { + attribute(Category.CATEGORY_ATTRIBUTE, objects.named(Category.class, Category.LIBRARY)) + attribute(TargetJvmEnvironment.TARGET_JVM_ENVIRONMENT_ATTRIBUTE, objects.named(TargetJvmEnvironment.class, TargetJvmEnvironment.STANDARD_JVM)) + attribute(KotlinPlatformType.attribute, KotlinPlatformType.jvm) + attribute(Usage.USAGE_ATTRIBUTE, objects.named(Usage.class, Usage.JAVA_API)) + } + } + + // Add variant artifact as a dependencies, since it's in another module + dependencies { + javaApi("com.couchbase.lite:couchbase-lite-java:$version") + } + + def javaRuntimeConfig = configurations.create("javaRuntime").tap { + extendsFrom(javaApiConfig) + canBeResolved = false + canBeConsumed = true + attributes { + attribute(Category.CATEGORY_ATTRIBUTE, objects.named(Category.class, Category.LIBRARY)) + attribute(TargetJvmEnvironment.TARGET_JVM_ENVIRONMENT_ATTRIBUTE, objects.named(TargetJvmEnvironment.class, TargetJvmEnvironment.STANDARD_JVM)) + attribute(KotlinPlatformType.attribute, KotlinPlatformType.jvm) + attribute(Usage.USAGE_ATTRIBUTE, objects.named(Usage.class, Usage.JAVA_RUNTIME)) + } + } + + // AdhocComponentWithVariants is wrapped by anonymous component class, find it with reflection + // can be replaced with (components.release as AdhocComponentWithVariants) + // with this fix: https://youtrack.jetbrains.com/issue/KT-58830 + def adhocField = components.release.class.getDeclaredFields() + .find { it.getType() == AdhocComponentWithVariants } + adhocField.setAccessible(true) + AdhocComponentWithVariants adhocComponent = adhocField.get(components.release) + + adhocComponent.with { + addVariantsFromConfiguration(javaApiConfig) { + mapToMavenScope("compile") + mapToOptional() + } + addVariantsFromConfiguration(javaRuntimeConfig) { + mapToMavenScope("runtime") + mapToOptional() + } + } + publishing { publications { libRelease(MavenPublication) { @@ -508,25 +560,21 @@ project.afterEvaluate { artifactId CBL_ARTIFACT_ID version BUILD_VERSION - artifact bundleReleaseAar + from components.release artifact sourcesJar artifact javadocJar - // include dependencies pom.withXml { def root = asNode() root.appendNode('description', CBL_DESCRIPTION) root.children().last() + pomConfig - def dependenciesNode = root.appendNode('dependencies') + def dependencies = root.dependencies.dependency // Include only configured dependencies - configurations.implementation.allDependencies.each { - if (DEPENDENCIES.contains(it.name)) { - def dep = dependenciesNode.appendNode('dependency') - dep.appendNode('groupId', it.group) - dep.appendNode('artifactId', it.name) - dep.appendNode('version', it.version) + dependencies.each { + if (!DEPENDENCIES.contains(it.artifactId.last().value().last())) { + it.parent().remove(it) } } } @@ -537,25 +585,21 @@ project.afterEvaluate { artifactId CBL_ARTIFACT_ID version BUILD_VERSION - artifact bundleDebugAar + from components.debug artifact sourcesJar artifact javadocJar - // include dependencies pom.withXml { def root = asNode() root.appendNode('description', CBL_DESCRIPTION) root.children().last() + pomConfig - def dependenciesNode = root.appendNode('dependencies') + def dependencies = root.dependencies.dependency // Include only configured dependencies - configurations.implementation.allDependencies.each { - if (DEPENDENCIES.contains(it.name)) { - def dep = dependenciesNode.appendNode('dependency') - dep.appendNode('groupId', it.group) - dep.appendNode('artifactId', it.name) - dep.appendNode('version', it.version) + dependencies.each { + if (!DEPENDENCIES.contains(it.artifactId.last().value().last())) { + it.parent().remove(it) } } } diff --git a/java/gradle.properties b/java/gradle.properties index 2eb22c2c..8bba0857 100644 --- a/java/gradle.properties +++ b/java/gradle.properties @@ -19,3 +19,4 @@ org.gradle.jvmargs=-Xmx4608m # Required to publish to ProGet (see https://github.com/gradle/gradle/issues/11308) systemProp.org.gradle.internal.publish.checksums.insecure=true +kotlin.stdlib.default.dependency=false diff --git a/java/lib/build.gradle b/java/lib/build.gradle index 9b576800..0ffcd004 100644 --- a/java/lib/build.gradle +++ b/java/lib/build.gradle @@ -18,7 +18,9 @@ import com.github.spotbugs.snom.SpotBugsTask import org.apache.tools.ant.filters.ReplaceTokens +import org.gradle.api.attributes.java.TargetJvmEnvironment import org.gradle.internal.os.OperatingSystem +import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType import java.util.regex.Pattern @@ -603,6 +605,46 @@ project.afterEvaluate { tasks.withType(Zip) { duplicatesStrategy = DuplicatesStrategy.EXCLUDE } } +// Include Android variant definition in Gradle Module Metadata +def androidApiConfig = configurations.create("androidApi").tap { + canBeResolved = false + canBeConsumed = true + attributes { + attribute(Category.CATEGORY_ATTRIBUTE, objects.named(Category.class, Category.LIBRARY)) + attribute(TargetJvmEnvironment.TARGET_JVM_ENVIRONMENT_ATTRIBUTE, objects.named(TargetJvmEnvironment.class, TargetJvmEnvironment.ANDROID)) + attribute(KotlinPlatformType.attribute, KotlinPlatformType.androidJvm) + attribute(Usage.USAGE_ATTRIBUTE, objects.named(Usage.class, Usage.JAVA_API)) + } +} + +// Add variant artifact as a dependencies, since it's in another module +dependencies { + androidApi("com.couchbase.lite:couchbase-lite-android:$version") +} + +def androidRuntimeConfig = configurations.create("androidRuntime").tap { + extendsFrom(androidApiConfig) + canBeResolved = false + canBeConsumed = true + attributes { + attribute(Category.CATEGORY_ATTRIBUTE, objects.named(Category.class, Category.LIBRARY)) + attribute(TargetJvmEnvironment.TARGET_JVM_ENVIRONMENT_ATTRIBUTE, objects.named(TargetJvmEnvironment.class, TargetJvmEnvironment.ANDROID)) + attribute(KotlinPlatformType.attribute, KotlinPlatformType.androidJvm) + attribute(Usage.USAGE_ATTRIBUTE, objects.named(Usage.class, Usage.JAVA_RUNTIME)) + } +} + +(components.java as AdhocComponentWithVariants).with { + addVariantsFromConfiguration(androidApiConfig) { + mapToMavenScope("compile") + mapToOptional() + } + addVariantsFromConfiguration(androidRuntimeConfig) { + mapToMavenScope("runtime") + mapToOptional() + } +} + publishing { publications { couchbaseLiteJava(MavenPublication) { @@ -612,7 +654,7 @@ publishing { artifactId "${JAR_ARTIFACT}${suffix}" version BUILD_VERSION - artifact jar + from components.java artifact sourcesJar artifact javadocJar @@ -646,15 +688,12 @@ publishing { } withXml { - def dependenciesNode = asNode().appendNode('dependencies') + def dependencies = asNode().dependencies.dependency // Include only configured dependencies - configurations.implementation.allDependencies.each { - if (DEPENDENCIES.contains(it.name)) { - def dep = dependenciesNode.appendNode('dependency') - dep.appendNode('groupId', it.group) - dep.appendNode('artifactId', it.name) - dep.appendNode('version', it.version) + dependencies.each { + if (!DEPENDENCIES.contains(it.artifactId.last().value())) { + it.parent().remove(it) } } }