-
Notifications
You must be signed in to change notification settings - Fork 6
Publish Gradle Module Metadata and variant info #27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
3d5302c
d3b1f4e
81bb467
907a0a6
73196d1
b3c93c0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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,32 +505,76 @@ 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 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this going to work for both the CE and EE versions? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. All of this should work the same for both CE and EE, just with the variant artifacts being different for EE. So
here and
in the Java lib's build.gradle. It might make sense to use a variable, like |
||
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) { | ||
groupId CBL_GROUP | ||
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) | ||
} | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Jeff: How does this work? Who provides the library at runtime?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is just to filter the coroutines dependency from being published as an explicit runtime dependency in both the .pom and .module, which is what you were doing already when manually filtering the published pom dependencies.
By specifying the dependency as
compileOnly
, the library consumer needs to provide the dependency if they make use of any of the CBL KTX APIs that depend on coroutines-core APIs (same with work-runtime-ktx). But it makes the dependency optional if they don't use those APIs.The tests add the dependencies as
androidTestImplementation
, so they're added to the test binaries.Again, this is how the behavior was already, this just makes it explicit and allows it to be the same in both the .pom and the .module metadata.