Skip to content

Commit d279da2

Browse files
author
mtctx
committed
Updated licenses in ProjectBuilder, changed from withType to maybeCreate
1 parent 7137a26 commit d279da2

File tree

4 files changed

+61
-63
lines changed

4 files changed

+61
-63
lines changed

README.md

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ unipub {
106106
inceptionYear = "2025"
107107
url = "https://github.com/example/awesome-lib"
108108
109-
licenses = listOf(License.APACHE_2_0)
109+
licenses(License.APACHE_2_0)
110110
111111
scm {
112112
url = "https://github.com/example/awesome-lib"
@@ -153,10 +153,7 @@ unipub {
153153
url = "https://github.com/corporate/awesome-library"
154154
155155
// Multiple licenses
156-
licenses = listOf(
157-
License.APACHE_2_0,
158-
License.MIT
159-
)
156+
licenses(License.APACHE_2_0, License.MIT)
160157
161158
scm {
162159
url = "https://github.com/corporate/awesome-library"

build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ plugins {
2525
}
2626

2727
group = "dev.mtctx.unipub"
28-
version = "1.0.12"
28+
version = "1.0.13"
2929

3030
repositories {
3131
mavenCentral()

src/main/kotlin/dev/mtctx/unipub/UniPub.kt

Lines changed: 55 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ import org.gradle.api.publish.maven.tasks.PublishToMavenRepository
3131
import org.gradle.kotlin.dsl.create
3232
import org.gradle.kotlin.dsl.getByType
3333
import org.gradle.kotlin.dsl.register
34-
import org.gradle.kotlin.dsl.withType
3534
import org.gradle.plugins.signing.SigningExtension
3635
import java.io.File
3736
import java.nio.file.Paths
@@ -156,69 +155,69 @@ class UniPub : Plugin<Project> {
156155
}
157156
}
158157

159-
publications.withType<MavenPublication> {
160-
groupId = projectInfo.groupId
161-
artifactId = projectInfo.id
162-
version = projectInfo.version
163-
164-
artifactInfos.forEach { artifactInfo ->
165-
when (artifactInfo) {
166-
is ArtifactInfo.Component -> {
167-
val component = components.findByName(artifactInfo.componentName)
168-
if (component != null) {
169-
from(component)
170-
} else {
171-
logger.warn("Component '${artifactInfo.componentName}' not found during publication")
172-
}
173-
}
158+
val publication = publications.maybeCreate("mavenJava", MavenPublication::class.java)
159+
160+
publication.groupId = projectInfo.groupId
161+
publication.artifactId = projectInfo.id
162+
publication.version = projectInfo.version
174163

175-
is ArtifactInfo.Task ->
176-
try {
177-
artifact(artifactInfo.task)
178-
} catch (e: UnknownTaskException) {
179-
logger.error("Task not found: ${artifactInfo.task.name}")
180-
logger.trace("Stacktrace: ", e)
181-
}
182-
183-
is ArtifactInfo.File ->
184-
artifact(artifactInfo.file) {
185-
artifactInfo.classifier?.let { classifier = it }
186-
}
187-
188-
is ArtifactInfo.Custom ->
189-
artifactInfo.configure(this)
164+
artifactInfos.forEach { artifactInfo ->
165+
when (artifactInfo) {
166+
is ArtifactInfo.Component -> {
167+
val component = components.findByName(artifactInfo.componentName)
168+
if (component != null) {
169+
publication.from(component)
170+
} else {
171+
logger.warn("Component '${artifactInfo.componentName}' not found during publication")
172+
}
190173
}
174+
175+
is ArtifactInfo.Task ->
176+
try {
177+
publication.artifact(artifactInfo.task)
178+
} catch (e: UnknownTaskException) {
179+
logger.error("Task not found: ${artifactInfo.task.name}")
180+
logger.trace("Stacktrace: ", e)
181+
}
182+
183+
is ArtifactInfo.File ->
184+
publication.artifact(artifactInfo.file) {
185+
artifactInfo.classifier?.let { classifier = it }
186+
}
187+
188+
is ArtifactInfo.Custom ->
189+
artifactInfo.configure(publication)
191190
}
191+
}
192192

193-
pom {
194-
name.set(projectInfo.name)
195-
description.set(projectInfo.description)
196-
inceptionYear.set(projectInfo.inceptionYear)
197-
url.set(projectInfo.url)
198-
licenses {
199-
projectInfo.licenses.forEach { licenseInfo ->
200-
license {
201-
name.set(licenseInfo.name)
202-
url.set(licenseInfo.url)
203-
distribution.set(licenseInfo.distribution.value)
204-
}
193+
publication.pom {
194+
name.set(projectInfo.name)
195+
description.set(projectInfo.description)
196+
inceptionYear.set(projectInfo.inceptionYear)
197+
url.set(projectInfo.url)
198+
licenses {
199+
projectInfo.licenses.forEach { licenseInfo ->
200+
license {
201+
name.set(licenseInfo.name)
202+
url.set(licenseInfo.url)
203+
distribution.set(licenseInfo.distribution.value)
205204
}
206205
}
207-
developers {
208-
developerInfos.forEach { developerInfo ->
209-
developer {
210-
name.set(developerInfo.name)
211-
email.set(developerInfo.email)
212-
organization.set(developerInfo.organization)
213-
organizationUrl.set(developerInfo.organizationUrl)
214-
}
206+
}
207+
developers {
208+
developerInfos.forEach { developerInfo ->
209+
developer {
210+
name.set(developerInfo.name)
211+
email.set(developerInfo.email)
212+
organization.set(developerInfo.organization)
213+
organizationUrl.set(developerInfo.organizationUrl)
215214
}
216215
}
217-
scm {
218-
url.set(projectInfo.scm.url)
219-
connection.set(projectInfo.scm.connection)
220-
developerConnection.set(projectInfo.scm.developerConnection)
221-
}
216+
}
217+
scm {
218+
url.set(projectInfo.scm.url)
219+
connection.set(projectInfo.scm.connection)
220+
developerConnection.set(projectInfo.scm.developerConnection)
222221
}
223222
}
224223
}

src/main/kotlin/dev/mtctx/unipub/dsl/DSL.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,11 @@ class ProjectBuilder {
5656
var inceptionYear: String = ""
5757
var groupId: String = ""
5858
var url: String = ""
59-
var licenses: List<License> = emptyList()
59+
private var licenses: MutableList<License> = mutableListOf()
6060
private var scmBuilder: ScmBuilder? = null
6161

62+
fun licenses(vararg licenses: License) = this.licenses.addAll(licenses)
63+
6264
fun scm(block: ScmBuilder.() -> Unit) {
6365
val builder = ScmBuilder()
6466
builder.block()

0 commit comments

Comments
 (0)