-
Gradle dependency 초기화Build/Gradle 2021. 2. 21. 23:05728x90반응형
가끔씩 Gradle에서 Dependency들을 제대로 불러오지 못하거나 꼬이는 경우가 생긴다. 이때 해결할 수 있는 몇 가지 방법들을 다루어 보자.
해결 방안
1. Intellij - Invalidate Caches / Restart...
Intellij 환경에서 gradle 관련해서 꼬이거나 문제가 생기면 이 방법을 추천한다. project와 관련된 dependency들을 초기화하고 재시작시켜준다. 이 방법으로 많이 해결했었다.
Shift 두번 연타 -> invalidate 입력 (Invalidate Caches / Restart... 선택) -> 엔터
2. gradlew build refresh dependencies
gradle에서 제공하는 방법으로 dependency들에 대해 refresh를 시킨다. 해당 옵션에 대해 아래와 같이 설명하고 있다.
To refresh all dependencies in the dependency cache, use the --refresh-dependencies option on the command line.
프로젝트 위치로 이동 ./gradlew build --refresh-dependencies
3. 다운 받은 dependency들을 모두 삭제
dependency들은 $HOME/.gradle/caches/에 저장이 되어 있다. 해당 디렉토리를 날려주면 새로 gradle build할 때 파일이 없으니 다시 다운로드하게 된다. 어찌 보면 가장 확실한(?) 방법이다. 그런데 내 맥북 기준으로 용량이 2.6G나 되기에(gralde 버전도 참 많이 깔려 있다) 이를 다 지우고 다시 받으려면 한 세월이라 최후의 방법으로 사용하자.
rm -rf $HOME/.gradle/caches
참고 자료
- https://docs.gradle.org/current/userguide/dependency_management.html#sec:refreshing-dependencies
- https://stackoverflow.com/questions/13565082/how-can-i-force-gradle-to-redownload-dependencies
반응형