All Downloads are FREE. Search and download functionalities are using the official Maven repository.

name.remal.gradle_plugins.toolkit.build_logic.publish-maven-bom.gradle Maven / Gradle / Ivy

import org.w3c.dom.Document
import org.w3c.dom.Element
import org.w3c.dom.Node

if (project.isBuildSrcProject) return

allprojects {
    rootProject.evaluationDependsOnChildren()
    pluginManager.withPlugin('maven-publish') {
        if (project != rootProject) {
            rootProject.pluginManager.apply('maven-publish')
            return
        }

        publishing.publications.create('mavenBom', MavenPublication) { MavenPublication publication ->
            publication.artifactId = publication.artifactId?.replaceFirst(/-root$/, '') + '-bom'

            publication.pom { MavenPom pom ->
                String prevName = pom.name.get()
                pom.name = "${prevName}: BOM"
                pom.description = "${prevName}: Bill of Materials (BOM)"
                pom.withXml {
                    Element root = asElement()
                    Document document = root.ownerDocument
                    Node dependencyManagement = root.appendChild(document.createElement("dependencyManagement"))
                    Node dependencies = dependencyManagement.appendChild(document.createElement("dependencies"))
                    List otherPublications = allprojects
                        .findAll { it.pluginManager.hasPlugin('maven-publish') }
                        .collect { it.publishing.publications.withType(MavenPublication).collect() }
                        .flatten()
                        .findAll { it !== publication }
                    for (MavenPublication otherPublication : otherPublications) {
                        Node dependency = dependencies.appendChild(document.createElement("dependency"))
                        dependency.appendChild(document.createElement("groupId"))
                            .setTextContent(otherPublication.groupId)
                        dependency.appendChild(document.createElement("artifactId"))
                            .setTextContent(otherPublication.artifactId)
                        dependency.appendChild(document.createElement("version"))
                            .setTextContent(otherPublication.version)
                    }
                }
            }
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy