Programmatically add a dependency as non-transitive (via Java code)

I want to do something like

dependencies {
  compileOnly (project(":potato")) {
    transitive = false

in Java but I can’t seem to figure out how to… I’m looking at:

project.getDependencies().add("name", potatoProject, whatDoIPutHere??)

The only available option is Closure, presumably there is a way to use this from Java code, but usually there’s a second method with an Action parameter sitting next to it? Looking around the gradle codebase hasn’t helped me much.

Can I do this programmatically?

Hrmm, just realized I can access the underlying dependency object returned by add and cast it and then set it to transitive = false?

Dependency dep = project.getDependencies.add("name", potatoProject)
((ProjectDependency) dep).setTransitive(false)