Gradle이 종속성을 다시 다운로드하도록 강제 할 수 있습니까?
저장소에서 종속성을 다시 다운로드하도록 Gradle에 어떻게 알릴 수 있습니까?
일반적으로 명령 줄 옵션 --refresh-dependencies 를 사용하여 캐시의 종속성을 새로 고칠 수 있습니다 . 에서 캐시 된 파일을 삭제할 수도 있습니다 ~/.gradle/caches
. 다음 빌드에서 Gradle은 다시 다운로드를 시도합니다.
특정 사용 사례는 무엇입니까? 동적 종속성 버전 또는 SNAPSHOT 버전을 사용합니까?
Unix 시스템에서는 다음을 사용하여 Gradle이 다운로드 한 기존 아티팩트 (아티팩트 및 메타 데이터)를 모두 삭제할 수 있습니다.
rm -rf $HOME/.gradle/caches/
최신 버전의 Gradle을 사용하는 경우 --refresh-dependencies 옵션을 사용할 수 있습니다.
./gradlew build --refresh-dependencies
Gradle 매뉴얼을 참조 할 수 있습니다 .
--refresh-dependencies 옵션은 Gradle이 확인 된 모듈 및 아티팩트에 대해 캐시 된 모든 항목을 무시하도록 지시합니다. 동적 버전이 다시 계산되고 모듈이 새로 고쳐지고 아티팩트가 다운로드되어 구성된 모든 저장소에 대해 새로운 해결이 수행됩니다.
종속성을 '변경 중'으로 플래그 지정하여 Gradle에 빌드 스크립트에서 일부 종속성을 다시 다운로드하도록 지시 할 수 있습니다. Gradle은 24 시간마다 업데이트를 확인하지만 resolutionStrategy DSL을 사용하여 구성 할 수 있습니다. SNAPSHOT 또는 NIGHTLY 빌드에 이것을 사용하는 것이 유용하다는 것을 알았습니다.
configurations.all {
// Check for updates every build
resolutionStrategy.cacheChangingModulesFor 0, 'seconds'
}
퍼지는:
dependencies {
implementation group: "group", name: "projectA", version: "1.1-SNAPSHOT", changing: true
}
압축 :
implementation('group:projectA:1.1-SNAPSHOT') { changing = true }
이 포럼 스레드 에서이 솔루션을 찾았습니다 .
MAC의 경우
./gradlew build --refresh-dependencies
Windows의 경우
gradlew build --refresh-dependencies
시도 할 수도 있습니다 gradlew assembleDevelopmentDebug --refresh-dependencies
Windows의 경우 ... gradle이 특정 종속성을 다시 다운로드하도록하려면 :
아래 디렉토리에서 다시 다운로드하려는 종속성을 삭제하십시오.
C:\Users\[username]\.gradle\caches\modules-2\files-2.1
경로에서 모든 메타 데이터 디렉토리를 삭제합니다 .
C:\Users\[username]\.gradle\caches\modules-2\metadata-*
프로젝트의 루트 디렉터리에서 실행
gradle build
(또는gradlew build
gradle 래퍼를 사용하는 경우)합니다.
참고 : 위의 파일 경로에있는 숫자는 사용자에 따라 다를 수 있습니다.
캐시 된 jar로 폴더를 제거 할 수 있습니다.
제 경우에는 Mac 에서 라이브러리가 다음 경로에 캐시되었습니다.
/Users/MY_NAME/.gradle/caches/modules-2/files-2.1/cached-library-to-remove
캐시 된 라이브러리 폴더 (위의 예에서 "cached-library-to-remove")를 제거하고 내 프로젝트의 빌드 폴더를 삭제 한 다음 다시 컴파일했습니다. 그때 신선한 라이브러리가 다운로드되었습니다.
여기의 일부 답변이 제안하는 것처럼 전체 gradle 캐시를 제거하는 대신 특정 그룹 또는 아티팩트 ID에 대한 캐시를 삭제할 수 있습니다. 다음 기능을 추가했습니다 .bash_profile
.
deleteGradleCache() {
local id=$1
if [ -z "$id" ]; then
echo "Please provide an group or artifact id to delete"
return 1
fi
find ~/.gradle/caches/ -type d -name "$id" -prune -exec rm -rf "{}" \; -print
}
용법:
$ deleteGradleCache com.android.support
Then, on the next build or if you resync, gradle will re-download dependencies.
There is 2 ways to do that:
- Using command line option to refresh dependenices cashe.
- You can delete local cache where artefasts are caches by Gradle and trigger build
Using --refresh-dependencies option:
./gradlew build --refresh-dependencies
Short explanation --refresh-dependencies option tells Gradle to ignore all cached entries for resolved modules and artifacts.
Long explanantion
- WIth –refresh-dependencies’ Gradle will always hit the remote server to check for updated artifacts: however, Gradle will avoid downloading a file where the same file already exists in the cache.
- First Gradle will make a HEAD request and check if the server reports the file as unchanged since last time (if the ‘content-length’ and ‘last-modified’ are unchanged). In this case you’ll get the message: "Cached resource is up-to-date (lastModified: {})."
- Next Gradle will determine the remote checksum if possible (either from the HEAD request or by downloading a ‘.sha1’ file).. If this checksum matches another file already downloaded (from any repository), then Gradle will simply copy the file in the cache, rather than re-downloading. In this case you’ll get the message: "“Found locally available resource with matching checksum: [{}, {}]”.
Using delete: When you delete caches
rm -rf $HOME/.gradle/caches/
You just clean all the cached jars and sha1 sums and Gradle is in situation where there is no artifacts on your machine and has to download everything. Yes it will work 100% for the first time, but when another SNAPSHOT is released and it is part of your dependency tree you will be faced again in front of the choice to refresh or to purge the caches.
This worked for me. Make sure Gradle is not set to offline by unchecking button at File>Settings>Gradle>Offline Work.
Add this to the top level of your build.gradle, nice to have above dependencies
configurations.all {
resolutionStrategy.cacheChangingModulesFor 0, 'seconds'
}
I made sure my dependencies are written like this:
implementation('com.github.juanmendez:ThatDependency:ThatBranch-SNAPSHOT') {
changing = true
}
Thereafter, I open the Gradle panel in Android Studio and click the blue circle arrows button. I can always see my updates getting a new fresh copy.
Mb I'm too late however my solution is for single repository. I think deleting ~/.gradle/* is overkill. The problmem I've bumped into was that I was deleting directory where sources were and gradle was getting another version not from nexus. To avoid that I run the next:
~/.gradle$ find . -type d -name 'group.plugins.awssdk'
./caches/modules-2/files-2.1/group.plugins.awssdk
./caches/modules-2/metadata-2.23/descriptors/group.plugins.awssdk
~/.gradle$ rm -r ./caches/modules-2/files-2.1/group.plugins.awssdk ./caches/modules-2/metadata-2.23/descriptors/group.plugins.awssdk
After that gradle is dragging files from nexus.
delete this directory:
C:\Users\[username]\.gradle
None of the solutions above worked for me.
If you use IntelliJ, what resolved it for me was simply refreshing all Gradle projects:
For those who are wondering where to run gradle commands:
Open android studio-->Click on Terminal(You will find it in the base of android studio)-->The command tool will open--->Type your command(gradlew build --refresh-dependencies)
Deleting all the caches makes download all the dependacies again. so it take so long time and it is boring thing wait again again to re download all the dependancies.
How ever i could be able to resolve this below way.
Just delete groups which need to be refreshed.
Ex : if we want to refresh com.user.test group
rm -fr ~/.gradle/caches/modules-2/files-2.1/com.user.test/
then remove dependency from build.gradle and re add it. then it will refresh dependencies what we want.
For Android Studio 3.4.1
Simply open the gradle tab (can be located on the right) and right-click on the parent in the list (should be called "Android"), then select "Refresh dependencies".
This should resolve your issue.
I think gradle 2.14.1 fixes the issue. The accepted answer is correct, but there is a bug in gradle with –refresh-dependencies. 2.14.1 fixes that.
See https://discuss.gradle.org/t/refresh-dependencies-should-use-cachechangingmodulesfor-0s/556
For the majority of cases, just simply re-building the project should do the trick. Sometimes you have to run ./gradlew build --refresh-dependencies
as several answers have already mentioned (takes a long time, depending on how much dependencies you have). How ever, sometimes none of those will work: the dependency just won't get updated. Then, you can do this:
- Remove dependency from your gradle file
- Run / debug your project and wait for it to fail (with
NonExistingClass
reason) - Hit "build project" and wait for it to finish successfully
- Run / debug once again
This is ridiculous and seems like madness, but I actually do use this procedure daily, simply because the dependency I need can be updated dozens of times and none of adequate solutions would have any effect.
You can do it like this
https://marschall.github.io/2017/04/17/disabling-gradle-cache.html
To quote from Disabling the Gradle Build Cache
The Gradle build cache may be a great thing when you’re regularly building >large projects with Gradle. However when only occasionally building open source >projects it can quickly become large.
To disable the Gradle build cache add the following line to
~/.gradle/gradle.properties
org.gradle.caching=false
You can clean the existing cache with
rm -rf $HOME/.gradle/caches/ rm -rf $HOME/.gradle/wrapper/
If you are using eclipse and if you want force eclipse to re load dependencies you could try below command
gradlew clean cleaneclipse build eclipse --refresh-dependencies
You need to redownload it, so you can either manually download and replace the corrupted file and again sync your project . Go to this location C:\users[username].gradle\wrapper\dist\gradle3.3-all\55gk2rcmfc6p2dg9u9ohc3hw9\gradle-3.3-all.zip Here delete gradle3.3allzip and replace it by downloading again from this site https://services.gradle.org/distributions/ Find the same file and download and paste it to that location Then sync your project. Hope it works for you too.
참고URL : https://stackoverflow.com/questions/13565082/how-can-i-force-gradle-to-redownload-dependencies
'Programing' 카테고리의 다른 글
IntelliJ IDEA 프로젝트에 외부 jar (lib / *. jar)를 추가하는 올바른 방법 (0) | 2020.10.02 |
---|---|
입력 유형 지정 = "파일"버튼 (0) | 2020.10.02 |
iOS 8 UITableView 구분 기호 삽입 0이 작동하지 않음 (0) | 2020.10.02 |
기본적으로 라디오 버튼을 선택하는 방법은 무엇입니까? (0) | 2020.10.02 |
라이브러리를 사용하지 않고 JavaScript에서 다른 요소 뒤에 요소를 삽입하는 방법은 무엇입니까? (0) | 2020.10.02 |