Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is this gradle flatDir example failing?

Tags:

gradle

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'
}
like image 956
Jay Koutavas Avatar asked Sep 26 '13 08:09

Jay Koutavas


People also ask

What is flatDir in Gradle?

flatDir(configureClosure) Adds an configures a repository which will look for dependencies in a number of local directories. flatDir(args) Adds a resolver that looks into a number of directories for artifacts. The artifacts are expected to be located in the root of the specified directories.

What can I use instead of flatDir?

Don't use flatDir!! Instead, use the Maven repository directory layout for your jars, sources jars, javadoc jars and poms. You can then configure a local directory as a maven repository in Gradle and your IDE will automatically find the javadocs and sources.

Is Gradle compile deprecated?

Gradle adds the dependency to the build output only, for use during runtime. That is, it is not added to the compile classpath. This configuration is deprecated (it's available in AGP 1.0-4.2).

What is a Gradle repo?

The location for storing modules is called a repository. By specifying the repositories for a project, Gradle can find and retrieve modules. Repositories can be in different forms, such as a local directory or a remote repository.


1 Answers

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").

like image 174
Peter Niederwieser Avatar answered Sep 28 '22 02:09

Peter Niederwieser