28

I have a new project, it depends on classes at legacy project, not jar files but actual classes. How can I make these directories a dependency for gradle compile?

Mashimom
  • 447
  • 1
  • 7
  • 18
  • https://stackoverflow.com/q/35545405/7926064 has some hints and links to bugs and discussions – BNT Jun 19 '17 at 15:24

1 Answers1

43
dependencies {
    compile files("relative/path/to/classes/dir")
}

For further details, check out the Gradle User Guide.

Peter Niederwieser
  • 121,412
  • 21
  • 324
  • 259
  • This seems add all files in that directory into the classpath as jar files. Can we just add a folder? I have the same problem. – zggame Jan 29 '15 at 17:33
  • This adds the specified directory to the class path, which effectively adds all class files (not Jar files) contained in that directory. This is what the OP asked. – Peter Niederwieser Jan 29 '15 at 22:26
  • You are correct. This adds the directory instead of the file of the directory. `fileTree()` add all the files of the folders (recursively) I think. I am confused with it. Thank you very much. – zggame Jan 30 '15 at 21:48
  • 2
    Shouldn't this be `classpath` instead of `compile` ? – Elias Dorneles Feb 23 '17 at 16:48
  • @elias OP asked "dependency for gradle `compile`" – TWiStErRob Dec 28 '17 at 17:54
  • `classpath` is only used for buildscript dependencies. Also, `compile` is now deprecated in favor of `api|implementation`. – Ajax Nov 03 '18 at 09:31