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

name.remal.gradle_plugins.toolkit.build_logic.dependencies.gradle Maven / Gradle / Ivy

allprojects {
    configurations.create('projectDependencyConstraints') { Configuration conf ->
        conf.canBeResolved = false
        conf.canBeConsumed = false

        conf.dependencies.whenObjectAdded { Dependency dep ->
            List sameDeps = conf.dependencies.toList()
                .findAll { "${it.group}:${it.name}" == "${dep.group}:${dep.name}" }
            List strictDeps = sameDeps
                .findAll { it instanceof ExternalDependency }
                .collect { (ExternalDependency) it }
                .findAll { !(it.versionConstraint.strictVersion ?: '').isEmpty() }
            if (!strictDeps.isEmpty()) {
                ExternalDependency strictDep = strictDeps.last()
                conf.dependencies.removeIf { sameDeps.contains(it) && it !== strictDep }
            } else {
                Dependency sameDep = sameDeps.last()
                conf.dependencies.removeIf { sameDeps.contains(it) && it !== sameDep }
            }
        }

        conf.dependencyConstraints.whenObjectAdded { DependencyConstraint constraint ->
            List sameConstraints = conf.dependencyConstraints.toList()
                .findAll { "${it.group}:${it.name}" == "${constraint.group}:${constraint.name}" }
            List strictConstraints = sameConstraints
                .findAll { !(it.versionConstraint.strictVersion ?: '').isEmpty() }
            if (!strictConstraints.isEmpty()) {
                DependencyConstraint strictConstraint = strictConstraints.last()
                conf.dependencyConstraints.removeIf { sameConstraints.contains(it) && it !== strictConstraint }
            } else {
                DependencyConstraint sameConstraint = sameConstraints.last()
                conf.dependencyConstraints.removeIf { sameConstraints.contains(it) && it !== sameConstraint }
            }
        }

        conf.dependencies.addAll(
            [
                'org.ow2.asm:asm-bom:9.7.1',
            ].collect { project.dependencies.platform(it) }
        )

        conf.dependencyConstraints.addAll(
            [
                // Compile
                "name.remal.gradle-api:local-groovy:${project.gradleApiVersion.version}",
                "name.remal.gradle-api:gradle-api:${project.gradleApiVersion.version}",

                // Test
                "name.remal.gradle-api:gradle-test-kit:${project.gradleApiVersion.version}",
            ].collect {
                project.dependencies.constraints.create(it) { DependencyConstraint constraint ->
                    constraint.version { it.strictly(constraint.version) }
                }
            }
        )

        conf.visible = false
        conf.canBeConsumed = false
        conf.canBeResolved = false
        conf.description = "Dependency constraints"

        configurations
            .matching { it !== conf }
            .configureEach { extendsFrom(conf) }
    }

    dependencies {
        components.all(GradleApiAlignmentRule)
        components.all(ErrorproneAlignmentRule)
        components.all(SpotBugsAlignmentRule)
        components.all(JacocoAlignmentRule)
    }
}

class GradleApiAlignmentRule implements ComponentMetadataRule {
    void execute(ComponentMetadataContext context) {
        context.details.with {
            if (id.group == 'name.remal.gradle-api') {
                belongsTo("${id.group}:bom:${id.version}")
            }
        }
    }
}

class ErrorproneAlignmentRule implements ComponentMetadataRule {
    void execute(ComponentMetadataContext context) {
        context.details.with {
            if (id.group == 'com.google.errorprone') {
                if (id.name == 'error_prone_check_api'
                    || id.name == 'error_prone_test_helpers'
                    || id.name == 'error_prone_core'
                    || id.name == 'error_prone_annotation'
                    || id.name == 'error_prone_annotations'
                    || id.name == 'error_prone_type_annotations'
                    || id.name == 'error_prone_docgen'
                    || id.name == 'error_prone_docgen_processor'
                    || id.name == 'error_prone_refaster'
                ) {
                    belongsTo("${id.group}:bom:${id.version}")
                }
            }
        }
    }
}

class SpotBugsAlignmentRule implements ComponentMetadataRule {
    void execute(ComponentMetadataContext context) {
        context.details.with {
            if (id.group == 'com.github.spotbugs') {
                if (id.name == 'spotbugs'
                    || id.name == 'spotbugs-annotations'
                    || id.name == 'spotbugs-ant'
                ) {
                    belongsTo("${id.group}:bom:${id.version}")
                }
            }
        }
    }
}

class JacocoAlignmentRule implements ComponentMetadataRule {
    void execute(ComponentMetadataContext context) {
        context.details.with {
            if (id.group == 'org.jacoco') {
                belongsTo("${id.group}:bom:${id.version}")
            }
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy