programing tip

기본 클래스 org.gradle.wrapper.GradleWrapperMain을 찾거나로드 할 수 없습니다.

itbloger 2020. 6. 29. 08:11
반응형

기본 클래스 org.gradle.wrapper.GradleWrapperMain을 찾거나로드 할 수 없습니다.


내가 좋아하는 로컬 디렉토리를 삭제하여 전체 프로젝트를 청소 ~/.gradle, ~/.m2 ~./android~/workspace/project/.gradle및 chosing File -> Invalidate Caches / Restart...안드로이드 스튜디오에서. 이제 명령을 실행 ./gradlew하면 다음과 같은 결과가 나타납니다.

usr$ ./gradlew tasks
Error: Could not find or load main class org.gradle.wrapper.GradleWrapperMain

말할 것도없이, 너무 많이 삭제했습니다. 문제는 어떻게 다시 수리 할 수 ​​있습니까? 이 문제를 해결하는 방법에 대한 아이디어가 있습니까?


gradlewgradle wrapper 실행 파일입니다-Windows의 배치 스크립트 및 다른 곳의 쉘 스크립트입니다. 당신이 당신의 다음 행을 포함하는 경우 build.gradle,

task wrapper(type: Wrapper) {
    gradleVersion = '4.1'
}

gradle wrapper 스크립트가 소스 폴더에 추가됩니다. 랩퍼 스크립트는 호출 될 때 정의 된 gradle 버전을 다운로드하여 실행합니다. 래퍼를 프로젝트와 함께 배포하면 누구나 Gradle을 미리 설치하지 않고도 작업 할 수 있습니다. 또한 빌드 사용자는 빌드와 함께 설계된 Gradle 버전을 사용해야합니다.

삭제에서 gradlew가 의존하는 것을 삭제했습니다. 소스 저장소에서 gradlew 파일 만 가져 오거나 gradle이 설치된 경우 gradle wrapper복원 할 수 있습니다.

심판 : Gradle Wrapper


@RaGe의 대답 외에도 .jar파일 을 무시하고 전역 git ignore가 발생하여 gradle wrapper jar가 절대 커밋되지 않은 상황에 직면했을 수 있습니다 . 따라서 시도 후 Jenkins 서버에서 해당 오류가 발생했습니다 /var/lib/jenkins/my_project/gradlew build. 항아리를 강제로 추가 한 다음 커밋해야했습니다.

git add -f gradle/wrapper/gradle-wrapper.jar

내 경우는 세계적인이었다 .gitignore, HankCa의 대답 @에 설명 된대로 .

각 Gradle 프로젝트에서 기억해야 할 항아리를 강제로 추가하는 대신 전역에 래퍼 항아리를 다시 포함시키는 재정의를 추가했습니다 .gitignore.

*.jar
!gradle/wrapper/gradle-wrapper.jar

Gradle을 사용하는 많은 프로젝트가 있으므로 유용합니다. Git은 이제 래퍼 용기를 포함하도록 상기시켜줍니다.

이 오버라이드 (override)는, 너무 오래 위의 어떤 디렉토리로 작동합니다 gradle-wrapper.jar(예 gradle와는 wrapper) 무시하지 않습니다 - 자식은 성능상의 이유로 무시 디렉토리에서 내려하지 않습니다 .


나를 위해 일한 것은 먼저 실행하는 것입니다.

 gradle wrapper

성공적인 빌드 후 나는 달릴 수 있었다

./gradlew assembleRelease

참고 : gradle wrapper첫 실행을 실행할 있습니다 brew install gradle. 설치가 성공한 경우 gradle wrapper프로젝트 루트에서 실행하십시오 .

출처와 감사 : http://gradle.org/docs/current/userguide/gradle_wrapper.htmlhttps://stackoverflow.com/users/745574/rage


내 경우에는 wrapper폴더를 복사하는 동안 하위 폴더를 제외 gradle하고 동일한 오류가 발생했습니다.

기본 클래스 org.gradle.wrapper.GradleWrapperMain을 찾거나로드 할 수 없습니다.

다른 위치에서 랩퍼를 복사 할 경우 올바른 폴더 구조를 사용해야합니다.

├── build.gradle
├── gradle
│ └── 포장지
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
└── settings.gradle

프로젝트의 gradle-wrapper.jar디렉토리 gradle/wrapper파일 이 없을 수 있습니다 .

아래와 같이 build.gradle 파일에서이 스크립트를 통해이 파일을 생성해야합니다.

task wrapper(type: Wrapper) {
   gradleVersion = '2.0' // version required
}

작업을 실행하십시오.

gradle wrapper

gradle 2.4 이상을 사용하면 전용 작업을 추가하지 않고도 래퍼를 설정할 수 있습니다.

gradle wrapper --gradle-version 2.3

또는

gradle wrapper --gradle-distribution-url https://myEnterpriseRepository:7070/gradle/distributions/gradle-2.3-bin.zip

모든 세부 사항은 이 링크 에서 찾을 수 있습니다


gradlew.bat를 루트 폴더에 복사하고 gradlew-wrapper를 gradlew 폴더에 복사 할 수도 있습니다.

그것은 나를 위해 일한 것입니다.


필자의 경우 (Windows 10 사용) gradlew.bat에는 다음 코드 줄이 있습니다.

set DIRNAME=%~dp0
if "%DIRNAME%" == "" set DIRNAME=.
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%

The APP_HOME variable is essentially gradles root folder for the project, so, if this gets messed up in some way you are going to get:

Error: Could not find or load main class org.gradle.wrapper.GradleWrapperMain

For me, this had been messed up because my project folder structure had an ampersand (&) in it. Eg C:\Test&Dev\MyProject

So, gradel was trying to find the gradle-wrapper.jar file in a root folder of C:\Test (stripping off everything after and including the '&')

I found this by adding the following line below the set APP_HOME=%DIRNAME% line above. Then ran the bat file to see the result.

echo "%APP_HOME%"

There will be a few other 'special characters' that could break a path/directory.


I followed the answers from above when i ran into this. And If you are having this issue than make sure to force push both jar and properties files. After these two, i stopped getting this issue.

git add -f gradle/wrapper/gradle-wrapper.jar
git add -f gradle/wrapper/gradle-wrapper.properties

@HankCa solved the problem in my case as well. I decided to change my dangerous **/*.jar ignores to self-explanatory ones like src/**/lib/*.jar to avoid such problems in the future. Ignores starting with **/* are a bit too hazardous, at least to me. And it's always a good idea to get the idea behind a .gitignore row just by looking at it.


In my case gradle-wrapper.jar got corrupted after replacing a bunch of files. Reverting to original one resolved the problem.


I fixed this problem with next fix (maybe it will help someone):

Just check if the parent folders of your project folder have names with spaces or other forbidden characters. If yes - remove it.

"C:\Users\someuser\Test Projects\testProj" - on this case "Test Projects" should be "TestProjects".


I saw the same error but in my case it was a fresh Git installation without LFS installed. The repo in question was set up with LFS and the gradle-wrapper.jar was in LFS so it only contained a pointer to the LFS server. The solution was simple, just run:

git lfs install

And a fresh clone did the trick. I suppose git lfs pull or just a git pull could have helped as well but the person with the problem decided to do a fresh clone instead.


On Gradle 5.x I use:

wrapper {
    gradleVersion = '5.5.1'
}

In my case , I had removed gradlew and gradle folders from project. Reran clean build tasks through "Run Gradle Task" from Gradle Projects window in intellij

enter image description here


For Gradle version 5+, this command solved my issue :

gradle wrapper

https://docs.gradle.org/current/userguide/gradle_wrapper.html#sec:adding_wrapper


if it's a new project, remove existing folder and run $ npm install -g react-native-cli

check that runs without any error

참고URL : https://stackoverflow.com/questions/29805622/could-not-find-or-load-main-class-org-gradle-wrapper-gradlewrappermain

반응형