To cache the actual compiled dependencies, rather than caching the source tarballs or caching object files, adding the Cellar and opt directories to the appropriate packages in the cache and using the appropriate before_install check works fine.
You can also add all /usr/local/Cellar/ and /usr/local/opt/ , but this will add all installed homebrew packages, not just the ones you need.
An example from a project that depends on openssl, libevent, and check:
cache: directories: - /usr/local/Cellar/openssl - /usr/local/opt/openssl - /usr/local/Cellar/libevent - /usr/local/opt/libevent - /usr/local/Cellar/check - /usr/local/opt/check before_install: - test -d /usr/local/opt/openssl/lib || { rmdir /usr/local/opt/openssl; brew install openssl; } - test -d /usr/local/opt/libevent/lib || { rmdir /usr/local/opt/libevent; brew install libevent; } - test -d /usr/local/opt/check/lib || { rmdir /usr/local/opt/check; brew install check; }
rmdir necessary because TravisCI creates cached directories if they do not exist, and brew install fails if /usr/local/opt/$package is a directory (unlike the link to the specific installed version in the cellar). For the same reason, test tests are for a subdirectory, and not for the main package directory.
Note that this approach requires that your own project can pick up the dependencies installed in /usr/local/opt .
source share