From 8419d6a6d11ea0713246292ab556077cb614d18e Mon Sep 17 00:00:00 2001 From: kric_jspark Date: Fri, 5 Jun 2026 11:53:18 +0900 Subject: [PATCH] =?UTF-8?q?260605=5F02=5FENH:=20=EB=B0=B0=ED=8F=AC=20?= =?UTF-8?q?=EC=9E=90=EB=8F=99=ED=99=94=EC=97=90=EC=84=9C=20=EB=B2=84?= =?UTF-8?q?=EC=A0=84=20=EC=95=88=EB=B0=94=EB=80=8C=EB=A9=B4=20=EB=B0=B0?= =?UTF-8?q?=ED=8F=AC=20=EC=8B=A4=ED=8C=A8=20=EC=B2=98=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle | 101 ++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 91 insertions(+), 10 deletions(-) diff --git a/build.gradle b/build.gradle index 7d3bd69..9d2772e 100644 --- a/build.gradle +++ b/build.gradle @@ -3,14 +3,16 @@ plugins { id 'maven-publish' } -//버전 변경은 여기서 +// 버전 변경은 여기서 def commonVer = "beta.1.1.22" group = 'com.kri.common' version = commonVer java { - toolchain { languageVersion = JavaLanguageVersion.of(17) } + toolchain { + languageVersion = JavaLanguageVersion.of(17) + } } tasks.withType(JavaCompile).configureEach { @@ -39,7 +41,8 @@ dependencies { // Security Core api 'org.springframework.security:spring-security-core' - // ✅ HttpSecurity, SecurityFilterChain, WebSecurityCustomizer 등 들어있는 모듈들 + + // HttpSecurity, SecurityFilterChain, WebSecurityCustomizer 등 들어있는 모듈들 compileOnly 'org.springframework.security:spring-security-config' compileOnly 'org.springframework.security:spring-security-web' @@ -49,15 +52,16 @@ dependencies { compileOnly 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.6.0' // JPA AttributeConverter, Entity 등 인터페이스용 - compileOnly "org.springframework.boot:spring-boot-starter-data-jpa" + compileOnly 'org.springframework.boot:spring-boot-starter-data-jpa' // Lombok compileOnly 'org.projectlombok:lombok' annotationProcessor 'org.projectlombok:lombok' - //Json Util + // Json Util implementation 'com.fasterxml.jackson.core:jackson-databind:2.17.0' - //Excel Util + + // Excel Util implementation 'org.apache.poi:poi-ooxml:5.5.1' // ConfigurationProperties 메타데이터 @@ -71,13 +75,14 @@ dependencies { compileOnly 'org.springframework.boot:spring-boot-starter-data-redis' } -def giteaUser = findProperty("giteaUser") ?: System.getenv("GITEA_USER") ?: "" -def giteaToken = findProperty("giteaToken") ?: System.getenv("GITEA_TOKEN") ?: "" +def giteaUser = findProperty('giteaUser') ?: System.getenv('GITEA_USER') ?: '' +def giteaToken = findProperty('giteaToken') ?: System.getenv('GITEA_TOKEN') ?: '' publishing { publications { release(MavenPublication) { from components.java + groupId = 'com.kri.common' artifactId = 'starter' version = commonVer @@ -86,8 +91,8 @@ publishing { repositories { maven { - name = "gitea" - url = uri("https://gitea.kric.com/api/packages/KRi/maven") + name = 'gitea' + url = uri('https://gitea.kric.com/api/packages/KRi/maven') credentials { username = giteaUser @@ -96,3 +101,79 @@ publishing { } } } + +def checkHttpStatus = { String targetUrl, String auth, String method -> + HttpURLConnection conn = null + + try { + conn = (HttpURLConnection) new URL(targetUrl).openConnection() + conn.setRequestMethod(method) + conn.setRequestProperty('Authorization', "Basic ${auth}") + conn.setConnectTimeout(10000) + conn.setReadTimeout(10000) + + return conn.getResponseCode() + } finally { + if (conn != null) { + conn.disconnect() + } + } +} + +tasks.register('checkGiteaPackageVersionNotExists') { + group = 'publishing' + description = 'Gitea Packages에 동일한 Maven package version이 이미 존재하는지 확인합니다.' + + doLast { + def packageGroupId = 'com.kri.common' + def packageArtifactId = 'starter' + def packageVersion = commonVer + def packageOwner = 'KRi' + + if (!giteaUser || !giteaToken) { + throw new GradleException( + '[GITEA_AUTH_MISSING] Gitea 인증정보가 없습니다. ' + + 'giteaUser/giteaToken 또는 GITEA_USER/GITEA_TOKEN을 확인하세요.' + ) + } + + def groupPath = packageGroupId.replace('.', '/') + def pomUrl = "https://gitea.kric.com/api/packages/${packageOwner}/maven/${groupPath}/${packageArtifactId}/${packageVersion}/${packageArtifactId}-${packageVersion}.pom" + def auth = "${giteaUser}:${giteaToken}".bytes.encodeBase64().toString() + + def status = checkHttpStatus(pomUrl, auth, 'HEAD') + + if (status == 405) { + status = checkHttpStatus(pomUrl, auth, 'GET') + } + + if (status >= 200 && status < 300) { + throw new GradleException( + "[DUPLICATE_PACKAGE_VERSION] 이미 Gitea Packages에 동일 패키지가 존재합니다. " + + "package=${packageGroupId}:${packageArtifactId}:${packageVersion}. " + + "build.gradle의 commonVer를 올린 뒤 다시 배포하세요." + ) + } + + if (status == 404) { + println "Gitea Packages 중복 없음: ${packageGroupId}:${packageArtifactId}:${packageVersion}" + return + } + + if (status == 401 || status == 403) { + throw new GradleException( + "[GITEA_AUTH_FAILED] Gitea Packages 조회 권한 오류입니다. " + + "HTTP status=${status}. Jenkins credential 또는 token 권한을 확인하세요." + ) + } + + throw new GradleException( + "[GITEA_PACKAGE_CHECK_FAILED] Gitea Packages 중복 확인에 실패했습니다. " + + "HTTP status=${status}, url=${pomUrl}" + ) + } +} + +tasks.named('publishReleasePublicationToGiteaRepository') { + dependsOn 'checkGiteaPackageVersionNotExists' +} \ No newline at end of file