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 }
            }
        }

        String errorproneVersion = '2.33.0'
        String jacocoVersion = '0.8.12'

        conf.dependencies.addAll(
            [
                'org.immutables:bom:2.10.1',
                'org.ow2.asm:asm-bom:9.7',
                'org.junit:junit-bom:5.11.1',
            ].collect { project.dependencies.platform(it) }
        )

        conf.dependencyConstraints.addAll(
            [
                // Static analysis
                'com.google.code.findbugs:jsr305:3.0.2',
                'org.jetbrains:annotations:25.0.0',
                "com.google.errorprone:error_prone_annotations:$errorproneVersion",
                "com.google.errorprone:error_prone_core:$errorproneVersion",
                'com.github.spotbugs:spotbugs-annotations:4.8.6',

                // Annotation processing
                'com.google.auto.service:auto-service:1.1.1',
                'com.google.auto.service:auto-service-annotations:1.1.1',

                // Compile-only
                'name.remal:gradle-plugins-api:1.9.2',
                'org.apache.commons:commons-lang3:3.17.0',
                'org.apache.commons:commons-text:1.12.0',
                'com.google.guava:guava:33.3.1-jre',
                'org.jdom:jdom2:2.0.6.1',

                // 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}",
                'org.assertj:assertj-core:3.26.3',
                "org.jacoco:org.jacoco.agent:$jacocoVersion",
                "org.jacoco:org.jacoco.ant:$jacocoVersion",
                "org.jacoco:org.jacoco.core:$jacocoVersion",
            ].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_core'
                    || id.name == 'error_prone_annotations'
                ) {
                    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 - 2024 Weber Informatics LLC | Privacy Policy