0

I'm looking into using Gradle instead of Ant/Ivy. I'm trying to create dependencies between my projects for all configurations, so that for example, project1.compile depends on project2.compile, project1.runtime depends on project2.runtime, etc.

In Ivy, I did this with the following XML:

project1/ivy.xml

<dependency conf="*->@" org="myorg" name="project2" rev="latest.integration" />

In Gradle, here's what I have tried:

project1/build.gradle

configurations.each { config ->
    config.dependencies.add project(path: ':project2', configuration: config.name)
}

But it complains that the project function doesn't exist:

> Could not find method project() for arguments [{path=:project2, configuration=archives}] on project ':project1'.

Any ideas how to do this?

Sean Adkinson
  • 8,425
  • 3
  • 45
  • 64

2 Answers2

2
configurations.all { config ->
    project.dependencies.add(config.name, 
        project.dependencies.project(
            path: ':project2', configuration: config.name))
}
Peter Niederwieser
  • 121,412
  • 21
  • 324
  • 259
  • Thank you, worked great. In order to make this piece of code available in all sub-projects, I added a function in the root project that is called like this: `addProjectDependency(project, ':project2')`. My hope was to define something like an 'all' configuration that would do the same thing. Any tips or feedback on my approach or a better way to make this reusable? Thanks again. – Sean Adkinson Dec 31 '13 at 16:30
0

To anyone looking for a working answer to the same question in 2023:

configurations.all {
    withDependencies {
        add(
            project.dependencies.module("org.example:example-artifact:0.0.1") // external dependency
        )
        add(
            project.dependencies.platform("org.example:example-bom:0.0.1") // platform BOM
        )
        add(
            project.dependencies.project(":project2") // project submodule
        )
    }
}