com.github.panpf.maven.publish.legacy.Coordinates.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of maven-publish-gradle-plugin Show documentation
Show all versions of maven-publish-gradle-plugin Show documentation
Gradle plugin that configures publish tasks to automatically upload all of your Java, Kotlin, Gradle, or Android libraries to any Maven instance.
The newest version!
package com.github.panpf.maven.publish.legacy
import com.github.panpf.maven.publish.findOptionalProperty
import com.github.panpf.maven.publish.gradlePublishing
import org.gradle.api.Project
import org.gradle.api.publish.maven.MavenPublication
internal fun Project.setCoordinates() {
group = project.findOptionalProperty("GROUP") ?: group
version = project.findOptionalProperty("VERSION_NAME") ?: version
val artifactId = project.findOptionalProperty("POM_ARTIFACT_ID")
if (artifactId != null && artifactId != project.name) {
setArtifactId(artifactId)
}
}
/**
* Artifact id defaults to project name which is not mutable.
* Some created publications use derived artifact ids (e.g. library, library-jvm, library-js) so it needs to be
* replaced instead of just set.
*/
private fun Project.setArtifactId(artifactId: String) {
gradlePublishing.publications.withType(MavenPublication::class.java).configureEach { publication ->
// skip the plugin marker artifact which has it's own artifact id based on the plugin id
if (publication.name.endsWith("PluginMarkerMaven")) {
return@configureEach
}
val projectName = name
val updatedArtifactId = publication.artifactId.replace(projectName, artifactId)
publication.artifactId = updatedArtifactId
// in Kotlin MPP projects some publications change our manually set artifactId again
afterEvaluate {
gradlePublishing.publications.withType(MavenPublication::class.java).named(publication.name).configure { publication ->
if (publication.artifactId != updatedArtifactId) {
publication.artifactId = publication.artifactId.replace(projectName, artifactId)
}
}
}
}
}