Skip to content

Commit

Permalink
Move setupPublishing(...)
Browse files Browse the repository at this point in the history
  • Loading branch information
srnyx committed Jun 20, 2023
1 parent 33ff4e2 commit ba403e3
Showing 1 changed file with 86 additions and 86 deletions.
172 changes: 86 additions & 86 deletions src/main/kotlin/xyz/srnyx/gradlegalaxy/utility/Scripts.kt
Original file line number Diff line number Diff line change
Expand Up @@ -148,92 +148,6 @@ fun Project.relocate(
tasks.named<ShadowJar>("shadowJar") { relocate(from, to) }
}

/**
* Sets up a simple publishing configuration
*
* 1. Applies the `maven-publish` plugin
* 2. Creates a [MavenPublication] with the specified parameters
* 3. Configures the [MavenPublication] with the specified [configuration]
*
* @param groupId The group ID
* @param artifactId The artifact ID
* @param version The version
* @param component The [SoftwareComponent] to publish
* @param artifacts The artifacts to publish
* @param name The name of the project
* @param description The description of the project
* @param url The URL of the project
* @param licenses The licenses of the project
* @param developers The developers of the project
* @param scm The SCM information of the project
* @param configuration The configuration of the [MavenPublication]
*
* @return The [MavenPublication] that was created
*/
@Ignore
inline fun Project.setupPublishing(
groupId: String? = null,
artifactId: String? = null,
version: String? = null,
withJavadocSourcesJars: Boolean = true,
component: SoftwareComponent? = components["java"],
artifacts: Collection<Any> = emptyList(),
name: String? = project.name,
description: String? = project.description,
url: String? = null,
licenses: List<LicenseData> = emptyList(),
developers: List<DeveloperData> = emptyList(),
scm: ScmData? = null,
crossinline configuration: MavenPublication.() -> Unit = {}
): MavenPublication {
apply(plugin = "maven-publish")
if (withJavadocSourcesJars) addJavadocSourcesJars()
return (extensions["publishing"] as PublishingExtension).publications.create<MavenPublication>("maven") {
groupId?.let { this.groupId = it }
artifactId?.let { this.artifactId = it }
version?.let { this.version = it }
component?.let { this.from(component) }
artifacts.forEach(this::artifact)
pom {
name?.let(this.name::set)
description?.let(this.description::set)
url?.let(this.url::set)
licenses {
licenses.forEach {
license {
this.name.set(it.name)
this.url.set(it.url)
it.distribution?.value?.let(this.distribution::set)
it.comments?.let(this.comments::set)
}
}
}
developers {
developers.filterNot(DeveloperData::isEmpty).forEach {
developer {
it.id?.let(this.id::set)
it.name?.let(this.name::set)
it.url?.let(this.url::set)
it.email?.let(this.email::set)
it.timezone?.let(this.timezone::set)
it.organization?.let(this.organization::set)
it.organizationUrl?.let(this.organizationUrl::set)
it.roles.takeIf(List<String>::isNotEmpty)?.let(this.roles::set)
it.properties.takeIf(Map<String, String>::isNotEmpty)?.let(this.properties::set)
}
}
}
if (scm != null) scm {
connection.set(scm.connection)
developerConnection.set(scm.developerConnection)
scm.url?.let(this.url::set)
scm.tag?.let(this.tag::set)
}
}
configuration()
}
}

/**
* Sets up the project with the specified [group] and [version] for a simple Java project
*
Expand Down Expand Up @@ -328,3 +242,89 @@ fun Project.setupAnnoyingAPI(
dependencies { add("implementation", "xyz.srnyx:annoying-api:$annoyingAPIVersion") }
relocate("xyz.srnyx.annoyingapi")
}

/**
* Sets up a simple publishing configuration
*
* 1. Applies the `maven-publish` plugin
* 2. Creates a [MavenPublication] with the specified parameters
* 3. Configures the [MavenPublication] with the specified [configuration]
*
* @param groupId The group ID
* @param artifactId The artifact ID
* @param version The version
* @param component The [SoftwareComponent] to publish
* @param artifacts The artifacts to publish
* @param name The name of the project
* @param description The description of the project
* @param url The URL of the project
* @param licenses The licenses of the project
* @param developers The developers of the project
* @param scm The SCM information of the project
* @param configuration The configuration of the [MavenPublication]
*
* @return The [MavenPublication] that was created
*/
@Ignore
inline fun Project.setupPublishing(
groupId: String? = null,
artifactId: String? = null,
version: String? = null,
withJavadocSourcesJars: Boolean = true,
component: SoftwareComponent? = components["java"],
artifacts: Collection<Any> = emptyList(),
name: String? = project.name,
description: String? = project.description,
url: String? = null,
licenses: List<LicenseData> = emptyList(),
developers: List<DeveloperData> = emptyList(),
scm: ScmData? = null,
crossinline configuration: MavenPublication.() -> Unit = {}
): MavenPublication {
apply(plugin = "maven-publish")
if (withJavadocSourcesJars) addJavadocSourcesJars()
return (extensions["publishing"] as PublishingExtension).publications.create<MavenPublication>("maven") {
groupId?.let { this.groupId = it }
artifactId?.let { this.artifactId = it }
version?.let { this.version = it }
component?.let { this.from(component) }
artifacts.forEach(this::artifact)
pom {
name?.let(this.name::set)
description?.let(this.description::set)
url?.let(this.url::set)
licenses {
licenses.forEach {
license {
this.name.set(it.name)
this.url.set(it.url)
it.distribution?.value?.let(this.distribution::set)
it.comments?.let(this.comments::set)
}
}
}
developers {
developers.filterNot(DeveloperData::isEmpty).forEach {
developer {
it.id?.let(this.id::set)
it.name?.let(this.name::set)
it.url?.let(this.url::set)
it.email?.let(this.email::set)
it.timezone?.let(this.timezone::set)
it.organization?.let(this.organization::set)
it.organizationUrl?.let(this.organizationUrl::set)
it.roles.takeIf(List<String>::isNotEmpty)?.let(this.roles::set)
it.properties.takeIf(Map<String, String>::isNotEmpty)?.let(this.properties::set)
}
}
}
if (scm != null) scm {
connection.set(scm.connection)
developerConnection.set(scm.developerConnection)
scm.url?.let(this.url::set)
scm.tag?.let(this.tag::set)
}
}
configuration()
}
}

0 comments on commit ba403e3

Please sign in to comment.