프로그래밍/Java

Maven 저장소에 오픈소스 배포하기 - bintray를 통한 배포

Jay Tech 2019. 11. 30. 16:32
반응형

모듈 배포하기

이 부분에서 도메인 지식이 하나도 없어서 처음 공부해보면서 정리한 내용입니다.

JCenter와 MavenCentral 차이점

스택 오버플로우의 답변을 참고하세요.

Jcenter vs. mavenCentral

jcenter() and mavenCentral() is a repository for the Gradle plugin in Android Studio

Earlier versions of Android Studio used mavenCentral(), and after some time, it switched to jcenter.

This is because jcenter() is superior to mavenCentral() in terms of performance and memory footprint:

  • Jcenter is the world's largest Java repository
  • Jcenter through the CDN service, using the https protocol, highly secured, and Android Studio 0.8 version mavenCentral() using the http protocol
  • Jcenter is a superset of mavenCentral, including many additional jars
  • Jcenter performance is better than mavenCentral
  • mavenCentral will automatically download many IDE-related indexes, and these are used less often which are not required.

 

그럼 이번 글의 목적인 라이브러리를 오픈소스로 만드는 방법 중에서 제일 간단한 방법을 알아보겠습니다.

그리고 제가 적용 해보면서 맞닥뜨린 이슈(포인트 1, 포인트 2, 포인트 3, 포인트 4)가 생겼던 부분 4가지를 강조할 텐데 그 부분을 유념해서 보면 될 것 같네요. 중간에 bold로 하이라이트를 시켜놓겠습니다.

 

먼저 bintray에 가입을 합니다. bintray란, 'Software Distribution as a Service'라는 슬로건을 걸고 있네요.

회원가입을 할 때 우측에 open source 버전으로 회원 가입해야 free-trial 기간이 생기지 않습니다. (Sign Up Here을 누르면 됩니다!!)

 

여기서 리포지토리(Repository)와 패키지(Package)를 만들어 줍니다. 포함관계는 리포지토리 안에 여러 패키지들이 포함된다고 생각하면 됩니다. 리포지토리 이름을 maven이라고 지어보겠습니다. 왜 maven으로 짓는지는 이따가 나옵니다. (뭐 물론 다른 이름으로 짓고 다른 플러그인을 쓰면 리포지토리 이름을 다르게 가져갈 수 있습니다)

 

여타 다른 좋은 글들이 있는데 버전 업이 되면서 사소하게 바뀐 것들이 있기 때문에 다시 작성해보겠습니다.

https://jojoldu.tistory.com/161 ← 요거는 maven에서 사용할 때 보면 될 것 같아요 (역시 갓동욱님).

https://blog.junil.kim/deploy-android-library-to-jcenter/

 

저는 bintray에 업로드할 때도 간편하게 하기 위해서 편한 모듈을 사용하겠습니다.

https://github.com/novoda/bintray-release

 

novoda/bintray-release

A helper for releasing from gradle up to bintray. Contribute to novoda/bintray-release development by creating an account on GitHub.

github.com

저는 Gradle에서 사용할 것이기 때문에 build.gradle에 코드 몇 줄을 추가하겠습니다.

먼저 초기 build.gradle 파일입니다. dependencies 빼고 보시면 될 것 같네요.

plugins {
    id 'java'
}

group 'com.gaejangmo'
version '1.0-SNAPSHOT'

sourceCompatibility = 1.8

repositories {
    mavenCentral()
}

dependencies {
    testImplementation 'org.junit.jupiter:junit-jupiter-api:5.3.1'
    testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.3.1'
    testCompile("org.assertj:assertj-core:3.11.1")
}

위에 소개한 bintray-release 플러그인을 적용해보겠습니다.

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.novoda:bintray-release:0.9'
    }
}

plugins {
    id 'java'
}

apply plugin: 'com.novoda.bintray-release'

group 'com.gaejangmo'
version '1.0.0'

sourceCompatibility = 1.8

repositories {
    mavenCentral()
}

publish {
    userOrg = 'jaypark3749'
    groupId = 'com.gaejangmo'
    artifactId = 'gae-jang-mo-utils'
    publishVersion = '1.0.0'
    desc = 'util module for gae-jang-mo'
    website = 'https://github.com/gae-jang-mo/utils'
}

dependencies {
    testImplementation 'org.junit.jupiter:junit-jupiter-api:5.3.1'
    testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.3.1'
    testCompile("org.assertj:assertj-core:3.11.1")
}

포인트 1: plugin 태그 순서!!

보시면 plugins라는 것 위에 다른 속성들을 정의하면 에러가 납니다. 에러 메시지를 보면 오직 buildscript {}와 다른 plugins {} 만이 plugins{} 이 위치할 수 있다고 나오죠. 그래서 위의 코드처럼 순서를 잘 지켜주어야 합니다.

 

포인트 2: publish 속성 값!!

publish {
    userOrg = 'jaypark3749'
    groupId = 'com.gaejangmo'
    artifactId = 'gae-jang-mo-utils'
    publishVersion = '1.0.0'
    desc = 'util module for gae-jang-mo'
    website = 'https://github.com/gae-jang-mo/utils'
}

속성 이름을 보면 명시적이기 때문에 다 알겠죠. 근데 bintray의 리포지토리 이름 설정하는 부분이 없네요. 여기서 삽질을 오지게 했는데 (빌드 후 deploy가 계속 되질 않았습니다) novoda-release 플러그인 코드를 까 보니 repoName이 maven으로 하드코딩이 되어 있습니다. 결국 제 리포지토리 이름을 maven으로 바꾸고 해결되었습니다.

 

 

포인트 3: deploy 명령어 오타 조심!

$ ./gradlew clean build bintrayUpload -PbintrayUser=[id] -PbintrayKey=[api key] -PdryRun=false

저는 제 아이디를 쓰는데 오타가 나서 계속 삽질했었네요. 똑똑한 여러분들은 그런 실수를 할 리가 없겠죠?

그리고 publish scope에 아이디와 api key를 넣을 수 있습니다. 한데 깃허브에 고대로 키가 올라가기 때문에 그렇게 하면 안 되겠죠. 시스템 변수를 명령어를 칠 때 넣는 방식으로 해야 합니다. 저기 id와 api key를 넣어주면 됩니다.

 

포인트 4: bintray-release 버전!

대망의 Big 삽질 포인트. bintray-release 플러그인 레포에 가보면 버전을 latest-version을 쓰라고 나와있습니다. 다른 참고자료들에는 대부분 0.8.0 버전이더라고요. 그래서 현재 시점에서는 동작을 하지 않는... ㅠㅠ

버전을 최신 것을 쓰지 않으면 deploy가 되지 않습니다!

현재 최근 버전은 0.9입니다. (쓰는 시점의 최근 버전을 써야 합니다. 아마도 bintray 정책에 맞게 플러그인이 계속 업데이트되는 것 같습니다)

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.novoda:bintray-release:0.9'
    }
}

deploy 된 모습

 

 

왼쪽 하단에 보면 maven, gradle, ivy에서 배포한 모듈을 쓸 수 있게 되었습니다. 참고로 이미 있는 버전이면 재 업로드가 안됩니다. 새로이 기능 추가나 버그 수정으로 인한 배포는 버전을 하나씩 올려서 배포해야 합니다.

 

사용!!

 

 

빌드하면 라이브러리가 추가된 것을 볼 수 있습니다.

반응형