Build被配置为首选设置存储库而不是项目存储库,但存储库‘maven’是通过生成文件‘build.gradle’添加的

goqiplq2  于 2022-09-21  发布在  Maven
关注(0)|答案(12)|浏览(482)

我想将jitpack.io作为存储库添加到Gradle文件中。这是我的Gradle根文件:

buildscript {
    repositories {
        google()
        mavenCentral()
    }
    dependencies {
        classpath "com.android.tools.build:gradle:7.0.2"
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.21"

        classpath 'com.google.dagger:hilt-android-gradle-plugin:2.38.1'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}
task clean(type: Delete) {
    delete rootProject.buildDir
}

因为我没有将依赖项放在那里的“所有存储库”(只在那里工作),所以我在构建脚本代码之后创建并添加了以下代码:

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

但这就是我得到的错误

Caused by: org.gradle.api.InvalidUserCodeException: Build was configured to prefer settings repositories over project repositories but repository 'maven' was added by build file 'build.gradle'
ntjbwcob

ntjbwcob1#

Gradle 6.8引入了中央存储库声明,这是定义存储库的新方法。可在此处找到最新的文档(7.4.2)。

setting.gradle文件中删除dependencyResolutionManagement块,以使您的项目以旧方式工作。

mm5n2pyu

mm5n2pyu2#

您可以在settings.gradle中的DependencyResolutionManagement中添加jitpack.io作为存储库

dependencyResolutionManagement {
    repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
    repositories {
        google()
        mavenCentral()
        maven { url 'https://jitpack.io' }
    }
}
z6psavjg

z6psavjg3#

您需要更新settings.gradle中的设置,并将repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)更改为repositoriesMode.set(RepositoriesMode.PREFER_SETTINGS)

最后,将maven { url 'https://jitpack.io' }添加到存储库块。

完整的settings.gradle文件如下所示:

import org.gradle.api.initialization.resolve.RepositoriesMode

dependencyResolutionManagement { 
    repositoriesMode.set(RepositoriesMode.PREFER_SETTINGS)
    repositories { 
        google()
        mavenCentral()
        jcenter() // Warning: this repository is going to shut down soon
        maven { url 'https://jitpack.io' }
    }
}
rootProject.name = "appname"
include ':app'
sy5wg1nm

sy5wg1nm4#

替换此行:

repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)

使用:

repositoriesMode.set(RepositoriesMode.PREFER_SETTINGS)

之前

之后

repositoriesMode.set(RepositoriesMode.PREFER_SETTINGS)
mrphzbgm

mrphzbgm5#

gradle version '7.1.0'中只需在setting.gradle中添加maven { url 'https://jitpack.io' }

dependencyResolutionManagement {
    repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
    repositories {
        google()
        mavenCentral()
        maven { url 'https://jitpack.io' }
    }
}
qpgpyjmq

qpgpyjmq6#

  • 解决方案:*

您可以将此url添加到settings.gradle(项目设置)文件中,您可以在Gradle脚本中找到该文件。

将您的URL添加到DependencyResolutionManagement中,如下所示

dependencyResolutionManagement{
    maven {
        url 'https://jitpack.io'
    }    
}

完整参考见下图,

现在同步它,它会起作用的,

谢谢!:)

qjp7pelc

qjp7pelc7#

转到Settings.gradle并将其放入存储库中

dependencyResolutionManagement {
    repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
    repositories {
        google()
        mavenCentral()
        maven { url 'https://jitpack.io' }
    }
}
vom3gejh

vom3gejh8#

由于Android Studio已更新,因此您必须从设置中控制您的依赖关系。app

dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
    google()
    mavenCentral()
    jcenter() // Warning: this repository is going to shut down soon
    maven { url 'https://jitpack.io' }
  }

}rootProject.name=“EmfDetector”包含‘:app’

请把这根管子放在呼吸机上

maven { url 'https://jitpack.io' } //as i have done above 
     `
nwo49xxi

nwo49xxi9#

在我的例子中,我只删除了dependencyResolutionManagement{...}语句,该语句在settings.gradle中默认将新项目添加到settings.gradle中

fnatzsnv

fnatzsnv10#

在settings.gradle中添加此行

请点击此处查看更多信息

6fe3ivhb

6fe3ivhb11#

一些老建议允许您将maven{url“https://jitpack.io”}添加到根build.gradle中,但只要您使用的是最新版本的AS,您只需将其添加到settings.gradle中,而不是build.gradle中

2guxujil

2guxujil12#

在我的例子中,我只在settings.gradle中添加了mavenLocal()

相关问题