Skip to content

Instantly share code, notes, and snippets.

@RdeWilde
Created December 10, 2019 12:02
Show Gist options
  • Save RdeWilde/5fb125cd3b69d49ea483e8a824f32708 to your computer and use it in GitHub Desktop.
Save RdeWilde/5fb125cd3b69d49ea483e8a824f32708 to your computer and use it in GitHub Desktop.
Export dependency to shared library
group = "com.mylib"
version = "0.0.1"
plugins {
idea
java
id("kotlin-multiplatform")
}
repositories {
mavenCentral()
jcenter()
google()
}
dependencies {
// implementation("com.google.protobuf:protobuf-java:3.6.1")
}
apply {
plugin<MavenPublishPlugin>()
}
configure<JavaPluginConvention> {
sourceCompatibility = JavaVersion.VERSION_1_8
}
tasks.withType<JavaCompile> {
options.encoding = "UTF-8"
}
kotlin {
jvm()
linuxX64("native") {
val attributes = compilations["main"].compileDependencyConfigurationName.let {
configurations[it].attributes
}
val exportDeps by configurations.creating {
// Copy attributes from the regular dependency configuration
// (aka compileClasspath) to enable variant-aware dependency resolution.
copyAttributes(attributes, this.attributes)
isCanBeConsumed = false
isCanBeResolved = true
// Make export non-transitive for more granular exporting.
isTransitive = false
}
// Add dependencies to be exported.
dependencies.add("exportDeps", "com.ionspin.kotlin:bignum:0.1.3")
binaries.sharedLib {
baseName = "mylib"
val lib = this
linkTask.apply {
// Take exported dependencies into account during UP-TO-DATE checks.
inputs.files.plus(exportDeps)
doFirst {
// Modify compiler args in a doFirst block to avoid
// resolving the export configuration at the configuration stage.
exportDeps.resolve().forEach {
print(it.absolutePath)
lib.freeCompilerArgs += "-Xexport-library=${it.absolutePath}"
}
}
}
}
}
sourceSets.apply {
commonMain {
dependencies {
implementation(kotlin("stdlib"))
implementation(kotlin("stdlib-common"))
implementation("com.ionspin.kotlin:bignum:0.1.3")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core-common:1.3.2")
// api("com.ionspin.kotlin:bignum:0.1.3")
}
}
commonTest {
dependencies {
implementation(kotlin("test-common"))
implementation(kotlin("test-annotations-common"))
}
}
linuxX64 {
dependencies {
implementation(kotlin("stdlib"))
}
}
}
}
tasks {
wrapper {
gradleVersion = "5.6.1"
distributionType = Wrapper.DistributionType.ALL
}
}
fun copyAttributes(from: AttributeContainer, to: AttributeContainer) {
fun <T> copyAttribute(key: Attribute<T>, from: AttributeContainer, to: AttributeContainer) {
to.attribute(key, from.getAttribute(key)!!)
}
from.keySet().forEach { key -> copyAttribute(key, from, to) }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment