본문 바로가기
공부/프로그래밍

[gradle] 외부 jar파일 추가하기

by demonic_ 2020. 8. 11.
반응형

libs 폴더에 다음과 같이 파일을 추가한다

 

root 폴더에 넣는다(src와 같은 레벨 위치)

 

build.gradle 파일을 열어 다음과 같이 추가한다.

dependencies {
...
    compile files("libs/ksnet/kspg_eclient.jar")
    compile files("libs/ksnet/kspg_m1000.jar")
...
}

 

 

혹시 다음과 같이 에러가 난다면 오타를 확인하자

내 경우 compile file 이라고 써서 에러가 났다

A problem occurred evaluating root project 'kinspayconnector'.
> Cannot convert the provided notation to an object of type Dependency: /Users/dgpark/git/project/[프로젝트명]/libs/ksnet/kspg_eclient.jar.
  The following types/formats are supported:
    - Instances of Dependency.
    - String or CharSequence values, for example 'org.gradle:gradle-core:1.0'.
    - Maps, for example [group: 'org.gradle', name: 'gradle-core', version: '1.0'].
    - FileCollections, for example files('some.jar', 'someOther.jar').
    - Projects, for example project(':some:project:path').
    - ClassPathNotation, for example gradleApi().

 

완료하고 Reload 버튼을 누른 다음 Dependencies에 추가되었는지 확인.

 

 

# 폴더째로 추가할 경우

fileTree 명령어를 통해 추가 가능

 

dependencies {
...
    compile fileTree(dir: 'libs/ksnet', includes: ['*.jar'])
...
}

 

Dependency 에 다음과 같이 표시된다.

 

개인적으로 명확히 명시되는걸 선호하기 때문에 폴더보단 파일별로 추가하는 것을 선호한다.

파일이 너무 많으면 폴더째로 추가하겠지만.

 

 

끝.

 

 

반응형

댓글