diff --git a/src/main/groovy/com/liulishuo/okcheck/OkCheckPlugin.groovy b/src/main/groovy/com/liulishuo/okcheck/OkCheckPlugin.groovy index f9af250..7399059 100644 --- a/src/main/groovy/com/liulishuo/okcheck/OkCheckPlugin.groovy +++ b/src/main/groovy/com/liulishuo/okcheck/OkCheckPlugin.groovy @@ -40,7 +40,7 @@ class OkCheckPlugin implements Plugin { if (project == project.rootProject) CleanOkCheckDiffTask.addTask(project) // lint, ktlint, checkstyle, unitTest, pmd, findbugs - if (project != project.rootProject) { + if (project != project.rootProject || project.rootProject.subprojects.size() <= 0) { project.afterEvaluate { OkLint.inspectLint(project, okCheckExtension.lint) if (okCheckExtension.checkStyle.enabled) OkCheckStyleTask.addTask(project, okCheckExtension.checkStyle) @@ -62,24 +62,31 @@ class OkCheckPlugin implements Plugin { if (project == project.rootProject) { // root project setupOkCheckDiff(project) + if (project.subprojects.size() <= 0) { + distributeOkCheckTask(project) + } } else { // changed module list - final List changedModuleList = BuildConfig.getChangedModuleList(project) - project.afterEvaluate { - if (!Util.hasAndroidPlugin(project) && !Util.hasLibraryPlugin(project)) { - Util.printLog("Pass ${project.name} directly because it isn't android/library project.") - BuildConfig.addToPassedModuleFile(project) - return - } + distributeOkCheckTask(project) + } + } - boolean isChangedModule = changedModuleList.contains(project.name) - if (isChangedModule) { - Util.printLog("Enable check for ${project.name} because of file changed on it") - OkCheckTask.addValidTask(project, changedModuleList, okCheckExtension) - } else { - Util.printLog("NO CHANGED CODE FOUND FOR ${project.name}") - OkCheckTask.addMockTask(project) - } + private void distributeOkCheckTask(Project project) { + final List changedModuleList = BuildConfig.getChangedModuleList(project) + project.afterEvaluate { + if (!Util.hasAndroidPlugin(project) && !Util.hasLibraryPlugin(project)) { + Util.printLog("Pass ${project.name} directly because it isn't android/library project.") + BuildConfig.addToPassedModuleFile(project) + return + } + + boolean isChangedModule = changedModuleList.contains(project.name) + if (isChangedModule) { + Util.printLog("Enable check for ${project.name} because of file changed on it") + OkCheckTask.addValidTask(project, changedModuleList, okCheckExtension) + } else { + Util.printLog("NO CHANGED CODE FOUND FOR ${project.name}") + OkCheckTask.addMockTask(project) } } } diff --git a/src/main/groovy/com/liulishuo/okcheck/OkCheckTask.groovy b/src/main/groovy/com/liulishuo/okcheck/OkCheckTask.groovy index 20af6b7..00e4be6 100644 --- a/src/main/groovy/com/liulishuo/okcheck/OkCheckTask.groovy +++ b/src/main/groovy/com/liulishuo/okcheck/OkCheckTask.groovy @@ -34,7 +34,7 @@ class OkCheckTask extends DefaultTask { @TaskAction void setupOkcheck() { - if (project == project.rootProject) { + if (project == project.rootProject && project.subprojects.size() > 0) { Util.printLog("Finish root okcheck task!") } else if (!isMock) { Util.printLog("Finish ${project.name} okcheck task!") diff --git a/src/main/groovy/com/liulishuo/okcheck/util/ChangeModule.groovy b/src/main/groovy/com/liulishuo/okcheck/util/ChangeModule.groovy index b69da1d..4f0ed16 100644 --- a/src/main/groovy/com/liulishuo/okcheck/util/ChangeModule.groovy +++ b/src/main/groovy/com/liulishuo/okcheck/util/ChangeModule.groovy @@ -22,18 +22,29 @@ class ChangeModule { static List getAllModuleList(Project project) { final List moduleNameList = new ArrayList<>() - project.subprojects { - moduleNameList.add(it.name) + + if (project.subprojects.size() <= 0) { + moduleNameList.add(project.name) + } else { + project.subprojects { + moduleNameList.add(it.name) + } } + return moduleNameList } static List getChangedModuleList(Project project, List changedFilePaths) { final List pathModuleList = new ArrayList<>() File rootDir = project.rootProject.rootDir - project.subprojects { - String relativePath = rootDir.toURI().relativize(it.projectDir.toURI()).getPath() - pathModuleList.add(new PathModule(relativePath, it.name)) + if (project.subprojects.size() <= 0) { + String relativePath = rootDir.toURI().relativize(project.projectDir.toURI()).getPath() + pathModuleList.add(new PathModule(relativePath, project.name)) + } else { + project.subprojects { + String relativePath = rootDir.toURI().relativize(it.projectDir.toURI()).getPath() + pathModuleList.add(new PathModule(relativePath, it.name)) + } } final List changedModuleNameList = new ArrayList<>()