IntelliJ Platfrom Plugin

IntelliJ Platform Plugin SDK 공식문서 읽기 - Class Loaders

PI.314 2022. 10. 19. 23:32

Class Loaders

별도의 클래스 로더를 사용하여 각 플러그인의 클래스를 로드합니다. 이를 통해 IDE 자체 또는 다른 플러그인에서 동일한 라이브러리를 사용하더라도 각 플러그인은 다른 라이브러리 버전을 사용할 수 있습니다.

Bundled Libraries

Third-Party Software and Licenses는 각 제품의 모든 번들 라이브러리와 해당 버전을 나열합니다.

Overriding IDE Dependencies

Gradle 7은 compile scope를 대체하여 implementation scope를 도입했습니다. 이 설정의 경우 번들 IDE 버전 대신 dependency를 사용하려면 Gradle 빌드 스크립트에 다음 snippet을 추가하십시오.
 
configurations.all {
  resolutionStrategy.sortArtifacts(ResolutionStrategy.SortOrder.DEPENDENCY_FIRST)
}

Classes from Plugin Dependencies

기본적으로 메인 IDE Class Loader는 플러그인 Class Loader에 없는 클래스를 로드합니다. 그러나 plugin.xml 파일에서 <depends> element를 사용하여 플러그인이 하나 이상의 다른 플러그인에 종속되도록 지정할 수 있습니다. 이 경우 해당 플러그인의 Class Loader는 현재 플러그인에 없는 클래스에 사용됩니다. 이렇게하면 플러그인이 다른 플러그인의 클래스를 참조 할 수 있습니다.

Using ServiceLoader

일부 라이브러리는 Service Loader를 사용하여 implementations를 검색하고 로드합니다. 이것이 플러그인에서 작동하려면 Context Class Loader를 플러그인의 Class Loader로 설정하고 복원해야 합니다.
 
Thread currentThread = Thread.currentThread();
ClassLoader originalClassLoader = currentThread.getContextClassLoader();
ClassLoader pluginClassLoader = this.getClass().getClassLoader();
try {
  currentThread.setContextClassLoader(pluginClassLoader);
  // code working with ServiceLoader here
} finally {
  currentThread.setContextClassLoader(originalClassLoader);
}