6

I'm completely new to gradle. I've put the following build.gradle together as a means of seeing how dependencies get pulled from a flatDir repository. The 'localrepo' directory contains two files 'a.txt', and 'b.txt' and nothing else. When I run 'gradle dependencies' I get failures:

:dependencies

------------------------------------------------------------
Root project
------------------------------------------------------------

copytest
+--- :a.txt: FAILED
\--- :b.txt: FAILED

BUILD SUCCESSFUL

Total time: 5.506 secs

Why?

Here's my build.gradle:

configurations {
  copytest
}

repositories {
  flatDir name: 'localRepository', dirs: 'localrepo'
}

dependencies {
  copytest ':a.txt'
  copytest ':b.txt'
}

task copyTask(type: Copy) {
  from configurations.copytest
  into 'result'
}

1 Answer 1

16

A flatDir repo uses a simple heuristic to turn the dependency's module name into the filename to be searched for. If you specify :a.txt, Gradle will search for a.txt.jar, or, if you have project.version set, also for a.txt-theVersion.jar. To add arbitrary files to a configuration, instead of declaring a flatDir repo, you can use copytest files("some/path").

3
  • Thanks. The point of the exercise is to learn how to use repositories for non-jar files. I need to ultimately setup an Artifactory containing lots of binaries that have nothing to do with Java at all (images, .pdf files, etc.) It's my understanding that repositories can "hold anything". So, with that said, how do I access my simplistic example of pulling out two .txt files? (As an aside, if I rename the files to 'a.jar' and 'b.jar', it still fails.) Sep 26, 2013 at 8:31
  • 1
    If you want to prepare for using Artifactory, you need to declare a maven or ivy repository, not a flatDir repository. You could use a file: repository URL, but I'd probably go with a local Artifactory installation. To answer your second question, you'd have to rename the file to a.txt.jar. Maybe :a:1.0@txt would match a.txt (or a-1.0.txt), but I'm not sure, as flatDir repos are special and limited. Sep 26, 2013 at 8:51
  • :a:1.0@txt did the trick, Peter. Thank you. Now that I have my contrived test completed, I can start evolving things into using Artifactory. Sep 26, 2013 at 9:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.