사용자 도구

사이트 도구


springframework:springboot:gradle

차이

문서의 선택한 두 판 사이의 차이를 보여줍니다.

차이 보기로 링크

다음 판
이전 판
springframework:springboot:gradle [2018/11/28 12:54]
kwon37xi 만듦
springframework:springboot:gradle [2020/09/16 16:41] (현재)
kwon37xi [bootJar 파일을 별도 파일로 복사하기]
줄 2: 줄 2:
   * [[springframework:springboot|SpringBoot]] and [[:gradle|Gradle]]   * [[springframework:springboot|SpringBoot]] and [[:gradle|Gradle]]
  
 +
 +===== Dependency Version Override =====
 +의존 라이브러리의 버전을 다른 것으로 바꾸고자 한다면 property를 변경하면 된다.
 +<code groovy>
 +// 하이버네이트 버전
 +ext['hibernate.version'] = '5.2.14.Final'
 +</code>
 +혹은 프로젝트의 ''gradle.properties'' 에 설정할수도 있다.
 +<code>
 +hibernate.version=5.2.14.Final
 +</code>
 +
 +  * [[https://docs.spring.io/spring-boot/docs/current/reference/html/appendix-dependency-versions.html|Dependency versions]] 여기서 버전 프라퍼티 목록을 알 수 있다.
 +  * Gradle 에서 SpringBoot 버전 프라퍼티의 값을 읽고자 한다면
 +<code groovy>
 +// slf4j.version 의 값을 읽을 때는
 +def slf4jVersion = dependencyManagement.importedProperties['slf4j.version']
 +</code>
 +
 +===== 라이브러리성 모듈 설정 =====
 +  * 라이브러리성 모듈인데 ''org.springframework.boot:spring-boot-starter-web'' 같은 것을 포함할 경우 자동으로 ''bootJar''가 활성화 되고 ''jar''가 꺼지게 되는데 이렇게 되면 올바르게 라이브러리로서 기능할 수 없게 된다.
 +  * 이 경우 ''jar''만 활성화해야한다.
 +<code>
 +bootJar.enabled = false
 +jar.enabled = true
 +</code>
 +  * 말단 배포 모듈(''main'' 이 존재하는 모듈, web, batch 등.)은 이 값을 반대로 해야한다.(기본으로 그렇게 됨)
 +<code>
 +bootJar.enabled = true
 +jar.enabled = false
 +</code>
 +===== BootRun =====
 +==== profile 지정 ====
 +<code sh>
 +SPRING_PROFILES_ACTIVE=<PROFILE> ./gradlew bootRun
 +</code>
 +
 +==== Debug Mode ====
 +<code groovy>
 +bootRun {
 +    if (project.hasProperty("bootDebug")) {
 +        jvmArgs = ["-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=5005"]
 +    }
 +}
 +
 +// suspend=y는 JVM이 뜰 때 Remote Debugger가 접속될 때까지 기다린다.
 +// 실행 후 바로 종료하는 명령행 애플리케이션의 경우 무조건 y
 +</code>
 +
 +<code sh>
 +# -PbootDebug 프라퍼티를 지정하면 디버그 모드로 뜬다.
 +./gradlew bootRun -PbootDebug
 +</code>
 +
 +==== Application Arguments ====
 +  * [[https://www.baeldung.com/spring-boot-command-line-arguments|Command-line Arguments in Spring Boot | Baeldung]]
 +<code groovy>
 +bootRun {
 +    if (project.hasProperty('args')) {
 +        args project.args.split(',')
 +    }
 +}
 +</code>
 +
 +위와 같이 설정하고, 아래와 같은 형태로 실행한다.
 +
 +<code sh>
 +./gradlew bootRun -Pargs=param1,param2,...
 +</code>
 +
 +==== Property Override ====
 +  * [[https://stackoverflow.com/questions/36923288/how-to-run-bootrun-with-spring-profile-via-gradle-task|java - How to run bootRun with spring profile via gradle task - Stack Overflow]]
 +
 +=== Environment Variable 사용 ===
 +<code>
 +SPRING_PROFILES_ACTIVE=test gradle clean bootRun
 +
 +// on Windows
 +SET SPRING_PROFILES_ACTIVE=test
 +gradle clean bootRun
 +</code>
 +
 +
 +=== Gradle 에 System Property 그대로 계승 ===
 +<code>
 +bootRun.systemProperties = System.properties
 +</code>
 +
 +=== 새로운 bootRun Task 로 만들어버리기 ===
 +  * 새로운 ''bootRun'' 태스크를 만들고, 거기에 각종 기본 설정 추가
 +<code>
 +task bootRunDev(type: org.springframework.boot.gradle.tasks.run.BootRun, dependsOn: 'build') {
 +    group = 'Application'
 +
 +    doFirst() {
 +        main = bootJar.mainClassName
 +        classpath = sourceSets.main.runtimeClasspath
 +        systemProperty 'spring.profiles.active', 'dev'
 +        systemProperty 'debug', 'true'
 +    }
 +}
 +</code>
 +
 +
 +===== bootJar 파일을 별도 파일로 복사하기 =====
 +<code groovy>
 +task copyBootJarNormalizedName(type: Copy) {
 +    from bootJar.archiveFile
 +    into "${buildDir}"
 +    rename { 'my.jar' }
 +    dependsOn bootJar
 +}
 +</code>
 +
 +
 +
 +
 +
 +===== 참조 =====
 +  * [[https://guides.gradle.org/building-spring-boot-2-projects-with-gradle/|Building Spring Boot 2 Applications with Gradle]]
 +  * [[https://www.baeldung.com/spring-boot-gradle-plugin|Spring Boot Gradle Plugin]]
springframework/springboot/gradle.1543377248.txt.gz · 마지막으로 수정됨: 2018/11/28 12:54 저자 kwon37xi