Gradle: how do I include a local jar from a dependent java project in an Android build?

妖精的绣舞 提交于 2019-11-28 23:32:38

This is not directly possible as local jars are not declared as transitive dependencies in Gradle.

You have two options:

  • merge the two jars in your java library so that the output contains the local jar.
  • create a different project with no source, only the jar, and make the project depend on it.

The second option gives you the ability to have more than one project depend directly on the local jar (on top of it becoming a transitive dependency). To do it, create a new gradle project and just put in its build.gradle the following:

configurations.create("default")
artifacts.add("default", file('somelib.jar'))

This simply register your jar as the default artifact published by the project and this will get consumed by the other projects.

In recent (4+, IIRC) versions of gradle, you can achieve this with the following configuration:

compile (project(':ProjectIDependOn')) {
  transitive = true
}

Setting transitive to true when depending on another project will expose all of that project's libraries to this project.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!