2

我有一个工具需要对多模块项目中的子项目进行拓扑排序。Gradle 有办法提供这个吗?

4

3 回答 3

3

定义拓扑排序。您可以通过引用subprojects. 像这样:

subprojects.each { p ->
  println p.path
}

您可以按它们的路径对它们进行排序(这是完全限定的名称(即。:module:submodule

于 2013-10-23T10:32:05.083 回答
2

以下适用于我的目的。

class ProjectCategory {
    static List<Project> topologicallySortedProjectDependencies(Project project) {
        topologicallySortedProjectDependenciesImpl(project).unique().reverse()
    }

    private static List<Project> topologicallySortedProjectDependenciesImpl(Project project) {
        final dependencies = project.configurations.compile.dependencies.findAll { dependency ->
            dependency instanceof ProjectDependency
        } collect { ProjectDependency projectDependency ->
            topologicallySortedProjectDependenciesImpl(projectDependency.dependencyProject)
        } flatten()

        dependencies + project
    }
}

task topologicallySortedProjects << {
    println project(':').toString().capitalize()

    use(ProjectCategory) {
        project.topologicallySortedProjectDependencies().each { projectDependency ->
            println "+--- ${projectDependency.toString().capitalize()}"
        }
    }
}
于 2013-10-24T16:40:01.290 回答
0

以下对我有用:

final class ProjectManager {

    private static printSubProjects(Project project) {
        project.subprojects.each { p ->
            println p.path
        }
    }
}

rootProject {

    task listAllProjects << {
        println project(':').toString()
        ProjectManager.printSubProjects(project)
    }
}

cd root_gradle_project

毕业名单所有项目

于 2018-08-17T02:43:59.883 回答