Skip to content

Commit

Permalink
Fix gradle plugin maven publication coordinates
Browse files Browse the repository at this point in the history
  • Loading branch information
johnsonlee committed Oct 6, 2021
1 parent d15d76c commit ed56a9d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,19 @@ abstract class AbstractLibraryPublishPlugin : Plugin<Project> {

fun MavenPublication.configure(project: Project) {
artifactId = project.name
configureGroupId(project)
configureVersion(project)
}

fun MavenPublication.configureGroupId(project: Project) {
groupId = listOf(project.group, project.rootProject.group)
.map(Any::toString)
.filterNot { it == project.rootProject.name || it.startsWith("${project.rootProject.name}.") }
.firstOrNull(String::isNotBlank)
?: throw GradleException("group id of $project has not been configured")
}

fun MavenPublication.configureVersion(project: Project) {
version = listOf(project.version, project.rootProject.version)
.map(Any::toString)
.firstOrNull { it != DEFAULT_VERSION }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ class GradlePluginPublishPlugin : AbstractLibraryPublishPlugin() {
}

withType<MavenPublication>().configureEach {
configureGroupId(project)
configureVersion(project)
artifact(javadocJar)
artifact(sourcesJar)
config.invoke(this)
Expand Down

0 comments on commit ed56a9d

Please sign in to comment.