0

We have multiple versions of dependencies (aar) built and published by our own.

We would like to use the latest version on the maven repository.

How to download the latest dependency version aar if I already have a gradle script to get it.

How to trigger it?

Here is what I tried:

  1. Android Studio -> Sync project with gradle files

Not get the 4.0.2 version aar.

  1. ./gradlew --recompile-scripts

Will do a sync without building anything. But it is removed in 5.1.1 which I used.

Upgrading your build from Gradle 4.x to 5.0

(Upgrading your build from Gradle 4.x to 5.0)[docs.gradle.org/current/userguide/upgrading_version_4.html]

  1. ./gradlew --refresh-dependencies

Not sure if it will download new dependency and how to verify it. Either not sure if it is equals to "Sync project with gradle files" in gradle.

Since my network is not very good, is there a way to just download the dependencies I do not have and remain the dependency I have downloaded as it is?

Here is what I use:

moduleA/build.gradle

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',
    ]
}

My Question:

  1. is there any debugging way to debug the dependency.gradle file?

  2. how to execute the build.gradle to download the latest dependencies?

Related quesion How can I force gradle to redownload dependencies?

Francis Bacon
  • 4,080
  • 1
  • 37
  • 48

1 Answers1

0

It turns out that I should also update dependencyVersion from 0.3.1 to 0.4.1, which is forgotten to be told to me.

Then Sync with gradle files in Android Studio.

(I tried ./gradlew --refresh-dependencies, it shows the latest 0.4.2 version of dependency in log, but the Android Studio still shows the old 0.3.6 version of dependency.)

I wonder how should I know about the principle?

Francis Bacon
  • 4,080
  • 1
  • 37
  • 48