@@ -31,7 +31,6 @@ import org.gradle.api.publish.maven.tasks.PublishToMavenRepository
3131import org.gradle.kotlin.dsl.create
3232import org.gradle.kotlin.dsl.getByType
3333import org.gradle.kotlin.dsl.register
34- import org.gradle.kotlin.dsl.withType
3534import org.gradle.plugins.signing.SigningExtension
3635import java.io.File
3736import 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 }
0 commit comments