Dennis Ich
Dennis Ich

Reputation: 3775

Gradle Multiproject - Better dependency control

I got a multi module project with an arbitrary number of spring-boot rest services which all run on their own embedded tomcat and some web frontends which it self must not contain any business logic. These will be configured as Zuul proxies and therefore do not need any other dependencies.

So in my top level build.gradle I can declare all dependencies which are common to all projects which in that case would be spring-boot-starter and log4j. Though all the rest services share nearly all their dependencies.

Is there a way to cluster dependencies? So I can say you are a frontend with minimal dependencies and you are a basic JPA project?

I know I could define dependencies for all separate but then it's doubled in many files.

Upvotes: 1

Views: 67

Answers (1)

Stanislav
Stanislav

Reputation: 28096

Take a look at the official user guide's "How to declare your dependencies", chapter 52.4.8. "Optional attributes". According to it, you are able to combine dependencies into some collections, which could be applied as project dependencies, as:

List groovy = ["org.codehaus.groovy:groovy-all:2.4.4@jar",
               "commons-cli:commons-cli:1.0@jar",
               "org.apache.ant:ant:1.9.4@jar"]
List hibernate = ['org.hibernate:hibernate:3.0.5@jar',
                  'somegroup:someorg:1.0@jar']
dependencies {
    runtime groovy, hibernate
}

So, you can create in the root build script a number of dependencies groups for different configurations (I mean one for frontend, one for JPA project and etc.). And then the only thing you need, is to apply this groups to the subprojects, which are of the reauired type.

Upvotes: 1

Related Questions