Fix a cache corruption bug caused by including a rule's output on its classpath.

Apparently, a `java_library` was including its output JAR on the classpath when
building itself. This means that removing `srcs` from a `java_library` and then rebuilding
the rule would still succeed if the output JAR was still around from the previous build.
This would explain some rebuild issues that we have received anecdotal reports of,
but have not been able to reproduce.

This diff solves the bug by fixing `DefaultJavaLibraryRule.getDeclaredClasspathEntries()`
so that its return value matches that which is required by its Javadoc:

 * @return The set of entries to pass to {@code javac}'s {@code -classpath} flag in order to
 *     compile the {@code srcs} associated with this rule.  This set only contains the classpath
 *     entries for those rules that are declared as direct dependencies of this rule.
public ImmutableSetMultimap<JavaLibraryRule, String> getDeclaredClasspathEntries();

Test Plan:
Added an integration test to make sure changing the set of files in a java_library's srcs
causes a rebuild.
Added a unit test to make sure the `-classpath` argument passed to `javac` does not include
the output JAR of the `java_library` rule being built.
7 files changed
tree: e3f84a36be8e29d57ebc9a4d2dcfc6ade1ec97d2
  1. .buckconfig
  2. .classpath
  3. .gitignore
  4. .idea/
  5. .project
  6. .travis.yml
  7. DEFS
  10. bin/
  11. buck.iml
  12. build.xml
  13. config/
  14. docs/
  15. lib/
  16. plugin/
  17. pmd/
  18. scripts/
  19. src/
  20. test/
  21. testdata/
  22. third-party/


Buck is an Android build tool. To see what Buck can do for you, check out the documentation at

Build Status


To build Buck, run the following:

git clone
cd buck
./bin/buck --help


Apache License 2.0