Last active
January 17, 2019 06:06
-
-
Save e5l/3bd4101e3f3fcb9f849e4f1e89511da7 to your computer and use it in GitHub Desktop.
gradle publishing hacks
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
// 4.7 | |
publishing { | |
publications { | |
foo { | |
gradleModuleMetadataFile = null | |
tasks.matching { it.name == "generateMetadataFileFor${name.capitalize()}Publication" }.all { onlyIf { false } } | |
} | |
} | |
} | |
// 4.8-5.0 | |
publishing { | |
publications { | |
foo { | |
moduleDescriptorGenerator = null | |
} | |
} | |
} | |
// publishing: use module-name to be compatible with middle plugin | |
targets { | |
configure([linux64, macos64, windows64, iosArm32, iosArm64, iosX64]) { | |
def compileTask = tasks.getByName(compilations.main.compileKotlinTaskName) | |
compileTask.kotlinOptions.freeCompilerArgs += ["-module-name", "atomicfu-native"] | |
} | |
} | |
// reword modules to avoid metadata clash | |
afterEvaluate { | |
publishing.publications { | |
jvm.artifactId = 'atomicfu' | |
js.artifactId = 'atomicfu-js' | |
metadata.artifactId = 'atomicfu-common' | |
kotlinMultiplatform.artifactId = 'atomicfu-native' | |
configure([metadata, jvm, js]) { | |
gradleModuleMetadataFile = null | |
tasks.matching { it.name == "generateMetadataFileFor${name.capitalize()}Publication" }.all { onlyIf { false } } | |
} | |
} | |
} | |
// dependency without meta-data | |
// middle plugin: | |
import org.jetbrains.kotlin.gradle.plugin.experimental.KotlinNativeBinary | |
components.withType(KotlinNativeBinary).all { | |
def target = konanTarget.name | |
dependencies.with { | |
implementation "org.jetbrains.kotlinx:atomicfu-native_debug_$target:0.11.10-eap13" | |
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core-native_debug_$target:0.30.2-eap13" | |
} | |
} | |
// new plugin: | |
targets { | |
fromPreset(presets.iosX64, 'ios') | |
fromPreset(presets.macosX64, 'macos') | |
fromPreset(presets.iosArm64, 'iosSim') | |
configure([ios, macos, iosSim]){ | |
def target = konanTarget.name | |
compilations.main { | |
dependencies { | |
implementation "org.jetbrains.kotlinx:atomicfu-native_debug_$target:0.11.10-eap13" | |
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core-native_debug_$target:0.30.2-eap13" | |
} | |
} | |
} | |
} | |
// update app with dependency wo metadata | |
targets { | |
fromPreset(presets.iosX64, 'ios') | |
fromPreset(presets.macosX64, 'macos') | |
fromPreset(presets.iosArm64, 'iosSim') | |
configure([ios, macos, iosSim]){ | |
// Instead of target = konanTarget.name | |
def attributes = project.configurations.getByName(compileDependencyConfigurationName).attributes | |
def targetAttribute = attributes.keySet().find { | |
it.name == "org.jetbrains.kotlin.native.target" | |
} | |
def target = attributes.getAttribute(targetAttribute) | |
// --- | |
compilations.main { | |
dependencies { | |
implementation "org.jetbrains.kotlinx:atomicfu-native_debug_$target:0.11.10-eap13" | |
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core-native_debug_$target:0.30.2-eap13" | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment