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

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

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

allprojects {
    pluginManager.withPlugin('java-gradle-plugin') {
        configurations.all { Configuration conf ->
            conf.dependencies.all { Dependency dep ->
                if (conf.state != Configuration.State.UNRESOLVED) return
                if (dep instanceof FileCollectionDependency && dep.files.toString() != 'file collection') {
                    conf.dependencies.remove(dep)
                }
            }
        }

        configurations.create('gradleApi') { Configuration conf ->
            conf.canBeResolved = true
            conf.canBeConsumed = false
            conf.description = "Gradle API"
            configurations.optional.extendsFrom(conf)
        }

        dependencies {
            gradleApi 'name.remal.gradle-api:gradle-api'
            testImplementation 'name.remal.gradle-api:gradle-test-kit'
        }


        List> loggingExclusions = [
            [group: 'org.slf4j', module: '*'],
            [group: 'log4j', module: 'log4j'],
            [group: 'commons-logging', module: 'commons-logging'],
            [group: 'org.springframework', module: 'spring-jcl'],
        ]
        sourceSets.configureEach { sourceSet ->
            Collection configurationNames = project.getSourceSetConfigurationNames(sourceSet)
            configurations.matching { configurationNames.contains(it.name) }.configureEach { conf ->
                conf.dependencies.withType(ExternalModuleDependency).configureEach { dep ->
                    if (dep.group != 'name.remal.gradle-api') {
                        loggingExclusions.forEach { dep.exclude(it) }
                    }
                }
                conf.withDependencies { deps ->
                    configurations.gradleApi
                        .resolvedConfiguration
                        .lenientConfiguration
                        .allModuleDependencies
                        .findAll { !it.moduleArtifacts.isEmpty() }
                        .forEach { resolvedDep ->
                            deps.withType(ExternalModuleDependency).configureEach { dep ->
                                if (dep.group != 'name.remal.gradle-api') {
                                    dep.exclude(group: resolvedDep.moduleGroup, module: resolvedDep.moduleName)
                                }
                            }
                        }
                }
            }
        }


        SourceSet functionalTestSourceSet = testSourceSets.create('functionalTest')

        project.file('src/functional').with { dir ->
            if (dir.exists()) {
                throw new GradleException("$dir should be renamed to ${functionalTestSourceSet.name}")
            }
        }

        project.tasks.named(functionalTestSourceSet.name, Test) { Test task ->
            Closure> getPublishToBuildDirTasks = {
                rootProject.allprojects
                    .collect { it.tasks.matching { it.name == 'publishToBuildDir' } }
                    .flatten()
            }

            dependsOn(project.provider { getPublishToBuildDirTasks() })

            onlyIf {
                task.systemProperty(
                    'build-dir-maven-repos',
                    getPublishToBuildDirTasks()
                        .collect { it.outputDir.absolutePath }
                        .toSorted()
                        .join(File.pathSeparator)
                )
                return true
            }
        }


        Closure getCorrespondingKotlinVersion = { project.getGradleApiDependencyVersion('org.jetbrains.kotlin:kotlin-stdlib') }.memoize()

        tasks.withType(Test).configureEach {
            onlyIf {
                String correspondingKotlinVersion = getCorrespondingKotlinVersion()
                systemProperty('corresponding-kotlin.version', correspondingKotlinVersion ?: '')
                return true
            }
        }

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

            conf.defaultDependencies { deps ->
                String correspondingKotlinVersion = getCorrespondingKotlinVersion()
                Dependency kotlinPluginDep = project.dependencies.create(
                    "org.jetbrains.kotlin:kotlin-gradle-plugin:${correspondingKotlinVersion}"
                ) {
                    exclude(group: 'commons-logging', module: 'commons-logging')
                    exclude(group: 'com.google.code.findbugs')
                    exclude(group: 'org.checkerframework')
                    exclude(group: 'com.google.errorprone')
                    exclude(group: 'com.google.j2objc', module: 'j2objc-annotations')

                    attributes {
                        attribute(
                            Usage.USAGE_ATTRIBUTE,
                            objects.named(Usage.class, Usage.JAVA_RUNTIME)
                        )
                        attribute(
                            Category.CATEGORY_ATTRIBUTE,
                            objects.named(Category.class, Category.LIBRARY)
                        )
                    }
                }

                deps.add(kotlinPluginDep)
            }

            conf.extendsFrom = []
            conf.description = 'Kotlin Gradle plugin os the same version, as Kotlin that bundled in the current Gradle instance'
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy