简体   繁体   English

gradle项目是否依赖于另一个项目获得库?

[英]Does gradle project with dependency to another project get libraries?

I have two projects: 我有两个项目:

ProjectA makes use of ProjectB ProjectA使用ProjectB

ProjectA: 项目A:

-- Settings.graddle: -Settings.graddle:

include ':projectB'

-- build.gradle: -build.gradle:

dependencies {
  compile project(':projectB')
}

ProjectB: 项目B:

-- build.gradle: -build.gradle:

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

This imports into ProjectB the modelmapper-jackson lib. 这会将modelmapper-jackson库导入ProjectB。 (Expected behaviour) (预期的行为)

It also imports modelmapper-jackson lib into ProjectA . 还将 modelmapper-jackson lib导入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? 我错过了gradle吗?

You can use gradle dependencies to inspect your dependency graph. 您可以使用gradle dependencies检查依赖关系图。

There are multiple approaches to stop transitive dependencies. 有多种方法可以阻止传递依赖。

Set dependency to compileOnly in project B* 在项目B *中将依赖项设置为compileOnly

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

Exclude in project A 排除在项目A中

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM