2017-09-22 5 views
3

私は2つのgradleモジュール、:A:Bを持つマルチモジュールのgradleプロジェクトを持っているとしましょう。gradleモジュールの名前とそれが依存する他のモジュールの名前を取得

. 
├── :A 
│   └── build.gradle 
├── :B 
│   └── build.gradle 
├── build.gradle  (plugin applied here) 
└── settings.gradle 
  • :A依存関係
  • :Bを持っていない私は、以下の情報を取得したい:A

に依存しています。

  • プロジェクト内の各モジュールの名前のリスト::A、各モジュールが依存するモジュール名の:B
  • リスト。 :Aの場合、これは空のリストになり、そして:BことがlistOf(":A")(単一要素リスト)

がどのように私はルートGradleのモジュールに適用されるのカスタムのGradleプラグインのコンテキストで、この情報を得ることができるでしょうか?

このためのユースケースは、各モジュールはここでマルチモジュールプロジェクト

+0

を? – Opal

+0

@Opalマルチモジュールプロジェクト(標準アンドロイドプロジェクトの設定) – ZakTaccardi

+0

関連する '* .gradle'ファイルとともに構造をスケッチすることができますか?単純なASCIIツリーで十分です。 – Opal

答えて

3

に接続されているかを視覚的に表現を生成することで、各Configurationを通過し、それらからProjectDependency種類を取得するためのスニペットです。すべてのプロジェクトが評価された後に実行されるGradle.projectsEvaluated(org.gradle.api.Action)を使用します。これは、推移を把握するか、誰が誰に依存しているかという概念を保持するために何もしませんが、これはあなたが探しているものを達成する方法の出発点となることを願っています。

gradle.projectsEvaluated { 
    println('Projects loaded') 
    println('*' * 15) 
    allprojects.forEach { proj -> 
    final List<ProjectDependency> projectDependencies = proj.configurations.collectMany { Configuration configuration -> 
     configuration.allDependencies 
    }.findAll { Dependency dependency -> 
     dependency instanceof ProjectDependency 
    }.collect { 
     it as ProjectDependency 
    }.unique().collect() 
    println("Project ${proj.name}") 
    println(projectDependencies.collect { " ${it.name} -> ${it.dependencyProject.path}" }.join(System.lineSeparator())) 
    println() 
    } 
} 

私はjunit-team/junit5リポジトリ上でそれを試して、次の出力ました:あなたは `A`およびマルチモジュールプロジェクトまたはマルチモジュール内の 'B'とのプロジェクトは、自分自身を投影し意味

Projects loaded 
*************** 
Project junit5 


Project documentation 
    junit-jupiter-api -> :junit-jupiter-api 
    junit-jupiter-params -> :junit-jupiter-params 
    junit-platform-runner -> :junit-platform-runner 
    junit-platform-launcher -> :junit-platform-launcher 
    junit-platform-console -> :junit-platform-console 
    junit-vintage-engine -> :junit-vintage-engine 
    junit-jupiter-engine -> :junit-jupiter-engine 

Project junit-jupiter-api 
    junit-platform-commons -> :junit-platform-commons 

Project junit-jupiter-engine 
    junit-platform-engine -> :junit-platform-engine 
    junit-jupiter-api -> :junit-jupiter-api 
    junit-platform-launcher -> :junit-platform-launcher 
    junit-platform-runner -> :junit-platform-runner 
    junit-platform-engine -> :junit-platform-engine 
    junit-platform-console -> :junit-platform-console 

Project junit-jupiter-migrationsupport 
    junit-jupiter-api -> :junit-jupiter-api 
    junit-jupiter-engine -> :junit-jupiter-engine 
    junit-platform-launcher -> :junit-platform-launcher 
    junit-platform-runner -> :junit-platform-runner 
    junit-platform-engine -> :junit-platform-engine 
    junit-platform-console -> :junit-platform-console 

Project junit-jupiter-params 
    junit-jupiter-api -> :junit-jupiter-api 
    junit-platform-engine -> :junit-platform-engine 
    junit-jupiter-engine -> :junit-jupiter-engine 
    junit-platform-launcher -> :junit-platform-launcher 
    junit-platform-runner -> :junit-platform-runner 
    junit-platform-console -> :junit-platform-console 

Project junit-platform-commons 


Project junit-platform-console 
    junit-platform-launcher -> :junit-platform-launcher 

Project junit-platform-console-standalone 
    junit-platform-console -> :junit-platform-console 
    junit-jupiter-engine -> :junit-jupiter-engine 
    junit-jupiter-params -> :junit-jupiter-params 
    junit-vintage-engine -> :junit-vintage-engine 
    junit-jupiter-api -> :junit-jupiter-api 
    junit-jupiter-params -> :junit-jupiter-params 

Project junit-platform-engine 
    junit-platform-commons -> :junit-platform-commons 

Project junit-platform-gradle-plugin 
    junit-platform-console -> :junit-platform-console 
    junit-platform-launcher -> :junit-platform-launcher 
    junit-jupiter-api -> :junit-jupiter-api 
    junit-platform-console -> :junit-platform-console 
    junit-jupiter-engine -> :junit-jupiter-engine 

Project junit-platform-launcher 
    junit-platform-engine -> :junit-platform-engine 

Project junit-platform-runner 
    junit-platform-launcher -> :junit-platform-launcher 
    junit-platform-suite-api -> :junit-platform-suite-api 

Project junit-platform-suite-api 
    junit-platform-commons -> :junit-platform-commons 

Project junit-platform-surefire-provider 
    junit-platform-launcher -> :junit-platform-launcher 
    junit-jupiter-api -> :junit-jupiter-api 
    junit-platform-runner -> :junit-platform-runner 
    junit-jupiter-engine -> :junit-jupiter-engine 
    junit-platform-console -> :junit-platform-console 

Project junit-vintage-engine 
    junit-platform-engine -> :junit-platform-engine 
    junit-platform-launcher -> :junit-platform-launcher 
    junit-jupiter-api -> :junit-jupiter-api 
    junit-platform-runner -> :junit-platform-runner 
    junit-platform-engine -> :junit-platform-engine 
    junit-platform-console -> :junit-platform-console 
    junit-jupiter-engine -> :junit-jupiter-engine 

Project platform-tests 
    junit-platform-commons -> :junit-platform-commons 
    junit-platform-console -> :junit-platform-console 
    junit-platform-engine -> :junit-platform-engine 
    junit-platform-launcher -> :junit-platform-launcher 
    junit-jupiter-api -> :junit-jupiter-api 
    junit-jupiter-params -> :junit-jupiter-params 
    junit-platform-runner -> :junit-platform-runner 
    junit-platform-engine -> :junit-platform-engine 
    junit-jupiter-engine -> :junit-jupiter-engine 
    junit-vintage-engine -> :junit-vintage-engine 
    junit-jupiter-migrationsupport -> :junit-jupiter-migrationsupport 
    junit-platform-gradle-plugin -> :junit-platform-gradle-plugin 
    junit-platform-surefire-provider -> :junit-platform-surefire-provider 
+0

これはかなり良いですが、gradlの内部APIがこのコードで使用されていることを覚えておいてください。 – Opal

+0

@Opal私は内部APIを使用していないと思います(私が知る限り)。 – mkobit

+1

あなたは正しいです! ProjectDependencyは内部APIからのものだと私は考えました。クール! :) – Opal