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

name.remal.gradle_plugins.toolkit.build_logic.BuildLogicPlugin Maven / Gradle / Ivy

package name.remal.gradle_plugins.toolkit.build_logic;

import static java.lang.String.format;
import static name.remal.gradle_plugins.toolkit.ObjectUtils.unwrapProviders;
import static name.remal.gradle_plugins.toolkit.ResourceUtils.getResourceUrl;

import lombok.val;
import org.gradle.api.Plugin;
import org.gradle.api.Project;
import org.gradle.util.GradleVersion;

@SuppressWarnings({"checkstyle:LineLength", "checkstyle:RightCurlyAlone", "InjectedReferences"})
public class BuildLogicPlugin implements Plugin {
    public void apply(Project project) {
        val currentGradleVersion = GradleVersion.current().getBaseVersion();
        val minToolkitGradleVersion = GradleVersion.version("6.0").getBaseVersion();
        if (currentGradleVersion.compareTo(minToolkitGradleVersion) < 0) {
            throw new IllegalStateException(format(
                "Current Gradle version is %s, which is less than minimum supported Gradle version by toolkit: %s",
                currentGradleVersion.getVersion(),
                minToolkitGradleVersion.getVersion()
            ));
        }
    
        project.apply(it -> {
            it.from(getResourceUrl("/name/remal/gradle_plugins/toolkit/build_logic/helpers.gradle", BuildLogicPlugin.class));
            it.from(getResourceUrl("/name/remal/gradle_plugins/toolkit/build_logic/properties.gradle", BuildLogicPlugin.class));
            it.from(getResourceUrl("/name/remal/gradle_plugins/toolkit/build_logic/ci.gradle", BuildLogicPlugin.class));
            it.from(getResourceUrl("/name/remal/gradle_plugins/toolkit/build_logic/common.gradle", BuildLogicPlugin.class));
            it.from(getResourceUrl("/name/remal/gradle_plugins/toolkit/build_logic/dependencies.gradle", BuildLogicPlugin.class));
            it.from(getResourceUrl("/name/remal/gradle_plugins/toolkit/build_logic/check-source-dirs.gradle", BuildLogicPlugin.class));
            it.from(getResourceUrl("/name/remal/gradle_plugins/toolkit/build_logic/base-package.gradle", BuildLogicPlugin.class));
            it.from(getResourceUrl("/name/remal/gradle_plugins/toolkit/build_logic/java.gradle", BuildLogicPlugin.class));
            it.from(getResourceUrl("/name/remal/gradle_plugins/toolkit/build_logic/test-external-plugins.gradle", BuildLogicPlugin.class));
            it.from(getResourceUrl("/name/remal/gradle_plugins/toolkit/build_logic/lombok.gradle", BuildLogicPlugin.class));
            it.from(getResourceUrl("/name/remal/gradle_plugins/toolkit/build_logic/errorprone.gradle", BuildLogicPlugin.class));
            it.from(getResourceUrl("/name/remal/gradle_plugins/toolkit/build_logic/classes-relocation.gradle", BuildLogicPlugin.class));
            it.from(getResourceUrl("/name/remal/gradle_plugins/toolkit/build_logic/cross-compile.gradle", BuildLogicPlugin.class));
            it.from(getResourceUrl("/name/remal/gradle_plugins/toolkit/build_logic/groovy.gradle", BuildLogicPlugin.class));
            it.from(getResourceUrl("/name/remal/gradle_plugins/toolkit/build_logic/checkstyle.gradle", BuildLogicPlugin.class));
            it.from(getResourceUrl("/name/remal/gradle_plugins/toolkit/build_logic/sonarlint.gradle", BuildLogicPlugin.class));
            it.from(getResourceUrl("/name/remal/gradle_plugins/toolkit/build_logic/javadoc.gradle", BuildLogicPlugin.class));
            it.from(getResourceUrl("/name/remal/gradle_plugins/toolkit/build_logic/jacoco.gradle", BuildLogicPlugin.class));
            it.from(getResourceUrl("/name/remal/gradle_plugins/toolkit/build_logic/gradle-plugin.gradle", BuildLogicPlugin.class));
            it.from(getResourceUrl("/name/remal/gradle_plugins/toolkit/build_logic/gradle-plugin-collect-api-dependencies.gradle", BuildLogicPlugin.class));
            it.from(getResourceUrl("/name/remal/gradle_plugins/toolkit/build_logic/gradle-plugin-collect-classes-relying-on-dependencies.gradle", BuildLogicPlugin.class));
            it.from(getResourceUrl("/name/remal/gradle_plugins/toolkit/build_logic/publish-gradle-plugin.gradle", BuildLogicPlugin.class));
            it.from(getResourceUrl("/name/remal/gradle_plugins/toolkit/build_logic/publish-maven.gradle", BuildLogicPlugin.class));
            it.from(getResourceUrl("/name/remal/gradle_plugins/toolkit/build_logic/publish-maven-bom.gradle", BuildLogicPlugin.class));
            it.from(getResourceUrl("/name/remal/gradle_plugins/toolkit/build_logic/publish-maven-central.gradle", BuildLogicPlugin.class));
            it.from(getResourceUrl("/name/remal/gradle_plugins/toolkit/build_logic/publish-maven-to-build-dir.gradle", BuildLogicPlugin.class));
            it.from(getResourceUrl("/name/remal/gradle_plugins/toolkit/build_logic/publish-maven-push-back.gradle", BuildLogicPlugin.class));
            it.from(getResourceUrl("/name/remal/gradle_plugins/toolkit/build_logic/signing.gradle", BuildLogicPlugin.class));
            it.from(getResourceUrl("/name/remal/gradle_plugins/toolkit/build_logic/process-readme.gradle", BuildLogicPlugin.class));
            it.from(getResourceUrl("/name/remal/gradle_plugins/toolkit/build_logic/ide.gradle", BuildLogicPlugin.class));
            it.from(getResourceUrl("/name/remal/gradle_plugins/toolkit/build_logic/github-submit-dependencies.gradle", BuildLogicPlugin.class));
            it.from(getResourceUrl("/name/remal/gradle_plugins/toolkit/build_logic/build-performance.gradle", BuildLogicPlugin.class));
        });
    
        Object minPluginGradleVersionUntyped = unwrapProviders(project.findProperty("gradle-api.min-version"));
        if (minPluginGradleVersionUntyped instanceof GradleVersion) {
            minPluginGradleVersionUntyped = ((GradleVersion) minPluginGradleVersionUntyped).getBaseVersion().getVersion();
        }
        if (minPluginGradleVersionUntyped != null) {
            val minPluginGradleVersion = GradleVersion.version(minPluginGradleVersionUntyped.toString()).getBaseVersion();
            if (minPluginGradleVersion.compareTo(minToolkitGradleVersion) < 0) {
                throw new IllegalStateException(format(
                    "Min supported Gradle version by the plugin is %s, which is less than minimum supported Gradle version by toolkit: %s",
                    currentGradleVersion.getVersion(),
                    minToolkitGradleVersion.getVersion()
                ));
            }
        }
    
        project.allprojects(proj ->
            proj.getConfigurations()
                .getByName("projectDependencyConstraints")
                .getDependencies()
                .add(
                    proj.getDependencies().platform("name.remal.gradle-plugins.toolkit:toolkit-bom:0.69.7")
                )
        );
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy