Programing

Maven 패키지는 작동하지만 Intellij의 빌드가 실패합니다.

lottogame 2020. 10. 21. 07:37
반응형

Maven 패키지는 작동하지만 Intellij의 빌드가 실패합니다.


내 maven repo의 로컬 jar에 대한 maven 종속성이있는 JDK 1.7 프로젝트가 있습니다.

Intellij를 사용하여 프로젝트를 빌드 할 수 없으며 기호를 찾을 수 없다는 오류가 발생합니다 (기호는 로컬 jar에서 패키지를 가져 오는 클래스입니다).

하지만 'mvn package'를 사용하여 프로젝트를 성공적으로 빌드 할 수 있습니다.

솔루션을 찾기 위해 너무 많은 시간을 보냈습니다.

  • 무효화 된 캐시
  • 'mvn clean install'로컬 jar 종속성
  • Intellij의 Maven 구성에서 'autoload snapshots'로 표시되었습니다.
  • Intellij의 Reimpoted Maven
  • Syncornized

이 오류는 이전에 몇 번 발생했지만 일반적으로 Intellij를 닫거나 'mvn clean install'을 수행하면 트릭이 발생했습니다.

도와주세요.


늦었지만 실행 mvn idea:idea하면 문제가 해결됩니다.


모든 .iml 및 POM을 삭제하십시오. 그런 다음 POM을 다시 프로젝트에 복사하여 붙여넣고 다시 열고 다시 가져옵니다.


다른 사람에게 도움이 될 수있는 경우를 대비하여 비슷한 문제 (IntelliJ가 아닌 mvn에서 프로젝트 빌드)가 발생했을 때 검색에서 가장 먼저 나온 것이기 때문에 더 많은 팁을 추가합니다.

내가 이것을 가지고 있었을 때 그것은 Windows와 Mac에서 다른 수정이었습니다.

Mac에서는 ItellijIDEA / Preferences / Build, Execution, Deployment / Build Tools / Maven / Maven Home Directory로 이동하여 번들 Maven이 아닌 별도로 설치된 Maven을 사용하도록 설정했습니다. 모든 빌드 문제가 해결되었습니다.

Windows에서 SSL과 관련된 idea.log에 예외가 표시되었으며 내 프로젝트 트리에는 외부 라이브러리 분기 아래에 Java 만 있습니다. 다른 사이트를 보면 IntelliJ가 시스템 하나 대신 자체 개인 JDK를 사용하는 것처럼 들립니다 (제 경우에는 이미 똑같은 JDK 버전이 설치되어 있지만). 내 시스템 JDK에는 IntelliJ 개인 JDK에없는 기업 Nexus 서버의 키 저장소에 인증서가 설치되어 있으므로 Nexus에서 파일을 가져 오려고 할 때 예외가 발생했습니다. 이를 위해 해결책은 IntelliJ를 종료하고 IDEA_JDK라는 환경 변수를 설정하여 적절한 인증서가있는 이미 설치 한 JDK를 가리 키도록 설정하고 IntelliJ를 다시 시작하는 것입니다. 모든 빌드 문제가 해결되었습니다.


내 .iml 파일과 pom이 충돌하여 문제를 일으키는 것으로 나타났습니다.


Maven ReImport는 다음과 같이 나를 위해 일했습니다 ...

여기에 이미지 설명 입력


IDE는 빌드를 수행 할 때 자체 번들 Maven 사본을 사용합니다. 터미널의 maven이 IDE와 다른 경우 동일해야합니다.

GOTO (Mac)-IntelliJ 아이디어-> 환경 설정-> 빌드, 실행, 배포-> 빌드 도구-> Maven. Maven 홈 디렉토리 경로 설정 터미널에서 사용하는 Maven 경로를 찾으려면 command를 입력 mvn -version하면 dir 경로를 포함한 세부 정보가 출력됩니다. Maven 홈 디렉토리 에 넣으십시오 .

안전을 위해 JDK 위치에 대해서도 동일한 작업을 수행 할 수 있습니다.

==== 그러한 문제를 일으킬 수있는 다른 것들 ===

mvn 패키지 또는 mvn clean install 빌드를 수행하는 경우 IDE 캐시로 작업을 수행해야합니다. 무엇보다도 이것은 일반적으로 이러한 오류에 도움이됩니다 .-->

파일-> 캐시 무효화


나는이 대화에 꽤 늦었다는 것을 알고 있지만, 다른 누군가가이 문제를 발견 할 경우를 대비하여 이것을 게시하고 싶었습니다. 이것이 발생하는 또 다른 이유는 올바른 저장소를 참조하지 않기 때문입니다. Intellij는 기본적으로 자체 Maven 저장소의 jar 대신 번들 버전의 jar를 선택합니다. 연결된 저장소가 올바른지 확인하십시오.


제 경우에는 iml이 동기화되지 않았기 때문에 특정 모듈에 대해 iml을 삭제 한 다음 maven 옵션에서 unignore project를 선택하여 iml을 다시 만듭니다.


"기호를 찾을 수 없음"은 인텔리가 "종속성"을 해결할 수 없음을 의미합니다. 따라서 "Analyze"-> "Analyze Dependencies"를 클릭 한 다음 "Analysis Scope"를 선택하여 "Dependency analysis"를 강제 할 수 있습니다.


명령 프롬프트에서 commnad 실행 : mvn idea:idea프로젝트를 마우스 오른쪽 버튼으로 클릭-> 메뉴에서 종속성 다시 가져 오기


나는 같은 문제가 있었다. 아이디어 설정에서 maven 버전을 3.0.5에서 3.0.4로 변경했으며 이제 모두 정상적으로 작동합니다. 그게 왜 도움이되는지 모르겠어요.


여기에있는 다른 답변의 많은 유용한 팁은 내 문제에 대해 효과가 있었던 솔루션을 추가하고 싶습니다 .

우리는 최근에 개인 Maven 저장소를 사용하기 시작 mvn -s settings.xml했으며 Maven cmdline을 호출 항상 사용합니다 . IntelliJ는 물론 private repo에 대해 알지 못하므로 약간의 도움이 필요합니다.

설정-> 빌드, 실행, 배포-> 빌드 도구-> Maven으로 이동하여 "사용자 설정 파일"옵션을 재정의합니다.

여기에 이미지 설명 입력


캐시를 무효화하고 Maven을 설치된 버전으로 변경했지만 아무것도 작동하지 않았습니다.

Closing and recreating a new project resolved it.


I closed the project and imported it again by clicking on the root pom (not just the folder, but the pom file itself).


I tried everything above with no joy. However I did one thing that finally got it to work:

I went to C:\Users\.IntellijJIdea2018.2 and just deleted the entire folder.

It removes all the settings and cache for IntelliJ. I had to reimport my project from scratch but a simple remove and reimport hadn't worked before, but this finally got it working again.


If you are using gradle , try below command.This resolved my issue

gradle cleanIdea idea


This simple procedure takes about 1 minute without any risc.

  • Close IntelliJ
  • Delete ONLY the IntelliJ specific files like .idea/*, *.iml, .settings, etc. Suggested was deleting the POM as well, but that is not necessary IMHO.
  • Then re-create the project in IntelliJ using: File > New > Project from existing Sources > follow the steps. Be aware NOT to import multiple profiles or (same projects).

I had the same problem. Go to:

File -> Project Structure -> Module. Select your module and under "Dependencies" tab, make sure that all the maven dependencies are added.

To make sure you are warned about a similar issue in the idea editor: switch from "Dependencies tab" to "Sources" and add mark your src as source.


Delete the .idea folder and close the IDE

open the IDE again and import the project which will do a fresh import because .IDEA folder is deleted by us earlier

Check the external libraries module and if it is not populated with the required dependencies then check if the maven settings.xml location is given correctly in the IDE


There is also a possibility which was not mentioned. If you import library from com.sun.*. It will also cause this problem.

Programs works when run in ide, cause these classes in com.sun.* are all in jre/lib directory, it will be loaded when running. But when you run mvn package, these libraries won't be accessible because of the restriction of oracle since java 1.6(these libraries was deprecated in a way). To solve this problem, you can add

<build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.3.2</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                    <encoding>UTF-8</encoding>
                    <compilerArguments>
                        <verbose />
                        <bootclasspath>C:/Program Files/Java/jdk1.8.0_161/jre/lib/rt.jar</bootclasspath>
                    </compilerArguments>
                </configuration>
            </plugin>
        </plugins>
    </build>

remember to replace the cootclasspath with you own path of rt.jar

You can search Access restriction: The type XXX is not accessible due to restriction on required library for more detail.

참고 URL : https://stackoverflow.com/questions/18316857/maven-package-works-but-intellijs-build-fails

반응형