How to add project dependency from plugin


I’m working on a gradle plugin and at some point i need to add some dependencies to active project: an artifact from maven and a local lib project.
The problem is that method project.dependencies.add() doesn’t work for projects. And project.dependencies.project() requires Map as an argument (wasn’t able to find what exactly should i put in that Map). So my question is: how can i add project by name specified in settings.gradle ?

Here is an example:

class LocalLibsPlugin implements Plugin , DependencyResolutionListener {
    Project project

    void apply(Project project) {
        this.project = project

    void beforeResolve(ResolvableDependencies resolvableDependencies) {
        def compileDeps = project.getConfigurations().getByName("compile").getDependencies()
        println "adding maven lib:" // this one works fine:
       compileDeps.add(project.getDependencies().create("org:myFirstLib:2.1.3", { artifact { name = "myFirstLib-release"; type = 'aar' }}))
        println "adding local project(\":mySecondLib\")"  // this one doesn't:
        project.dependencies.add 'compile', project.dependencies.project(':mySecondLib') 

    void afterResolve(ResolvableDependencies resolvableDependencies) {}

Thanks in advance!

The map notation for project dependencies can be found in the documentation for DependencyHandler.

The link directly to the section didn’t seem to work at time of posting, so here’s the full address: