vanniktech / gradle-dependency-graph-generator-plugin

Gradle plugin that generates dependency graphs from your project.
http://vanniktech.com
Apache License 2.0
1.51k stars 98 forks source link

Custom Graph Generator: Conditional Attributes for Dependency Nodes #233

Open NiC0x36 opened 10 months ago

NiC0x36 commented 10 months ago

I wrote my own dependencyGraphGenerator. I managed to show the package name including the version.

But as soon as I add any if statement, the task fails:

Execution failed for task ':generateDependencyGraphMyGenerator '.
> Error while evaluating property 'dotFormatGraph' of task ':generateDependencyGraphMyGenerator '
   > java.lang.NullPointerException (no error message)

There are no nullpointers / empty values in my own code, I checked that. It seems like I can't manipulate only certain dependencyNodes in the lambda using ifs.

My Generator:

dependencyGraphGenerator {
    generators {
        myGenerator {
            include = { true }
            children = { true }

            dependencyNode = { node, dependency ->
                // Version of Label
                String versionedLabel = "${dependency.moduleGroup}:${dependency.moduleName}:${dependency.moduleVersion}"
                node.attrs().add(Label.of(versionedLabel))

                if (dependency.moduleName.startsWith("app")) {
                    node.attrs().add(Style.FILLED, Color.rgb("#ADD8E6"))
                }

                if (dependency.moduleGroup.startsWith('org.apache')) {
                    node.attrs().add(Style.FILLED, Color.rgb("#d1bc8a"))
                }
            }
        }
    }
}

How can I implement this generator, so some attributes will only be applied to dependency which fulfill a certain condition?

Thanks for your help