gradle 找不到参数的方法dependencyResolutionManagement()

hgc7kmma  于 2022-11-14  发布在  其他
关注(0)|答案(4)|浏览(2769)

我试着使用老师给我的一个项目,但是它显示了一个错误

Settings file '/Users/admin/AndroidStudioProjects/HTTPNetworking/settings.gradle' line: 1

A problem occurred evaluating settings 'HTTPNetworking'.
> Could not find method dependencyResolutionManagement() for arguments [settings_d1xerae4a210x6r7efckrwyki$_run_closure1@580a3803] on settings 'HTTPNetworking' of type org.gradle.initialization.DefaultSettings.

* Try:
Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Exception is:
org.gradle.api.GradleScriptException: A problem occurred evaluating settings 'HTTPNetworking'.
Caused by: org.gradle.internal.metaobject.AbstractDynamicObject$CustomMessageMissingMethodException: Could not find method dependencyResolutionManagement() for arguments [settings_d1xerae4a210x6r7efckrwyki$_run_closure1@580a3803] on settings 'HTTPNetworking' of type org.gradle.initialization.DefaultSettings
at settings_d1xerae4a210x6r7efckrwyki.run(/Users/admin/AndroidStudioProjects/HTTPNetworking/settings.gradle:1)

设置。gradle包含:

dependencyResolutionManagement {
   repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
      repositories {
         google()
         mavenCentral()
         jcenter() // Warning: this repository is going to shut down soon
      }
}
rootProject.name = "HTTP Networking"
include ':app'

有什么问题吗?

kdfy810k

kdfy810k1#

gradle-7.3和较低的方法dependencyResolutionManagement中有@Incubating注解。要在您的settings.gradlesettings.gradle.kts文件中使用此方法,您需要添加行:

enableFeaturePreview("VERSION_CATALOGS")
0kjbasz6

0kjbasz62#

此错误可能是由于在build.gradle文件中定义dependencyResolutionManagement块而不是在**settings.gradle**(doco明确告诉您放置它的位置)中定义dependencyResolutionManagement块而导致的。
不是说 * 我 * 做了什么。如果你也完全没有犯那个明显愚蠢的错误,请自由地投票给这个答案。

dddzy1tm

dddzy1tm3#

此错误可能是由于使用了较旧的gradle版本而导致的,在我将我的项目的gradle版本升级到7.4.2后,问题得到了解决

tuwxkamq

tuwxkamq4#

复制并替换Top-level build file中的以下代码:

// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
    repositories {
        google()
        mavenCentral()
        maven { url 'https://jitpack.io' }
        mavenCentral()

    }
    dependencies {
        classpath 'com.android.tools.build:gradle:4.1.3'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        google()
        mavenCentral()
        maven { url 'https://jitpack.io' }
        mavenCentral()

    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

并在settings中对这些行进行注解。gardle(:):

pluginManagement {
    repositories {
        gradlePluginPortal()
        google()
        mavenCentral()
    }
}
dependencyResolutionManagement {
    repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
    repositories {
        google()
        mavenCentral()
    }
}

请注意,Gradle Version最好为6.6,因为Gradle Plugin4.1.3

相关问题