Skip to content

Commit

Permalink
feat:存在多个 application 只有run 指定当前的生效
Browse files Browse the repository at this point in the history
  • Loading branch information
chaojiong1zhang20230913 committed Dec 10, 2021
1 parent af99b1a commit 235893c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
4 changes: 2 additions & 2 deletions buildSrc/src/main/kotlin/plugin/RocketXPlugin.kt
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ open class RocketXPlugin : Plugin<Project> {
override fun apply(project: Project) {
//应用在 主 project 上,也就是 app module
mRocketXBean = project.extensions.create("RocketX", RocketXBean::class.java)
if (!isEnable(project) || hasAndroidPlugin(project)) return
if (!isEnable(project) || hasAndroidPlugin(project) || !isCurProjectRun(project)) return
this.appProject = project
//禁止 release 使用加速插件
if(mFlavorBuildType.toLowerCase().contains("release")) return
Expand Down Expand Up @@ -126,7 +126,7 @@ open class RocketXPlugin : Plugin<Project> {

appProject.rootProject.allprojects.forEach {
//剔除 app 和 rootProject
if (it.name.equals("app") || it == appProject.rootProject || it.childProjects.size > 0) return@forEach
if (hasAppPlugin(it) || it == appProject.rootProject || it.childProjects.size > 0) return@forEach
if (mAllChangedProject?.contains(it.path)?.not() != false) return@forEach
var mLocalMaven: LocalMaven? = null
val childProject = it.project
Expand Down
16 changes: 15 additions & 1 deletion buildSrc/src/main/kotlin/plugin/utils/PluginUtil.kt
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,25 @@ fun getFlavorBuildType(appProject: Project):String {
flavorBuildType =
flavorBuildType.substring(0, 1).toLowerCase() + flavorBuildType.substring(1)
}

return flavorBuildType
}

//不能通过name ,需要通过 path ,有可能有多级目录(: 作为aar名字会有冲突不能用)
fun getFlatAarName(project: Project): String {
return project.path.substring(1).replace(":","-")
}

fun isCurProjectRun(appProject: Project):Boolean {
var ret = false
var projectPath = ""
val arg = appProject.gradle.startParameter?.taskRequests?.getOrNull(0)?.args?.getOrNull(0)
if(!arg.isNullOrEmpty()) {
var index = arg.indexOf(RocketXPlugin.ASSEMBLE)
index = if(index > 0) index - 1 else 0
projectPath = arg.substring(0,index)
}
if (projectPath.length > 0) {
ret = appProject.path.equals(projectPath)
}
return ret
}

0 comments on commit 235893c

Please sign in to comment.