Nice programing

IntellijIDEA가 Maven 종속성에 지정된 클래스를 인식하지 못함

nicepro 2021. 1. 6. 20:49
반응형

IntellijIDEA가 Maven 종속성에 지정된 클래스를 인식하지 못함


Maven으로 만든 IntellijIDEA에 프로젝트가 있습니다. 그런 다음 Pom.xml 파일에 종속성 및 외부 저장소 집합을 지정했습니다.

"mvn install"을 수행하면 프로젝트가 명령 줄에서 잘 빌드됩니다. IDE에서 코드 파일을 열면 Maven 종속성에 의해 처리되는 모든 클래스가 인식되지 않는다고 표시되지만 필수 JAR을 빌드 경로에 추가하지 않은 경우 일반 프로젝트 에서처럼 인식됩니다.

내 Eclipse Maven 프로젝트 (IntelliJ가 아닌)에서 일반적으로 왼쪽에 "Maven Dependencies"라는 추가 디렉토리를 표시하고 maven을 통해 가져온 JAR을 나열합니다. 여기에서는 보이지 않습니다. 내가 도대체 ​​뭘 잘못하고있는 겁니까?


내 화면은 다음과 같습니다.

IDE 이미지


어떤 이유로 다시 가져 오기가 트릭을 수행하지 않았습니다. 이것을 본 후 :

http://www.jetbrains.com/idea/webhelp/maven-importing.html

자동 가져 오기를 설정했지만 문제는 사라졌습니다. 다른 사람에게 도움이되기를 바랍니다. 아이디어 주셔서 감사합니다 :).


IntelliJ IDEA를 새 컴퓨터에 설치 한 후 동일한 문제가 발생했습니다.

원격 Maven 저장소를 업데이트해야했습니다. ( Settings > Maven > Repositories)

여기에 이미지 설명 입력

로컬 및 원격 저장소를 모두 업데이트해야했습니다. 원격 하나는 이전에 업데이트되지 않았습니다. 다시 시작한 후 모든 것이 잘 작동했습니다. 프로젝트를 다시 가져와야 할 수 있습니다.


비슷한 문제가 발생했습니다. 나에게는 프로젝트를 잘못 가져 오는 것이 끝났습니다. 나는하고 있었다

import project
    <navigate to existing project and click top level directory>
    follow the wizard

내 maven 문제를 해결 한 것은

import project
    <navigate to existing project and click the pom.xml
    follow the wizard

다음으로 이동할 수 있습니다.

파일> 설정> 빌드, 실행, 배포> 빌드 도구> Maven

pom.xml이 "무시 된 파일"목록에 없는지 확인하십시오.


나를 위해 File >> Invalidate Cache / Restart >> Invalidate and Restart working in IntelliJ


Intellij를 통해 리포지토리를 간단히 다시 가져 오거나 업데이트하는 것은 나에게 트릭을 제공하지 않았습니다.

대신 전체 ~/.m2/repository디렉토리 를 삭제하고 maven이 모든 것을 스스로 분류하도록해야했습니다. 그 후에 Maven -> Reimport그것을 끝냈습니다.


제 경우 문제는 프로젝트가 maven2에 있었고 intellj는 maven3에 대해 구성되었다는 것입니다. 설정에서 maven2로 전환하면 문제가 해결되었습니다.


나처럼 여전히 붙어있는 다른 사람들에게 유용 할 수 있습니다. 제안 된 수정 사항 중 어느 것도 작동하지 않았습니다. 실제로 maven의 설치 위치 인 주요 문제를 해결하기 전에는 아닙니다.

제 경우에는 표준 위치를 사용하지 않았습니다. Maven 설정 ( Settings / Maven / Maven 홈 저장소 ) 에서 해당 위치를 변경 하면 트릭이 발생했습니다.

내 2 센트.


이해가 안되는 이유로 필자의 경우에는 Build, Executions, Deployment> Build Tools> Maven에서 "Always update snapshots"설정을 켜야했습니다.

이로 인해 IntelliJ가 종속성을 다시 다운로드하고 작동하게했습니다.


캐시가 문제를 일으키고 있습니다! 다음을 수행하십시오.

터미널에서 프로젝트 / 모듈로 이동합니다.

mvn clean install

IntelliJ에서 :

  1. 파일> 캐시 무효화> 무효화

  2. 프로젝트 / 모듈> Maven> 다시 가져 오기를 마우스 오른쪽 버튼으로 클릭합니다.


이것은 Intellij를 1.4.15로 업그레이드 한 후에도 나에게 발생했습니다. 동일한 결과로 전체 프로젝트를 다시 가져 오려고 시도했지만 Maven Auto Import를 활성화하면 트릭이 발생했습니다.


intelliJ가 pom 파일을 무시하는 몇 가지 유효한 이유가있는 것 같습니다. 내 경우에는 이전 답변 중 어느 것도 작동하지 않았으므로 다른 사람 이이 문제에 부딪 힐 경우를 대비하여 다음과 같이 작동했습니다.

In this example, module3 was being completely ignored by IntelliJ. The pom.xml in that directory wasn't even being treated as a maven pom.

My project structure is like this:

myProject
    module1
    module2
    module3

BUT, my (simplified) pom structure is like this:

<project>
    <modelVersion>4.0.0</modelVersion>
    <groupId>devs</groupId>
    <artifactId>myProject</artifactId>
    <version>0.0-SNAPSHOT</version>
    <packaging>pom</packaging>
    <name>myProject</name>

    <modules>
        <module>module1</module>
        <module>module2</module>
    <modules>

    <profiles>
        <profile>
            <id>CompleteBuildProfile</id>
            <modules>
                <module>module3</module>
            </modules>
        </profile>
    </profiles>
</project>

To fix this, I modified the root <modules> element to add in module3 temporarily.

    <modules>
        <module>module1</module>
        <module>module2</module>
        <module>module3</module>
    <modules>

Next re-import the root pom, and IntelliJ will add the module. When that's done, revert the pom. IntelliJ will ask if you also want to remove module3 from the project structure. Click No.

Bam! Done. Module3 works and I can run my Integration tests from IntelliJ again :D


The problem was caused for me by selecting the project directory to be Imported when first starting IntelliJ rather than the pom.xml file for the project.

Closing the problem project and then following the Import process again but choosing the pom.xml resulted in a fully working project in the IDE.


For me the problem seems to be a conflict with the maven helper plugin (https://plugins.jetbrains.com/plugin/7179?pr=idea).

I disable it, and it works again :)


Go to File > Settings > Build, Execution, Deployment > Build Tools > Maven and check the Maven home directory. This should be the same maven installation used for command line


For me, what did the trick was to add the dependencies in File > Project Settings > Modules > Dependencies.


Just delete your project's .idea folder and re-import your project in IntelliJ.

참조 URL : https://stackoverflow.com/questions/15046764/intellijidea-not-recognizing-classes-specified-in-maven-dependencies

반응형