2

Going through the documentation of Gradle's build configuration I can see several conflicts with my build on Android Studio 2020.3.1 using Gradle 7.0.3.

For example, in the documentation is says that allProjects block for repositories settings used by all modules should be added to the root build.gradle while in fact it only allows me to configure modules repositories in the settings.gradle under dependencyResolutionManagement block.

Another example is applying plugins to application modules, in documentations it says the first line should be:

apply plugin: 'com.android.application'

While the one used in my build is:

plugins {
    id 'com.android.application'
}

What I also noticed is that also JitPack uses the same configurations suggested in that documentations page for using a JitPack published library in projects:

Add it in your root build.gradle at the end of repositories:

allprojects {
    repositories {
        ...
        maven { url 'https://jitpack.io' }
    }
}

Step 2. Add the dependency

dependencies {
        implementation 'com.github.arcm111.ScaleNumberPicker:final:1.0.1'
}

So my question is, are these documentation pages outdated, is Gradle 7 not fully supported yet, or am I looking at the wrong documentation?

razz
  • 9,770
  • 7
  • 50
  • 68

1 Answers1

2

in the documentation is says that allProjects block for repositories settings used by all modules should be added to the root build.gradle while in fact it only allows me to configure modules repositories in the settings.gradle under dependencyResolutionManagement block.

You may wish to ask a separate Stack Overflow question with a minimum verifiable example and details of your errors. This GitLab repo, in tag v2.2 contains a multi-module Android Studio project using Gradle 7.0.2 that uses allProjects for configuring repositories.

Another example is applying plugins to application modules, in documentations it says the first line should be... While the one used in my build is

Either syntax works. The plugins approach has been available for a year or so in Android Studio projects. The project that I linked to above uses the older apply plugin syntax. This sample project, by contrast, uses plugins.

are these documentation pages outdated, is Gradle 7 not fully supported yet, or am I looking at the wrong documentation?

None of the above, AFAICT. allProjects and apply plugin still work, at least with Gradle 7.0.2.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • When I add `allProjects` to top-level `build.gradle` is gives me the following error `Build was configured to prefer settings repositories over project repositories but repository 'maven' was added by build file 'build.gradle'` – razz Oct 17 '21 at 12:24
  • @razz: IIRC, there is something in your `settings.gradle` that is telling Gradle to not want `allprojects`. – CommonsWare Oct 17 '21 at 12:39
  • This is my `settings.gradle` file content: `dependencyResolutionManagement { repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS) repositories { google() mavenCentral() } } rootProject.name = "SNPTest" include ':app' `. It's the one generated by Android Studio, I didn't change any settings. – razz Oct 17 '21 at 14:25
  • @razz: Remove the `dependencyResolutionManagement` closure. That specifically says "do not support project-based repositories", which is what `allProjects` is part of. – CommonsWare Oct 17 '21 at 14:32
  • What I'm wondering about is, if these are the default configuration now in Gradle, then shouldn't android documentations be updated to be relevant to the latest version of Gradle? – razz Oct 17 '21 at 14:38
  • @razz: Ideally, the documentation would mention both approaches. However, right now, ~99.9% of Android Studio projects were not created using the Arctic Fox new-project wizard, and therefore are unlikely to be using `dependencyResolutionManagement`. – CommonsWare Oct 17 '21 at 14:46