build.gradle를 세세하게 파보자!👷‍♂️

Leeseojune·2021년 6월 17일
26

SpringBoot

목록 보기
2/3
post-thumbnail

아래의 build.gradle는 여기에서 사용한 build.gradle이다.

이 build.gradle를 보면 일단 한숨부터 나온다... 😵😵

plugins {
    id 'java'
    id 'maven-publish'
    id 'signing'
}

group = ~~~
version = ~~~
sourceCompatibility = ~~~

repositories {
    mavenCentral()
}

dependencies {
    ~~~~
}

test {
    useJUnitPlatform()
}

task javadocJar(type: Jar) {
    archiveClassifier.set('javadoc')
    from javadoc.destinationDir
}

task sourcesJar(type: Jar) {
    archiveClassifier.set('sources')
    from sourceSets.main.allSource
}

publishing {
    publications {
        maven(MavenPublication) {
            artifactId = 'neis-api'
            from components.java
            artifact sourcesJar
            artifact javadocJar

            pom {
                name = 'Neis Api'
                description = 'Supporting to develop KOREA school service'
                url = 'https://github.com/leeseojune53/neis-api'

                licenses {
                    license {
                        name = 'MIT License'
                        url = 'https://opensource.org/licenses/MIT'
                    }
                }

                developers {
                    developer {
                        id = 'leeseojune'
                        name = 'Seojune Lee'
                        email = 'sung07288346@gmail.com'
                    }
                }

                scm {
                    connection = 'scm:svn:http://foo.googlecode.com/svn/trunk/'
                    developerConnection = 'scm:svn:https://foo.googlecode.com/svn/trunk/'
                    url = 'http://foo.googlecode.com/svn/trunk/'
                }
            }
        }
    }

    repositories {
        maven {
            name = "OSSRH"
            url = "https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/"
            credentials {
                username = System.getenv("MAVEN_USERNAME")
                password = System.getenv("MAVEN_PASSWORD")
            }
        }
        maven {
            name = "GitHubPackages"
            url = "https://maven.pkg.github.com/leeseojune53/neis-api"
            credentials {
                username = System.getenv("GITHUB_ACTOR")
                password = System.getenv("GITHUB_TOKEN")
            }
        }
    }
}

signing {
    useGpgCmd()
    sign(publishing.publications)
}

천천히 이 코드를 뜯어보겠습니다.

plugins

프로젝트의 기능을 확장할 수 있다.

  • Gradle 모델 확장 (ex : 구성할 수 있는 새 DSL요소 추가)
  • 규칙에 따라 프로젝트를 구성 (ex : 새 작업 추가또는 합리적인 기본값 구성)
  • 특정 구성 적용 (ex : 조직 저장소 추가 또는 표준 적용)

DSL(Domain Specific Language)이란? 특정 영역을 타겟하고 있는 언어를 말한다.
plugins : java, maven-publish, signing

task

Task는 gradle 명령으로 호출 실행 시킬 수 있는 것이다.

publishing

  • artifactId : 버전이 없는 .jar의 이름이다.
  • components.java : 간단하게 모듈의 단일 버전이다.
  • artifact : 메이븐 빌드의 결과로 얻을 수 있는 일반적인 jar 나 war 등 실행 파일을 의미한다.
  • artifact sourcesJar/javadocJar : 배포 시 source와 javadoc가 필요하기 때문.
  • name : 라이브러리 명
  • description : 라이브러리 설명
  • url : 라이브러리 소개 url
  • licenses : 라이브러리의 라이센스
  • developers : 개발자 인적사항
  • scm(Software Configuration Management) : 소프트웨어 형상 관리, 형상 관리 사이트에 대한 정보를 기술한다.
  • credentials : 인증할때 필요한 정보들을 넣는다.

이제 위의 build.gradle를 대략적으로 이해할 수 있을것이다.

3개의 댓글

comment-user-thumbnail
2021년 6월 18일

에잉,, 잘보고갑니다 ^^*~

2개의 답글