javagradlegroovybuild-tools

How remove unnecessary dependencies in output from "gradle dependencies" task?


Assume, we have multi-project build and we want to see all dependencies for certain module:

gradle certainProject:dependencies

Then we will get similar output:

+--- project :firstProject
|    +--- project :anyProject
|    +--- org.slf4j:slf4j-api:1.7.30 -> 1.7.36
|    +--- org.projectlombok:lombok:1.18.20 -> 1.18.22
|    +--- org.springframework:spring-core:5.3.22 -> 5.3.25 (*)
+--- project :secondProject
|    +--- org.slf4j:slf4j-api:1.7.30 -> 1.7.36
|    +--- org.springframework.kafka:spring-kafka:2.8.6 (*)
|    +--- org.mapstruct:mapstruct:1.4.2.Final
|    \--- org.mapstruct:mapstruct-processor:1.4.2.Final
+--- project :thirdProject
|    +--- … e.t.c

I'm interesting in only see "project :" in output recursively in depth:

+--- project :firstProject
|    +--- project :anyProject
+--- project :secondProject
+--- project :thirdProject

Probably exclude by pattern or smth same?

These deps add such way:

dependencies {
    implementation(
            project(":firstProject"),
            project(":secondProject"),
            project(":thirdProject"),
    )
    
    implementation("org.postgresql:postgresql:3.2.2")
    //…
}

Solution

  • Is it absolutely necessary for some reason that this be solved only with arguments to gradle?

    If not, then this will produce what you want:

    gradle certainProject:dependencies | grep -E ' project \:'