org.danbrough.xtras.publications.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of plugin Show documentation
Show all versions of plugin Show documentation
Kotlin support for common native libraries.
The newest version!
package org.danbrough.xtras
import org.danbrough.xtras.tasks.PackageTaskName
import org.gradle.api.publish.PublishingExtension
import org.gradle.api.publish.maven.MavenPublication
import org.gradle.kotlin.dsl.create
import org.gradle.kotlin.dsl.dependencies
import org.gradle.kotlin.dsl.findByType
import org.jetbrains.kotlin.konan.target.KonanTarget
import java.io.File
fun XtrasLibrary.registerBinaryPublication(target: KonanTarget) {
val publishing = project.extensions.findByType() ?: return
val resolvePackageTaskName = PackageTaskName.RESOLVE.taskName(this, target)
val artifactTask = project.tasks.getByName(resolvePackageTaskName)
val publicationName = "${name}Binaries${target.kotlinTargetName.capitalized()}"
publishing.publications.create(publicationName) {
artifactId = artifactID(target)
version = [email protected]
groupId = [email protected]
val file = artifactTask.outputs.files.first()
//project.logError("registerBinaryPublication for file: ${file.absolutePath}")
artifact(file).builtBy(artifactTask)
pom {
packaging = "tgz"
}
}
}
fun XtrasLibrary.resolveBinariesFromMaven(target: KonanTarget): File? {
val mavenID = "$group:${artifactID(target)}:$version"
project.logDebug("$name::resolveBinariesFromMaven():$target $mavenID")
val binariesConfiguration =
project.configurations.create("configuration${[email protected]()}Binaries${target.kotlinTargetName.capitalized()}") {
/* isVisible = false
isTransitive = false
isCanBeConsumed = true
isCanBeResolved = true*/
}
project.dependencies {
binariesConfiguration(mavenID)
}
runCatching {
return binariesConfiguration.resolve().first().also {
project.logDebug("$name::resolveBinariesFromMaven(): $target found ${it.absolutePath}")
}
}.exceptionOrNull()?.let {
project.logInfo("$name::resolveBinariesFromMaven():$target Failed for $mavenID: ${it.message}")
}
return null
}