gradle

gradle 스프링부트 이클립스 생성 및 배포 build

초이짬 2020. 7. 18. 03:48
728x90

이클립스로 스프링 부트를 maven 을 통해 많이 써왔고 많이 익숙하다 특히 pom.xml 을 통한 라이브러리 계층 구조 파악은 항상 많은 도움이 된다.

msa 로 접어들면서 부터 부트를 접하게 되었고 부트의 편리함에 많은 납득이 되었는데

gradle 로 많이 빌드 하는걸 보게 되었지만 딱히 필요성은 모르던 차에 프로젝트에서 git 을 통한 예제소스를

내려 받는데 gradle 로 빌드를 하기에 공부해 보기로 했다 일단 이클립스에서 어떻게 빌드 배포 해야 되는지를 확인하고 나중에 또 헷갈림을 방지하기 위해 기록한다.

정확하진 않고 첨해본거라 그냥 부트 스타트만 하고 hello world 찍는 용도 정도다

아 물론 다른데서 설명들은 cli 모드라서 이클립스로 안되나? 해서 시도해본 목적이 크다.

일단 이클립스 상에서(물론 sts 로 했다) 스프링스타터 프로젝트로 gradle 프로젝트를 생성했다.

그리고 next 에서 web 항목 체크후 생성하면

기본 프로젝트

위와 같이 나오고 build.gradle 을 클릭한다.

buildscript {
ext {
springBootVersion = '2.3.1.RELEASE'
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}

plugins {
id 'org.springframework.boot' version '2.3.1.RELEASE'
id 'io.spring.dependency-management' version '1.0.9.RELEASE'
id 'java'
}

group = 'kr.letech'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.8'

repositories {
mavenCentral()
}

dependencies {
implementation 'org.springframework.boot:spring-boot-starter-jersey'
implementation 'org.springframework.boot:spring-boot-starter-web'
testImplementation('org.springframework.boot:spring-boot-starter-test') {
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
}
compileOnly('org.projectlombok:lombok')
}

test {
useJUnitPlatform()
}

//create a single Jar with all dependencies
jar {
baseName = "homepage-batch"
version = "${version}"
manifest {
attributes 'Title': 'Reqeust And Header Tester',
'Version': 1.0,
// 'Main-Class': 'com.donzbox.HomepageBatchApplication'
'Main-Class': 'com.example.demo.GradleTest11Application'
}

from {
    configurations.compile.collect {
        it.isDirectory() ? it : zipTree(it)
    }
}

}

 

.....위와 같이 썻는데 다음블로그 변경되고 적응이 안되네.....소스만 넣으면 마크다운으로 변경 해야 되고....

 

암튼.. 저렇게 하고

 

run configuration 에 

 

Tasks 항목에 build 라고 쓰고 아래 working directory 에는 해당 workspace 선택 해주고 Apply 후 Run 하면 

 

console 에

 

 

이렇게 나오고 해당 프로젝트 하단 build 폴더 > libs 폴더안에 해당 build 된 jar 가 있다...

 

뭐 대충 이렇게 빌드되고 실행해 보니 잘된다...

 

 

 

728x90