添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接

Hi guys, let’s say I have the following root level build.gradle file:

buildscript {
    repositories {
        google()
    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.0'
        classpath 'com.jakewharton.hugo:hugo-plugin:1.2.1'
allprojects {
    repositories {
        maven { url "https://jitpack.io" }
        google()

This would sync fine even though hugo is in the jitpack repo instead of the google() repo, which makes me believe that the buildscript somehow knows about jitpack via the allprojects {} block.

So I remove the repository {} block from buildscript {} altogether expecting that it will also know about the google() repository from the allprojects {} block, but now gradle complains that it cannot resolve the android gradle plugin (which is located in the google() repository). What gives? Thanks!

I suspect that you’ve got com.jakewharton.hugo:hugo-plugin:1.2.1 cached locally and Gradle is finding that. If I take the same build script, I get an error resolving that dependency:

> Could not resolve all files for configuration ':classpath'.
   > Could not find com.jakewharton.hugo:hugo-plugin:1.2.1.
     Searched in the following locations:
         https://dl.google.com/dl/android/maven2/com/jakewharton/hugo/hugo-plugin/1.2.1/hugo-plugin-1.2.1.pom
         https://dl.google.com/dl/android/maven2/com/jakewharton/hugo/hugo-plugin/1.2.1/hugo-plugin-1.2.1.jar
     Required by:
         project :
              

I’m not sure what you mean “doesn’t even re-download all deps” – --refresh-dependencies only forces Gradle to check for changes to the dependencies in the project. If it doesn’t find a change in the dependency, it doesn’t need to download anything. What kind of problem are you seeing/trying to solve?

In this case, even if you’ve removed the repository, Gradle will still have the dependency in its cache and will be able to satisfy the dependency request without looking externally.

I was playing around with different repository {} configurations and trying to tease out how things work, was surprised to see the behavior mentioned in my original post. Now I’m just looking for a way to replicate the error you mentioned but don’t know how. I’ve tried deleting the .gradle directory, cleanBuildCache, uninstalling Android Studio and even deleting and re-cloning the project.

Are you removing your Gradle user home (~/.gradle) or the project’s .gradle?

You can just try using a temporary Gradle user home to see the same behavior:

gradle -g gradle-user-home buildEnvironment

This creates a directory called gradle-user-home in the current directory and uses that as your Gradle user home, which is where Gradle caches downloaded dependencies.

Actually now that I’m building in a new gradle home, I’m still able to resolve dependencies like hugo, and they resolve from https://plugins.gradle.org/m2

Example input:

buildscript {
    repositories {
        google()
    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.0'
        classpath 'com.jakewharton.hugo:hugo-plugin:1.2.1'
        classpath 'com.romandanylyk:pageindicatorview:0.2.0@aar'
allprojects {
    repositories {
        maven { url "https://jitpack.io" }
        google()

Example output:

Download https://plugins.gradle.org/m2/com/jakewharton/hugo/hugo-plugin/1.2.1/hugo-plugin-1.2.1.pom
Download https://plugins.gradle.org/m2/com/jakewharton/hugo/hugo-plugin/1.2.1/hugo-plugin-1.2.1.jar
Download https://plugins.gradle.org/m2/com/romandanylyk/pageindicatorview/0.2.0/pageindicatorview-0.2.0.pom
Download https://plugins.gradle.org/m2/com/romandanylyk/pageindicatorview/0.2.0/pageindicatorview-0.2.0.aar