Skip to content

Commit

Permalink
Added developer information for POM
Browse files Browse the repository at this point in the history
  • Loading branch information
squid233 committed Nov 17, 2023
1 parent f8b04e7 commit ced902b
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 19 deletions.
60 changes: 43 additions & 17 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,38 @@ plugins {
`java-library`
signing
`maven-publish`
//application
}

data class ProjPublication(
data class PublicationRepo(
val name: String,
val usernameFrom: String,
val passwordFrom: String,
val usernameFrom: List<String>,
val passwordFrom: List<String>,
val snapshotRepo: String,
val releaseRepo: String,
val snapshotPredicate: (String) -> Boolean = { it.endsWith("-SNAPSHOT") }
)

val hasPublication: String by rootProject
val publicationSigning: String by rootProject
val publication: ProjPublication? = if (hasPublication.toBoolean()) ProjPublication(
val publicationRepo: PublicationRepo? = if (hasPublication.toBoolean()) PublicationRepo(
name = "OSSRH",
usernameFrom = "OSSRH_USERNAME",
passwordFrom = "OSSRH_PASSWORD",
usernameFrom = listOf("OSSRH_USERNAME", "ossrhUsername"),
passwordFrom = listOf("OSSRH_PASSWORD", "ossrhPassword"),
snapshotRepo = "https://s01.oss.sonatype.org/content/repositories/snapshots/",
releaseRepo = "https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/"
) else null

data class Developer(
val id: String,
val name: String? = null,
val email: String? = null
)

val projDevelopers = arrayOf(
Developer("example")
)

val hasJavadocJar: String by rootProject
val hasSourcesJar: String by rootProject

Expand Down Expand Up @@ -53,11 +64,11 @@ version = projVersion
repositories {
mavenCentral()
// snapshot repositories
// maven { url = uri("https://oss.sonatype.org/content/repositories/snapshots") }
// maven { url = uri("https://s01.oss.sonatype.org/content/repositories/snapshots") }
//maven { url = uri("https://oss.sonatype.org/content/repositories/snapshots") }
//maven { url = uri("https://s01.oss.sonatype.org/content/repositories/snapshots") }

// maven { url = uri("https://oss.oss.sonatype.org/content/repositories/releases") }
// maven { url = uri("https://s01.oss.sonatype.org/content/repositories/releases") }
//maven { url = uri("https://oss.oss.sonatype.org/content/repositories/releases") }
//maven { url = uri("https://s01.oss.sonatype.org/content/repositories/releases") }
}

dependencies {
Expand Down Expand Up @@ -103,6 +114,11 @@ tasks.withType<Javadoc> {
}
}

//application {
// applicationName = projName
// mainClass = "org.example.Main"
//}

tasks.named<Jar>("jar") {
manifestContentCharset = "utf-8"
setMetadataCharset("utf-8")
Expand All @@ -113,6 +129,7 @@ tasks.named<Jar>("jar") {
"Implementation-Title" to projName,
"Implementation-Vendor" to orgName,
"Implementation-Version" to projVersion
//"Main-Class" to "org.example.Main"
)
}

Expand All @@ -138,7 +155,7 @@ tasks.withType<Jar> {
from(projLicenseFileName).rename { "${projLicenseFileName}_$projArtifactId" }
}

if (hasPublication.toBoolean() && publication != null) {
if (hasPublication.toBoolean() && publicationRepo != null) {
publishing.publications {
register<MavenPublication>("mavenJava") {
groupId = projGroupId
Expand All @@ -160,6 +177,15 @@ if (hasPublication.toBoolean() && publication != null) {
name = orgName
url = orgUrl
}
developers {
projDevelopers.forEach {
developer {
id = it.id
it.name?.also { name = it }
it.email?.also { email = it }
}
}
}
scm {
projScmConnection?.also {
connection = it
Expand All @@ -173,20 +199,20 @@ if (hasPublication.toBoolean() && publication != null) {

publishing.repositories {
maven {
name = publication.name
name = publicationRepo.name
credentials {
username = rootProject.findProperty(publication.usernameFrom).toString()
password = rootProject.findProperty(publication.passwordFrom).toString()
username = publicationRepo.usernameFrom.firstNotNullOf { rootProject.findProperty(it) }.toString()
password = publicationRepo.passwordFrom.firstNotNullOf { rootProject.findProperty(it) }.toString()
}
url = uri(
if (publication.snapshotPredicate(projVersion)) publication.snapshotRepo
else publication.releaseRepo
if (publicationRepo.snapshotPredicate(projVersion)) publicationRepo.snapshotRepo
else publicationRepo.releaseRepo
)
}
}

signing {
if (!publication.snapshotPredicate(projVersion) && publicationSigning.toBoolean()) {
if (!publicationRepo.snapshotPredicate(projVersion) && publicationSigning.toBoolean()) {
sign(publishing.publications["mavenJava"])
}
}
Expand Down
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ hasSourcesJar=false
# Project Information
projGroupId=org.example
projArtifactId=example
# Name should only contain lowercase letters and hyphen.
projName=example
# The project ame should only contain lowercase letters, numbers and hyphen.
projName=project-template
projVersion=0.1.0-SNAPSHOT
projDesc=An example project.
# Uncomment them if you want to publish to maven repository.
Expand Down

0 comments on commit ced902b

Please sign in to comment.