plugins {
	id 'java'
	id 'org.springframework.boot' version '3.5.4'
	id 'io.spring.dependency-management' version '1.1.7'
	id 'com.google.cloud.tools.jib' version '3.4.0' // Jib 플러그인 추가
}

group = 'com.bio'
version = '0.0.1-SNAPSHOT'

java {
	toolchain {
		languageVersion = JavaLanguageVersion.of(17)
	}
}

configurations {
	compileOnly {
		extendsFrom annotationProcessor
	}
}

repositories {
	mavenCentral()
}

dependencies {
    developmentOnly 'org.springframework.boot:spring-boot-devtools'
	implementation 'org.springframework.boot:spring-boot-starter-data-jpa'

	// PostgreSQL JDBC
    runtimeOnly 'org.postgresql:postgresql'
	implementation 'org.springframework.boot:spring-boot-starter-web'
	
	// Spring Securit
	implementation 'org.springframework.boot:spring-boot-starter-security'
	
	// Validation
	implementation 'org.springframework.boot:spring-boot-starter-validation'
	
	// Spring Boot Actuator
	implementation 'org.springframework.boot:spring-boot-starter-actuator'
	
	// MapStruct
	implementation 'org.mapstruct:mapstruct:1.5.5.Final'
	annotationProcessor 'org.mapstruct:mapstruct-processor:1.5.5.Final'
	
	// MyBatis
	implementation 'org.mybatis.spring.boot:mybatis-spring-boot-starter:3.0.3'

	implementation 'org.springframework.boot:spring-boot-starter-actuator'
	
	// jwt
	implementation 'io.jsonwebtoken:jjwt-api:0.12.5'
	runtimeOnly 'io.jsonwebtoken:jjwt-impl:0.12.5'
	runtimeOnly 'io.jsonwebtoken:jjwt-jackson:0.12.5'

	// lombok
	compileOnly 'org.projectlombok:lombok'
	annotationProcessor 'org.projectlombok:lombok'
	annotationProcessor 'org.projectlombok:lombok-mapstruct-binding:0.2.0'
	testImplementation 'org.springframework.boot:spring-boot-starter-test'
	testRuntimeOnly 'org.junit.platform:junit-platform-launcher'

	// querydsl
	implementation 'io.github.openfeign.querydsl:querydsl-jpa:6.11'
	annotationProcessor 'io.github.openfeign.querydsl:querydsl-apt:6.11:jpa'
	annotationProcessor 'jakarta.annotation:jakarta.annotation-api'
	annotationProcessor 'jakarta.persistence:jakarta.persistence-api'

	// p6spy
	implementation 'com.github.gavlyukovskiy:p6spy-spring-boot-starter:1.9.0'
	
	// SpringDoc OpenAPI (Swagger)
	implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.8.9'
}

tasks.named('test') {
	useJUnitPlatform()
}

// querydsl
def generatedSrcDir = 'build/generated/sources/annotation-processor'
clean {
	delete file(generatedSrcDir)
}
tasks.withType(JavaCompile).configureEach {
	options.generatedSourceOutputDirectory = file(generatedSrcDir)
}

jib {
  from {
    image = 'demo.stam.kr/leejisun9/eclipse-temurin:17-jre'     // 가벼운 JRE 베이스
    // (선택) 인증서 추가/회사 CA 필요 시 extraDirectories 사용
  }
  to {
    image = 'demo.stam.kr/leejisun9/bio-backend'; tags = ['1.0.0']  // 기본 대상 레지스트리
    // tags는 skaffold가 자동 주입. 로컬 단독 빌드시 -Djib.to.tags=로 지정 가능
  }
  container {
    // Spring Boot 컨테이너 런타임 옵션
    ports = ['8080']
    jvmFlags = [
      '-XX:+UseContainerSupport',
      '-Dserver.port=8080',
      '-XX:InitialRAMPercentage=50.0',
      '-XX:MaxRAMPercentage=75.0'
    ]
    environment = [ 'SPRING_PROFILES_ACTIVE': 'dev' ]
    // (선택) non-root 권장 (권한 필요한 리소스 없는 경우)
    // user = '65532:65532'
    // workingDirectory = '/app'
  }
  // (선택) 계층 최적화/추가 파일
  // extraDirectories {
  //   paths {
  //     path {
  //       from = file('docker/extra')   // 예: CA cert, 설정 템플릿
  //       into = '/opt/extra'
  //     }
  //   }
  // }
}