当前位置: 首页 > 知识库问答 >
问题:

如何触发build.gradle并将新的依赖项下载到gradle缓存

王念
2023-03-14
    null

不获取4.0.2版本AAR。

将在不构建任何东西的情况下进行同步。但在我使用的5.1.1中删除了它。

将您的构建从Gradle4.x升级到5.0

def dependencyVersion = '0.3.1'
apply from: "https://***/dependencyVersions/${dependencyVersion}/dependencyVersions-${dependencyVersion}.gradle"
import groovy.json.JsonSlurper

ext {
    mepMajorVersion = 0

    mepMinorVersion = 3

    isLocalDevMode = {
        def devMode = project.findProperty('dev.mode') ?: System.getenv('dev.mode')
        return "local" == devMode
    }

    getVersionCode = { projectGroupId, projectArtifactId ->
        def repoPath = projectGroupId.replace(".", "/")
        try {
            def jsonSlurper = new JsonSlurper()
            def url = "https://***/api/search/versions?repos=vdca-mobile-maven&g=${repoPath}&a=$projectArtifactId"
//            println "url $url"
            def versions = jsonSlurper.parseText(new URL(url).text)
//            println "$projectArtifactId  versions $versions"
            def latestVersion = 0
            versions.results.each { v ->
                try {
                    def version = v.version.split("-")[0].split("\\.")
                    def majorVersion = version[0].toInteger()
                    def minorVersion = version[1].toInteger()
                    def patchVersion = version[2].toInteger()
//                    println "majorVersion $majorVersion minorVersion $minorVersion patchVersion $patchVersion"
                    if (majorVersion == mepMajorVersion && minorVersion == mepMinorVersion && patchVersion > latestVersion)
                        latestVersion = patchVersion
                } catch (Exception e) {
                }
            }
//            println "$projectArtifactId latest version $latestVersion"

            return latestVersion + 1
        } catch (Exception e) {
            return 1
        }
    }

    getLatestVersion = { projectGroupId, projectArtifactId ->
        def repoPath = projectGroupId.replace(".", "/")
        try {
            def jsonSlurper = new JsonSlurper()
            def url = "https://artifactory.trusted.visa.com/api/search/versions?repos=vdca-mobile-maven&g=${repoPath}&a=$projectArtifactId"
//            println "url $url"
            def versions = jsonSlurper.parseText(new URL(url).text)
//            println "$projectArtifactId  versions $versions"
            def latestVersion = 0
            versions.results.each { v ->
                try {
                    def version = v.version.split("-")[0].split("\\.")
                    def majorVersion = version[0].toInteger()
                    def minorVersion = version[1].toInteger()
                    def patchVersion = version[2].toInteger()
//                println "majorVersion $majorVersion minorVersion $minorVersion patchVersion $patchVersion"
                    if (majorVersion == mepMajorVersion && minorVersion == mepMinorVersion && patchVersion > latestVersion)
                        latestVersion = patchVersion
                } catch (Exception e) {
                }
            }
//            println "$projectArtifactId latest version "+mepMajorVersion+"."+mepMinorVersion+"."+latestVersion

            return mepMajorVersion+"."+mepMinorVersion+"."+latestVersion
        } catch (Exception e) {
            println "$e"
            return ""
        }
    }

    // version number MAJOR.MINOR.PATCH
    getVersionName = { projectGroupId, projectArtifactId ->
        return "$mepMajorVersion.$mepMinorVersion." + getVersionCode(projectGroupId, projectArtifactId)
    }

    mepVersions = [
            // foundation
            analytics                 : getLatestVersion('com.visa.mobileEnablement.mobileFoundation', 'analytics'),
            dataProvider              : getLatestVersion('com.visa.mobileEnablement.mobileFoundation', 'dataProvider'),
            logger                    : getLatestVersion('com.visa.mobileEnablement.mobileFoundation', 'logger'),
            profilingService          : getLatestVersion('com.visa.mobileEnablement.mobileFoundation', 'profiler'),
            storage                   : '',
            // fmcore
            authenticationService     : getLatestVersion('com.visa.mobileEnablement', 'authenticationService'),
            coreService               : getLatestVersion('com.visa.mobileEnablement', 'coreService'),
            coreServiceTesting        : getLatestVersion('com.visa.mobileEnablement', 'coreServiceTesting'),
            cryptoClient              : getLatestVersion('com.visa.mobileEnablement', 'cryptoClient'),
            deviceManagementService   : getLatestVersion('com.visa.mobileEnablement', 'deviceManagementService'),
            featureGateway            : getLatestVersion('com.visa.mobileEnablement', 'featureGateway'),
            mockAuthenticationService : getLatestVersion('com.visa.mobileEnablement', 'mockAuthenticationService'),
            uiComponents              : getLatestVersion('com.visa.mobileEnablement', 'uiComponents'),
            utilities                 : getLatestVersion('com.visa.mobileEnablement', 'utilities'),
            // mep_login
            enrollFeature             : getLatestVersion('com.visa.mobileEnablement.featureModules', 'enrollFeature'),
            enrollService             : getLatestVersion('com.visa.mobileEnablement', 'enrollService'),
            loginFeature              : getLatestVersion('com.visa.mobileEnablement.featureModules', 'loginFeature'),
            // mep_3ds
            mep3dsFeature             : getLatestVersion('com.visa.mobileEnablement.featureModules', 'mep3dsFeature'),
            mep3dsService             : getLatestVersion('com.visa.mobileEnablement', 'mep3dsService'),
            mockMep3dsService         : getLatestVersion('com.visa.mobileEnablement', 'mockMep3dsService'),
    ]
    mepLibVersions = [
            androidTestVersion        : '1.0.1',
            androidxTestVersion       : '1.1.0',
            androidArchCompVersion    : '1.1.1',
            appCompatVersion          : '1.1.0',
            biometricVersion          : '1.0.0',
            buildToolsVersion         : "28.0.3",
            butterknifeCompilerVersion: '8.5.1',
            butterknifeVersion        : '8.5.1',
            caverockAndroidSvgVersion : '1.2.1',
            compileSdk                : 28,
            constraintLayout          : '1.1.3',
            daggerCompilerVersion     : '2.8',
            daggerProducersVersion    : '2.8',
            daggerVersion             : '2.8',
            espressoVersion           : '3.1.0',
            firebaseCoreVersion       : '16.0.9',
            gradlePluginVersion       : '3.4.1',
            gsonConverter             : '2.0.1',
            gsonVersion               : '2.8.2',
            httpClientAndroidVersion  : '4.3.5.1',
            jacocoVersion             : '0.8.4',
            javaxInjectVersion        : 1,
            junitVersion              : '4.12',
            jsonOrgVersion            : '20140107',
            jsr250Version             : '1.0',
            jsr305Version             : '1.3.9',
            kotlinVersion             : '1.3.50',
            kotlin_coroutines         : '1.3.3',
            materialVersion           : '1.1.0-rc02',
            minSdk                    : 23,
            mockitoVersion            : '1.10.19',
            mockkVersion              : '1.9.3',
            multiDex                  : '1.0.3',
            nineoldandroids           : '2.4.0',
            okioVersion               : '1.6.0',
            okHttpLegacyUrlConnVersion: '2.6.0',
            okHttpLegacyVersion       : '2.6.0',
            okHttpUrlConnVersion      : '3.10.0',
            okHttpVersion             : '3.10.0',
            openPojoVersion           : '0.8.3',
            picassoVersion            : '2.5.2',
            powerMockVersion          : '1.6.2',
            playServiceVersion        : '11.0.4',
            retrofitLegacyVersion     : '1.9.0',
            retrofitVersion           : '2.5.0',
            retrofitScalarsVersion    : '2.1.0',
            supportLib                : '28.0.0',
            tagManagerVersion         : '16.0.8',
            targetSdk                 : 28,
            testRunnerVersion         : '1.1.0',
            threatMetrixVersion       : '5.4-73',
            uiAutomatorVersion        : '2.1.2',
            viewpagerindicator        : '2.4.1',
            wiremockVersion           : '2.0.8-beta',
            commonsIoVersion          : '2.6',
            commonsCodecVersion       : '1.13',
    ]
}

如何执行build.gradle来下载最新的依赖项?

相关的quesion我如何强制gradle重新下载依赖项?

共有1个答案

裴实
2023-03-14

事实证明,我还应该将DependencyVersion0.3.1更新到0.4.1,这是忘记告诉我的。

然后在Android Studio中与gradle文件同步。

(我尝试了./gradlew--refresh-dependencies,它在日志中显示了依赖项的最新0.4.2版本,但Android Studio仍然显示了依赖项的旧0.3.6版本。)

 类似资料:
  • 问题内容: 问题。 Gradle依赖管理使得: 没有简便的方法来检查依赖项更新的可用性(仅使用某些第三方插件,如ben-manes / gradle-versions-plugin)并下载更新以替换旧版本; 从远程存储库下载依赖项工件,然后将其存储在gradle缓存中,并在后续构建中重用;但是项目的成功编译必须不依赖于与Internet的连接,远程存储库的可用性以及这些存储库中特定版本的依赖项。

  • 问题。 分级依赖项管理是这样进行的: 检查依赖更新的可用性(仅使用一些第三方插件,如Ben-Manes/Gradle-Versions-Plugin),并下载替换旧版本的更新是不容易的; 依赖项构件从远程存储库下载,然后存储在gradle缓存中,并在后续构建中重用;但项目的成功编译不能依赖于与Internet的连接、远程存储库的可用性以及这些存储库中依赖项的特定版本的存在。 null

  • 我试图在我的文件系统上为maven和gradle维护相同的存储库。但是我遇到了一些问题。 我的 GRADLE_USER_HOME是 我的gradle主页与我的Maven存储库相同。 但是,当通过gradle下载依赖项时,它们将被下载到gradle\u USER\u HOME\cache中,而不是存储库文件夹中。我缺少什么配置? 编辑我已经查看了《Gradle In Action》一书中关于依赖关系

  • 是否有一种方法可以让gradle像maven一样将依赖项库下载到项目目录中?我知道gradle在本地机器目录中保留了自己的缓存,但是我怎么知道我的项目将使用哪些库,特别是我在build.gradle文件中定义的库有自己的依赖关系呢?

  • 我正在尝试添加以下依赖项: