1

I have Gradle-Java project. I want to use a local library in a directory inside root project and use this library to sub projects.

something like this

root-project |-resources/libraries |-subproject1 |-subproject2 |-.. |-.. and so on

for example I want to use a library.jar from resources/library folder .I have seen some examples on subproject's build.gradle

depdencies{ compiles files('dir/some-files') }

but as far as my knowledge goes this only refer to files inside the subproject(kindly correct me I am wrong). I have seen also something like(or I am just imagining)

@root-project settings.gradle

include 'resource/library'

@sub-project build.gralde

compile project(':resources/library')

but i dont know what to do next to access the content. I want to know how to do this in gradle so I can put some dependencies in where multiple sub projects may use that library from root-project's directory.

I know it will be easy if I just uploaded that library to maven or jcenter. But Im reluctant since its a crappy one.

I will be grateful if someone teaches me or give some advice.

  • Which IDE are you using? – AsthaUndefined Sep 05 '17 at 03:33
  • Another thing if your sub-projects are under root-project then those libraries will also be there. Just try to refresh,clean and build your project after adding new libraries. – AsthaUndefined Sep 05 '17 at 03:37
  • @Astha Srivastava I am using Intellij community edition. I dont want to add the library direct to root-project gradle.build. Is there a way I can add that library from select sub-projects dependency? :) thank you – Victor Harlan Lacson Sep 05 '17 at 03:54
  • I dont have much idea about Intellij but you can try adding it in classpath of that project. Then that library will only be available for that particular project only. For adding the lib to project you can check this: https://stackoverflow.com/questions/1051640/correct-way-to-add-external-jars-lib-jar-to-an-intellij-idea-project – AsthaUndefined Sep 05 '17 at 04:15
  • @AsthaSrivastava yes this much easier, I am using Intellij and this is what I usually do in creating modules, dependencies and using libraries. But what I want to achieve is using gradle alone for handling the dependency. – Victor Harlan Lacson Sep 05 '17 at 04:25
  • If you want to add it in the gradle file, then it will be available for all the project because gradle is shared across the whole project and not in a particular sub-project. You can not add lib for a particular project in gradle. If you add it will be available for all the project that are linked to that gradle. – AsthaUndefined Sep 05 '17 at 04:41

1 Answers1

1

I found a solution to what I want to achieve here in case someone like me might have the same question.

dependencies {
compile files{'$rootDir/some-files
}

my bad I am googling wrong qusetion to the wrong key word.