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

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

import org.gradle.work.DisableCachingByDefault

if (project.isBuildSrcProject) return

allprojects {
    pluginManager.withPlugin('java-gradle-plugin') {
        if (project.ext.find('javaGradlePluginWithoutPublish')) {
            gradlePlugin.automatedPublishing = false
            return
        }


        apply plugin: 'com.gradle.plugin-publish'

        gradlePlugin {
            website = property('repository-html-url')
            vcsUrl = property('repository-html-url')
            plugins.all {
                tags.set(
                    property('repository-topics').toString().split(/,/)
                        .collect { it.trim().toLowerCase() }
                        .findAll { !it.isEmpty() }
                        .findAll { it != 'gradle' && it != 'plugin' && it != 'gradle-plugin' }
                )
            }
        }

        if (project.isRunningOnCi) {
            TaskProvider validatePluginProperties = tasks.register('validatePluginProperties', ValidatePluginProperties)
            tasks.named('check').configure { dependsOn(validatePluginProperties) }
        }

        pluginManager.withPlugin('maven-publish') {
            afterEvaluate {
                publishing.publications.withType(MavenPublication).findAll({ it.component != null }).forEach { pub ->
                    MavenArtifactSet artifacts = pub.artifacts
                    ['sources', 'javadoc', 'groovydoc'].forEach { classifier ->
                        if (!artifacts.any { it.classifier == classifier }) {
                            Jar jarTask = tasks.withType(Jar).find { it.archiveClassifier.getOrNull() == classifier }
                            if (jarTask != null) {
                                pub.artifact(jarTask)
                            }
                        }
                    }
                }
            }
        }

        pluginManager.withPlugin('name.remal.generate-sources') {
            tasks.matching { it.name == 'publishPluginJar' }.configureEach {
                Set generateTasks = [
                    'generateResources',
                    'generateJava',
                    'generateKotlin',
                    'generateGroovy',
                ].toSet()
                dependsOn(
                    tasks.matching { generateTasks.contains(it.name) }
                )
            }
        }
    }
}


File flagFile = project.layout.buildDirectory.file('publish-gradle-plugin.flag').get().asFile
flagFile.delete()
allprojects {
    pluginManager.withPlugin('com.gradle.plugin-publish') {
        flagFile.parentFile.mkdirs()
        flagFile.text = ''
    }
}

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

@DisableCachingByDefault(because = "Should not be cached")
class ValidatePluginProperties extends DefaultTask implements VerificationTask {

    ValidatePluginProperties() {
        outputs.upToDateWhen { false }
        group = "Plugin development"
    }

    @TaskAction
    void execute() {
        if (project.gradlePlugin.website.orNull?.isEmpty() != false) {
            throw new GradleException("Website can't be empty for Gradle plugins")
        }
        if (project.gradlePlugin.vcsUrl.orNull?.isEmpty() != false) {
            throw new GradleException("VCS URL can't be empty for Gradle plugins")
        }
        project.gradlePlugin.plugins.forEach { plugin ->
            if (plugin.tags.orNull?.isEmpty() != false) {
                throw new GradleException("Gradle plugin `${plugin.id}` has empty tags")
            }
        }
    }

    @Override
    void setIgnoreFailures(boolean ignoreFailures) {
        // do nothing
    }

    @Override
    boolean getIgnoreFailures() {
        return false
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy