Mayday
Mayday

Reputation: 5136

Does gradle project with dependency to another project get libraries?

I have two projects:

ProjectA makes use of ProjectB

ProjectA:

-- Settings.graddle:

include ':projectB'

-- build.gradle:

dependencies {
  compile project(':projectB')
}

ProjectB:

-- build.gradle:

dependencies {
  compile group: 'org.modelmapper.extensions', name: 'modelmapper-jackson', version: '1.1.1'
}

This imports into ProjectB the modelmapper-jackson lib. (Expected behaviour)

It also imports modelmapper-jackson lib into ProjectA.

It might be this is the behaviour I want, but:

I would like to understand how to define what it is imported and what it is not, since in the future I might have more projects, and do not want all of them to have all the libraries

Is there anything in gradle I missed?

Upvotes: 1

Views: 1949

Answers (1)

shinjw
shinjw

Reputation: 3421

You can use gradle dependencies to inspect your dependency graph.

There are multiple approaches to stop transitive dependencies.

Set dependency to compileOnly in project B*

compileOnly group: 'org.modelmapper.extensions', name: 'modelmapper-jackson', version: '1.1.1'

Exclude in project A

dependencies {
  compile project(':projectB') {
    exclude module 'modelmapper-jackson'
}

Upvotes: 2

Related Questions