Spring Boot Data Jpa 관련하여 책에 나온 프로젝트를 따라 치다가 문득 의문이 들었다.
build.gradle에 dependencies를 설정하면서 jpa를 위하여 h2와 data-jpa를 compile하라고 되어 있었는데
인텔리제이에서 아래와 같은 오류가 발생했다.
A problem occurred evaluating root project
>Could not find method compile() for arguments
알고보니 compile은 gradle 3.0이상부터는 지원하지 않는다고 한다.
implementation
로 바꿔서 적용시켜줘야한다.
그러다가 의문이 생겼다.
compile과 implementation의 차이점은 그럼 뭐지?
둘 다 의존성을 부여해주는 역할을 한다.
공식문서에서는 다음과 같이 소개한다.
Managing Dependencies of JVM Projects
How does Gradle know where to find the files for external dependencies? Gradle looks for them in a repository. A repository is a collection of modules, organized by group, name and version. Gradle understands different repository types, such as Maven and I
docs.gradle.org
implementation
The dependencies required to compile the production source of the project which are not part of the API exposed by the project. For example the project uses Hibernate for its internal persistence layer implementation.
api
The dependencies required to compile the production source of the project which are part of the API exposed by the project. For example the project uses Guava and exposes public interfaces with Guava classes in their method signatures.
implementation은 API가 노출되지 않고 compile은 프로젝트와 연결된 API가 노출된다. API가 외부로 노출되게 되면 API로직에서 유효성 검사나 다른 원치 않은 데이터들이 들어와 보안상의 위협이 될 수 있으므로 노출되지 않는게 좋다고 한다.
또한, compile은 모듈의 수정이 필요할 때, 의존하고 있는 관련 오브젝트들이 다시 빌드되어야하지만, implementation은 직접 의존하는 오브젝트만 다시 빌드하면 되므로 더 빠르고 직관적으로 개선할 수 있다. 이는 프로젝트가 더 복잡할 수록 그 차이가 더 드러날 것 같다.
'SPRING' 카테고리의 다른 글
test subject로 필요한 junit 버전 설정하여 테스트하는 방법 (0) | 2022.08.22 |
---|---|
[오류해결] AopAutoConfiguration matched: - @ConditionalOnProperty (spring.aop.auto=true) matched (OnPropertyCondition) (0) | 2022.08.21 |