MAIN IDEA I want to save my external dependencies to a lib folder, in order to build a project offline and without some gradle cache information. The lib folder is part of the project and will be commit to the repository.
If an other user checkout the project he can build this project without internet connections.
ISSUES I try to write a task which copy project dependencies to folder according the maven repoistory folder layout.
is there a better way to resolve my requirement. If not, how can i resolve the transitive dependencies to store it in a maven repository directory layout?
…but, the build is not declarative and readable anymore…according to my understanding, this logic should be mapped to a gradle plugin…i will learn how to write a plugin and post my solution.
You can hide a lot of the complexity in a separate gradle script. If you create a ‘foo.gradle’ file in the ‘gradle’ subdirectory, you can include it via
You can also probably shorten a lot of your code by doing something like
task copyToLib << {
[ 'compile','runtime','testCompile' ].each { mode ->
copy {
from configurations.getByName(mode).files
into ext."${mode}Lib"
}
}
}
That should eliminate most of the Copy tasks you have created. If you read up on the ‘Copy’ task (or the equivalent ‘project.copy’ which I used, you can probably make your copying even a bit smarter.
I would also suggest you only run the task manually when needed, not everytime you run gradle.
Always use a ‘Copy’ task over the ‘project.copy’ method, unless there is a very specific reason not to. A ‘Copy’ task can have arbitrary many from-into pairs (e.g ‘into(“bar”) { from “foo” }’), in addition to the (mandatory) top-level ‘into’.
I noticed while testing that some tasks has not been exectued. I’m not sure buti also when i change the project dependencies the tasks has not been executed…