com.flyjingfish.module_communication_plugin.CommunicationModulePlugin.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of module-communication-plugin Show documentation
Show all versions of module-communication-plugin Show documentation
Lightweight Aop for Android platform, you deserve it, action is worse than your heartbeat
The newest version!
package com.flyjingfish.module_communication_plugin
import com.android.build.api.variant.AndroidComponentsExtension
import com.android.build.api.variant.Variant
import com.android.build.gradle.LibraryExtension
import org.gradle.api.Plugin
import org.gradle.api.Project
import java.io.File
class CommunicationModulePlugin : Plugin {
private val variantList: ArrayList = ArrayList()
override fun apply(project: Project) {
variantList.clear()
val androidComponents = project.extensions.getByType(AndroidComponentsExtension::class.java)
project.dependencies.add("implementation","io.github.FlyJingFish.ModuleCommunication:module-communication-annotation:${LibVersion.version}")
val libraryExtension = project.extensions.getByName("android") as LibraryExtension
androidComponents.onVariants { variant ->
variantList.add(variant)
variant.sources.java?.let { java ->
val path = "/${LibVersion.buildDir}/${variant.name}/${LibVersion.pathName}".replace('/',File.separatorChar)
val file = File("${project.buildDir}$path")
if (!file.exists()){
file.mkdirs()
}
java.addStaticSourceDirectory("build$path")
}
variant.sources.assets?.let { assets ->
val path = "/${LibVersion.buildDir}/${variant.name}/${LibVersion.assetsName}".replace('/',File.separatorChar)
val file = File("${project.buildDir}$path")
if (!file.exists()){
file.mkdirs()
}
assets.addStaticSourceDirectory("build$path")
}
val path = "/${LibVersion.buildDir}/${variant.name}/${LibVersion.resName}".replace('/',File.separatorChar)
val file = File("${project.buildDir}$path")
if (!file.exists()){
file.mkdirs()
}
libraryExtension.sourceSets.getByName(variant.name).res.srcDirs("build$path")
}
}
}