I am trying to find a nice way of unpacking my dependencies from zip files to a folder in my project directory. I want to use a Sync task or similar to do it, because I would rather that Gradle handles it.
I am on Gradle 1.5 using the gradle wrapper.
This is what I hope the relevant portions of my build.gradle file:
The task unpackDependencies works just fine. unpackDependencies2 gives me the error message
C:\gitlab\penfirmware-zeus>gradlew unpackDependencies2
-i
Starting Build
Settings evaluated using empty settings script.
Projects loaded. Root project using build file 'C:\gitlab\penfirmware-zeus\build.gradle'.
Included projects: [root project 'penfirmware-zeus']
Evaluating root project 'penfirmware-zeus' using build file 'C:\gitlab\penfirmware-zeus\build.gradle'.
Compiling build file 'C:\gitlab\penfirmware-zeus\build.gradle' using BuildScriptClasspathScriptTransformer.
Compiling build file 'C:\gitlab\penfirmware-zeus\build.gradle' using BuildScriptTransformer.
FAILURE: Build failed with an exception.
* Where:
Build file 'C:\gitlab\penfirmware-zeus\build.gradle' line: 101
* What went wrong:
A problem occurred evaluating root project 'penfirmware-zeus'.
> Could not resolve all dependencies for configuration ':compile'.
> Could not find com.anoto:PatternLibrary-C:0.1.0.0.
Required by:
com.anoto:penfirmware-zeus:unspecified
> Could not find com.anoto:PPSSWLibrary-C:0.1.0.1.
Required by:
com.anoto:penfirmware-zeus:unspecified
‘unpackDependencies2’ resolves the ‘compile’ configuration in the configuration phase, rather than the execution phase. This will cause several problems. If you can live with a shared ‘into’, ‘from { configurations.compile.collect { zipTree(it) }}’ is an elegant solution. If you need separates 'into’s, I can’t think of an easy solution, and you may have to defer configuration with ‘gradle.taskGraph.whenReady { graph -> if (graph.hasTask(unpackDependencies2)) { … } }’. (Deferring configuration with ‘unpackDependencies2.doFirst { … }’ won’t work for a ‘Sync’ task; it will always be UP-TO-DATE.)
PS: ‘configurations.compile.resolvedConfiguration.resolvedArtifacts.each’ can be shortened to ‘configurations.compile.each’.
I will probably keep my old approach of synching by deleting the folder for now. I am only dealing with a few files in each dependency and they are small.
It would be really nice to have a more gradle-y version of it that could unpack dependencies in a separate folder, sort of like the unpackDependencies2 in my example. I can however live without it for now.