com.cleveradssolutions.gradleplugin.CASDependencyManager.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of gradle-plugin Show documentation
Show all versions of gradle-plugin Show documentation
CAS Gradle Plugin provides an easy way to integrate and configure CAS.AI Mediation in your android project.
The 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)
}
}