DevOps/Project management
[Gradle 고급]git release 브랜치 기준으로 jar 자동 versioning하기
AndersonChoi
2018. 6. 19. 19:41
Git을 사용하면 여러 branch 전략이 있다.
많은 전략 중 development branch에서 지속적으로 개발후에 특정 시점에 release브랜치로 배포를 나가는 전략을 사용할 수 도 있다.
상기와 같은 전략을 사용할 경우 release/1.0.1 혹은 release/2.1.3 과 같은 이름으로 release 버젼을 따게 된다.
이 때 jar파일을 생성할때 자동으로 versioning이 가능하도록 하는 방법에 대해 설명하고자 한다.
기존 gradle
build.gradle
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | buildscript { repositories { maven { url 'http://repo.mycompany.com/maven2' } } dependencies { classpath("org.springframework.boot:spring-boot-gradle-plugin:2.0.0.RELEASE") classpath "io.franzbecker:gradle-lombok:1.8" } } apply plugin: 'java' apply plugin: 'eclipse' apply plugin: 'idea' apply plugin: 'org.springframework.boot' apply plugin: "io.franzbecker.gradle-lombok" apply plugin: 'io.spring.dependency-management' sourceCompatibility = 1.8 targetCompatibility = 1.8 bootJar { baseName = 'sample-java-project' } repositories { maven { url "http://repo.mycompany.com/maven2" } } dependencies { ...필요한 디펜던시들... } | cs |
생성물 : sample-project.jar
versioning 가능한 gradle
build.gradle
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | buildscript { repositories { maven { url 'http://repo.mycompany.com/maven2' } } dependencies { classpath("org.springframework.boot:spring-boot-gradle-plugin:2.0.0.RELEASE") classpath "io.franzbecker:gradle-lombok:1.8" } } plugins { id 'org.ajoberstar.grgit' version '1.7.1' } ext { git = org.ajoberstar.grgit.Grgit.open() gitBranchName = git.branch.current.name.replaceAll(/(.*)\//, '') } apply plugin: 'java' apply plugin: 'eclipse' apply plugin: 'idea' apply plugin: 'org.springframework.boot' apply plugin: "io.franzbecker.gradle-lombok" apply plugin: 'io.spring.dependency-management' sourceCompatibility = 1.8 targetCompatibility = 1.8 version = gitBranchName bootJar { baseName = 'sample-java-project' } repositories { maven { url "http://repo.mycompany.com/maven2" } } dependencies { ...필요한 디펜던시들... } | cs |
setting.gradle
1 | rootProject.name = 'sample-java-project' | cs |
생성물(master브랜치일 경우) : sample-project-master.jar생성물(release/1.0.3브랜치일 경우) : sample-project-1.0.3.jar
- setting.gradle에 rootProject를 셋팅하고, org.ajoberstar.grgit플러그인(사이트 바로가기)를 사용하면 효과적으로 버져닝 가능하다.
build.gradle에 추가된 부분은 아래와 같다.
1 2 3 4 5 6 7 8 9 10 11 12 | plugins { id 'org.ajoberstar.grgit' version '1.7.1' } ext { git = org.ajoberstar.grgit.Grgit.open() gitBranchName = git.branch.current.name.replaceAll(/(.*)\//, '') } ... version = gitBranchName | cs |
End of Document.
반응형