vanniktech/gradle-dependency-graph-generator-plugin

Custom Graph Generator: Conditional Attributes for Dependency Nodes

NiC0x36 opened this issue · 0 comments

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