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

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

There is a newer version: 0.64.11
Show newest version
if (project.isBuildSrcProject) return

allprojects {
    pluginManager.withPlugin('com.gradle.plugin-publish') {
        apply plugin: 'maven-publish'
    }

    pluginManager.withPlugin('maven-publish') {
        apply plugin: 'java'

        publishing.publications.withType(MavenPublication).configureEach {
            versionMapping {
                usage('java-api') { fromResolutionOf('compileClasspath') }
                usage('java-runtime') { fromResolutionOf('runtimeClasspath') }
            }

            moduleDescriptorGenerator = null

            pom {
                String displayName = property('repository-name')
                String ownerName = property('repository-owner-name')
                if (!ownerName.isEmpty()) {
                    displayName = "$ownerName: $displayName"
                }
                String subProjectName = project.path.substring(1).replace(':', ': ')
                if (!subProjectName.isEmpty()) {
                    displayName = "$displayName: $subProjectName"
                }

                name = displayName
                description = displayName
                url = property('repository-html-url')
                scm {
                    url = property('repository-html-url')
                }
                licenses {
                    license {
                        name = property('repository-license-name')
                        url = property('repository-license-html-url')
                    }
                }
                developers {
                    developer {
                        name = 'Semyon Levin'
                        email = '[email protected]'
                        id = email
                    }
                }

                withXml { XmlProvider xml ->
                    Node rootNode = xml.asNode()

                    Collection groupIdsToRemove = [
                        'name.remal.gradle-api',
                    ]
                    rootNode.dependencyManagement?.dependencies?.dependency?.forEach { Node dependency ->
                        if (groupIdsToRemove.contains(dependency.groupId?.text()?.trim() ?: '')) {
                            dependency.replaceNode {}
                        }
                    }
                    rootNode.dependencies?.dependency?.forEach { Node dependency ->
                        if (groupIdsToRemove.contains(dependency.groupId?.text()?.trim() ?: '')) {
                            dependency.replaceNode {}
                        }
                    }
                }
            }
        }

        afterEvaluate {
            if (pluginManager.hasPlugin('java-library')
                && !pluginManager.hasPlugin('com.gradle.plugin-publish')
            ) {
                java {
                    withJavadocJar()
                    withSourcesJar()
                }

                publishing.publications.create('mavenJavaLibrary', MavenPublication) {
                    from components.java
                }
            }
        }

        tasks.withType(GenerateModuleMetadata).configureEach { enabled = false }

        pluginManager.withPlugin('signing') {
            signing {
                sign publishing.publications
            }
        }

        pluginManager.withPlugin('java-test-fixtures') {
            publishing.publications.withType(MavenPublication).configureEach {
                suppressPomMetadataWarningsFor('testFixturesApiElements')
                suppressPomMetadataWarningsFor('testFixturesRuntimeElements')
            }
        }
    }

    tasks.register('generateAllPoms') {
        group = 'publishing'
        dependsOn(tasks.withType(GenerateMavenPom))
    }

    tasks.withType(AbstractPublishToMaven).configureEach {
        mustRunAfter(
            project.provider {
                project.rootProject.allprojects
                    .collect {
                        it.tasks.matching {
                            return (
                                it.name == 'jar'
                                    || it.name == 'sourcesJar'
                                    || it.name == 'javadocJar'
                                    || it.name == 'allTests'
                                    || it instanceof AbstractCompile
                                    || it instanceof Javadoc
                                    || it instanceof Sign
                                    || project.isVerificationTask(it)
                            )
                        }
                    }
                    .flatten()
                    .toList()
            }
        )
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy