All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.cleveradssolutions.gradleplugin.CASDependencyManager.kt Maven / Gradle / Ivy

Go to download

CAS Gradle Plugin provides an easy way to integrate and configure CAS.AI Mediation in your android project.

There is a newer version: 3.9.4
Show newest version
package com.cleveradssolutions.gradleplugin

import org.gradle.api.Project
import org.gradle.api.artifacts.DependencyResolutionListener
import org.gradle.api.artifacts.ResolvableDependencies

internal class CASDependencyManager(
    private val project: Project
) : DependencyResolutionListener {

    override fun beforeResolve(dependencies: ResolvableDependencies) {
        addAdapterDependency("cas-sdk", BuildConfig.GLOBAL_VERSION)
        addDependencies()

        project.gradle.removeListener(this)
    }

    override fun afterResolve(dependencies: ResolvableDependencies) {}

    private fun addDependencies() {
        val extension = project.extensions.findByType(CASPluginExtension::class.java)
        if (extension == null) {
            project.logger.warn(BuildConfig.TAG + ": Configuration for `cas` not applied to module")
            return
        }
        val includeFamilies = extension.includeFamiliesAds
        val includeOptimal = extension.includeOptimalAds

        if (includeFamilies) {
            addAdapterDependency("cas-families", BuildConfig.GLOBAL_VERSION)
        }
        if (includeOptimal) {
            addAdapterDependency("cas", BuildConfig.GLOBAL_VERSION)
        }

        val adaptersImpl = extension.adapters as AdaptersImpl
        for (artifact in adaptersImpl.includedSet) {
            addAdapterDependency(artifact.id, artifact.version)
        }

        if (extension.useAdvertisingId) {
            addDependency("com.google.android.gms:play-services-ads-identifier:18.0.1")
        }
    }

    private fun addAdapterDependency(adapterId: String, adapterVersion: String) {
        val dependency = "${BuildConfig.GROUP}:$adapterId:${adapterVersion}"
        addDependency(dependency)
    }

    private fun addDependency(dependency: String) {
        project.dependencies.add("implementation", dependency)
        project.logger.info(BuildConfig.TAG + " for '{}' module added dependency '{}'", project.name, dependency)
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy