How to write the dependencies block in a Java Plugin?

I am writing a conventions plugin in Java and I would like to add the dependencies below from the java plugin. Assume I have the dependency code below.

dependencies {
    implmenentation(platform(project(":components:platform")))
    testImplementation("nl.jqno.equalsverifier:equalsverifier")
    testImplementation("org.springframework.boot:spring-boot-starter-test")
}

In my plugin I am trying to do the following

public class ConventionsPlugin implements Plugin<Project> {

  @Override
  public void apply(Project project) {

   // how do I correctly add a platform dependency and a regular dependency, I have been looking   through
  // the java API but I am not able to figure it so far. 
    project.getConfigurations().getByName(JavaPlugin.IMPLEMENTATION_CONFIGURATION_NAME)
        .getAllDependencies().
  }
}

how do I correctly add a platform dependency and a regular dependency, I have been looking through the java API but I am not able to figure it so far?

You can do

DependencyHandler dependencies = project.getDependencies();
Dependency platform = dependencies.platform​(project.project(":components:platform"));
dependencies.add("implementation", platform);
dependencies.add("testImplementation", "nl.jqno.equalsverifier:equalsverifier");
dependencies.add("testImplementation", "org.springframework.boot:spring-boot-starter-test");
1 Like