From 6b65c453862e1fe52be54fa2e7ff9228daf2fe52 Mon Sep 17 00:00:00 2001 From: lukstbit <52494258+lukstbit@users.noreply.github.com> Date: Wed, 14 Jun 2023 13:31:02 +0300 Subject: [PATCH] Use plugins block to declare the plugins used See https://docs.gradle.org/current/userguide/plugins.html#sec:plugins_block The plugins that are to be used in different modules are added in the top level build file with apply "false"(doesn't make sense to apply them on the root project). Then the project modules, from the plugins already available on the classpath, actually apply the ones they need. Ktlint plugin was applied directly to all subprojects(initially it was added through allprojects {} but it doesn't make sense to add it to the root project as it doesn't contain source code, so subprojects{} was used instead). The amazonappstorepublisher plugin also required some custom configuration as we need the latest versions which are not available in mavenCentral() but can be fetched from jitpack.io. --- AnkiDroid/build.gradle | 18 ++++++++---------- build.gradle | 35 +++++++++++------------------------ lint-rules/build.gradle | 4 +++- settings.gradle.kts | 8 ++++++++ 4 files changed, 30 insertions(+), 35 deletions(-) diff --git a/AnkiDroid/build.gradle b/AnkiDroid/build.gradle index 7fa0cba90b..ac0cc90bbc 100644 --- a/AnkiDroid/build.gradle +++ b/AnkiDroid/build.gradle @@ -1,16 +1,14 @@ plugins { - // Gradle plugin portal - id 'com.github.triplet.play' version '3.8.4' - id 'org.jetbrains.kotlin.plugin.serialization' version '1.9.10' + // Gradle plugin portal + id 'com.github.triplet.play' version '3.8.4' + id 'com.android.application' + id 'app.brant.amazonappstorepublisher' + id 'idea' + id 'kotlin-android' + id 'kotlin-parcelize' + id 'org.jetbrains.kotlin.plugin.serialization' } -apply plugin: 'com.android.application' -apply plugin: 'app.brant.amazonappstorepublisher' -apply plugin: 'idea' -apply plugin: 'kotlin-android' -apply plugin: 'kotlin-parcelize' - - repositories { google() mavenCentral() diff --git a/build.gradle b/build.gradle index 45985ae35a..03f5cb4fb8 100644 --- a/build.gradle +++ b/build.gradle @@ -1,7 +1,6 @@ import org.gradle.internal.jvm.Jvm // Top-level build file where you can add configuration options common to all sub-projects/modules. - buildscript { // The version for the Kotlin plugin and dependencies // If changing this, make sure to update org.jetbrains.kotlin.plugin.serialization version too @@ -17,23 +16,8 @@ buildscript { ext.androidx_test_version = '1.5.0' ext.androidx_test_junit_version = '1.1.5' ext.robolectric_version = '4.10.3' + ext.android_gradle_plugin = "8.0.2" - repositories { - google() - maven { - url "https://plugins.gradle.org/m2/" - } - maven { url 'https://jitpack.io' } - } - dependencies { - classpath 'com.android.tools.build:gradle:8.0.2' - // NOTE: Do not place your application dependencies here; they belong - // in the individual module build.gradle files - classpath "com.github.BrantApps.gradle-amazon-app-store-publisher:amazonappstorepublisher:master-SNAPSHOT" - - classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" - classpath "org.jlleitschuh.gradle:ktlint-gradle:11.5.1" - } configurations.all { resolutionStrategy.eachDependency { details -> if (details.requested.group == 'org.jetbrains.kotlinx' @@ -45,12 +29,14 @@ buildscript { } } -repositories { - mavenCentral() -} - -allprojects { - apply plugin: "org.jlleitschuh.gradle.ktlint" +plugins { + id 'com.android.application' version "$android_gradle_plugin" apply false + id 'com.android.library' version "$android_gradle_plugin" apply false + id 'org.jetbrains.kotlin.jvm' version "$kotlin_version" apply false + id 'org.jetbrains.kotlin.android' version "$kotlin_version" apply false + id 'org.jetbrains.kotlin.plugin.parcelize' version "$kotlin_version" apply false + id 'org.jetbrains.kotlin.plugin.serialization' version "$kotlin_version" apply false + id 'org.jlleitschuh.gradle.ktlint' version '11.5.1' apply false } Properties localProperties = new Properties() @@ -61,8 +47,9 @@ Boolean fatalWarnings = !(localProperties['fatal_warnings'] == "false") // Here we extract per-module "best practices" settings to a single top-level evaluation subprojects { - afterEvaluate { project -> + apply plugin: "org.jlleitschuh.gradle.ktlint" + afterEvaluate { project -> if (project.hasProperty('android')) { project.android.testOptions.unitTests { includeAndroidResources = true diff --git a/lint-rules/build.gradle b/lint-rules/build.gradle index 23345005aa..6b524ecf1b 100644 --- a/lint-rules/build.gradle +++ b/lint-rules/build.gradle @@ -1,4 +1,6 @@ -apply plugin: 'kotlin' +plugins { + id 'kotlin' +} repositories { google() diff --git a/settings.gradle.kts b/settings.gradle.kts index 526188e522..c763be0d28 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -5,6 +5,14 @@ pluginManagement { mavenCentral() maven(url = "https://jitpack.io") // only needed for the "amazonappstorepublisher" plugin } + resolutionStrategy { + // TODO try to find another plugin for this functionality? + eachPlugin { + if (requested.id.id == "app.brant.amazonappstorepublisher") { + useModule("com.github.BrantApps.gradle-amazon-app-store-publisher:amazonappstorepublisher:master-SNAPSHOT") + } + } + } } include(":lint-rules", ":api", ":AnkiDroid")