๐Ÿ˜Gradle๊ณผ ๋ฉ€ํ‹ฐ ๋ชจ๋“ˆ ์„ค๊ณ„(1)

Big0ยท2023๋…„ 6์›” 15์ผ
0
post-thumbnail
post-custom-banner

Gradle, Maven, Ant๋Š” ๋ชจ๋‘ ๋นŒ๋“œ ๋„๊ตฌ๋‹ค. ๋นŒ๋“œ ๋„๊ตฌ๋ž€ ๋ฌด์—‡์ธ๊ฐ€?!

์šฐ๋ฆฌ๊ฐ€ ์—ด์‹ฌํžˆ ์ž‘์„ฑํ•œ ์ฝ”๋“œ๋ฅผ ์„œ๋ฒ„์— ๋ฐฐํฌํ•œ๋‹ค๊ณ  ๊ฐ€์ •ํ•˜์ž. ์ด ๊ณผ์ •์—์„œ ํ•„์š”ํ•œ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ๋‹ค์šด ๋ฐ›๊ณ (์ด ๋•Œ ๋ฒ„์ „์ด ๋งž์ง€ ์•Š๋‹ค๋ฉด ๋‹ค์‹œ ๋‹ค์šด ๋ฐ›์•„์•ผํ•œ๋‹ค..), ํ…Œ์ŠคํŒ…์„ ๊ฑฐ์ณ ๋ฐฐํฌํ•˜๋Š” ์ž‘์—…๊นŒ์ง€๋ฅผ ๋ชจ๋‘ ์ผ์ผ์ด ํ•œ๋‹ค๊ณ  ํ–ˆ์„ ๋•Œ ์ •๋ง ํž˜๋“ค ๊ฒƒ์ด๋‹ค.

๋นŒ๋“œ ๋„๊ตฌ๋ž€, ์ฝ”๋“œ๋ฅผ ์‹คํ–‰ ๊ฐ€๋Šฅํ•œ ํŒŒ์ผ๋กœ ๋งŒ๋“ค์–ด์ฃผ๋Š” ๊ณผ์ •์—์„œ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ ๊ด€๋ฆฌ, ํ…Œ์ŠคํŒ…, ๋ฐฐํฌ ๋“ฑ์„ ์ž๋™ํ™” ํ•˜์—ฌ ์ˆ˜ํ–‰ํ•ด์ฃผ๋Š” ๋„๊ตฌ๋ผ๊ณ  ํ•  ์ˆ˜ ์žˆ๋‹ค.

ํƒœ์ดˆ์— Ant๊ฐ€ ์žˆ์—ˆ์œผ๋‹ˆ.

// build.xml
<?xml version="1.0" encoding="UTF-8"?>
<!-- ํ”„๋กœ์ ํŠธ ๋นŒ๋“œ์šฉ Ant ์Šคํฌ๋ฆฝํŠธ. build.properties์˜ ๋‚ด์šฉ์„ ๊ธฐ๋ณธ ์„ค์ •์œผ๋กœ ์‚ฌ์šฉํ•œ๋‹ค.-->
<project name="common" default="compile">
    <property name="src.dir" value="src" />
	 
  	<target name="clean">
        <delete dir="build"/>
    </target>

    <target name="compile">
        <mkdir dir="build/classes"/>
        <javac srcdir="src" destdir="build/classes"/>
    </target>

    <target name="jar">
        <mkdir dir="build/jar"/>
        <jar destfile="build/jar/HelloWorld.jar" basedir="build/classes">
            <manifest>
                <attribute name="Main-Class" value="oata.HelloWorld"/>
            </manifest>
        </jar>
    </target>

    <target name="run">
        <java jar="build/jar/HelloWorld.jar" fork="true"/>
    </target>
</project>
  • Maven๊ณผ ๊ฐ™์€ XML์„ ์‚ฌ์šฉํ•˜๊ณ , XML์„ ์‚ฌ์šฉํ•ด์„œ ๊ทธ๋Ÿฐ์ง€ ๊ฐ€๋…์„ฑ์ด ๋–จ์–ด์ง„๋‹ค.

  • Ant๋Š” Remote Repository๋ฅผ ์‚ฌ์šฉํ•  ์ˆ˜ ์—†๋Š”๋ฐ, Remote Repository๋Š” Gradle์ด๋‚˜ Maven์„ ์‚ฌ์šฉํ•  ๋•Œ mavenRepository์—์„œ ์˜์กด์„ฑ์„ ์ฐพ์•„์„œ ๋„ฃ์–ด์ฃผ๊ธฐ๋งŒ ํ•˜๋ฉด ๋˜๋Š”๋ฐ, Ant๋Š” ์ด๊ฒŒ ๋ถˆ๊ฐ€๋Šฅํ•˜๋‹ค. ์ง์ ‘ jar๋ฅผ ๋ฐ›์•„์„œ ๋„ฃ์–ด์ค˜์•ผ ํ•œ๋‹ค..(์•„๋ž˜ ์˜ˆ์‹œ)

// maven
<dependency>
    <groupId>org.projectlombok</groupId>
    <artifactId>lombok</artifactId>
    <version>1.18.16</version>
    <scope>provided</scope>
</dependency>
providedCompile group: 'org.projectlombok', name: 'lombok', version: '1.18.16'

Ant๋ฅผ ๋ณด์™„ํ•œ Maven

Ant์™€ ๊ฐ™์€ Apache์—์„œ ๊ฐœ๋ฐœ๋˜์—ˆ๋‹ค.

  • ์ƒ๋ช…์ฃผ๊ธฐ(Lifecycle)์˜ ๊ฐœ๋…์ด ๋„์ž…๋˜์—ˆ๋‹ค.

    • ๋นŒ๋“œ ๋„๊ตฌ์˜ Lifecycle์€ ๊ฐœ๋ฐœ์ž๊ฐ€ ํ”„๋กœ์ ํŠธ๋ฅผ ๋นŒ๋“œํ•˜๊ฑฐ๋‚˜ ๋ฐฐํฌํ•  ๋•Œ ์–ด๋–ค ๋‹จ๊ณ„๋“ค์„ ๊ฑฐ์ณ์•ผ ํ•˜๋Š”์ง€๋ฅผ ์ •์˜ํ•œ๋‹ค.
    • **clean**, compile, test, package, install, deploy ๋“ฑ์ด ์žˆ๋‹ค.
  • POM ํŒŒ์ผ์„ ํ†ตํ•ด mavenRepository์—์„œ ํ”Œ๋Ÿฌ๊ทธ์ธ๊ณผ ์˜์กด์„ฑ์„ ๋ฐ›์•„์˜ฌ ์ˆ˜ ์žˆ๊ณ , ๊ด€๋ฆฌ๊นŒ์ง€ ๊ฐ€๋Šฅํ•˜๋‹ค.

  • ํ•˜์ง€๋งŒ ๋ฉ”์ด๋ธ์€ Ant์™€ ๋งˆ์ฐฌ๊ฐ€์ง€๋กœ XML์„ ๊ธฐ๋ฐ˜์œผ๋กœ ํ•œ๋‹ค. ์ฆ‰ ํ”„๋กœ์ ํŠธ๊ฐ€ ๋ณต์žกํ•ด์ง€๊ณ , ์˜์กด์„ฑ์ด ๋งŽ์•„์ง€๊ณ , ํ”Œ๋Ÿฌ๊ทธ์ธ์ด ๋งŽ์•„์งˆ ์ˆ˜๋ก ๊ฐ€๋…์„ฑ์ด ๋–จ์–ด์ง„๋‹ค. ์•„๋ž˜๋Š” ๊ทธ ์˜ˆ์‹œ๋‹ค.

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.example</groupId>
    <artifactId>my-project</artifactId>
    <version>1.0.0</version>
    <dependencies>
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-lang3</artifactId>
            <version>3.12.0</version>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.13.2</version>
            <scope>test</scope>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.1</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>
  • XML๊ธฐ๋ฐ˜์˜ ๋นŒ๋“œ ๋„๊ตฌ๋Š” ๋˜ ํ•œ๊ฐ€์ง€ ๋ฌธ์ œ์ ์ด ์žˆ๋‹ค. XML์€ ์ •์ ์ธ ๋ฐ์ดํ„ฐ๋ฅผ ์ €์žฅํ•˜๋Š”๋ฐ ์ ํ•ฉํ•œ ์–ธ์–ด๊ณ , ๋™์ ์ธ ํ–‰์œ„์ธ ๋นŒ๋“œ์— ํฌ๋‚˜ํฐ ์ œ์•ฝ์ด ๊ฑธ๋ฆฐ๋‹ค.

  • Maven์€ ๋ฉ€ํ‹ฐ ๋ชจ๋“ˆ ๊ตฌํ˜„์„ ์ง€์›ํ•˜๋Š”๋ฐ, ์ด๋ฅผ ์ƒ์† ๊ตฌ์กฐ๋กœ ํ‘œํ˜„ํ•˜๊ณ  ์žˆ๋‹ค.

    • ์ด๋Š” ํ”„๋กœ์ ํŠธ ๊ตฌ์กฐ๊ฐ€ ๋ณต์žกํ•ด์งˆ์ˆ˜๋ก ์ดํ•ดํ•˜๊ธฐ ์–ด๋ ค์›Œ์ง€๊ณ , ์œ ์ง€๋ณด์ˆ˜๊ฐ€ ์–ด๋ ค์›Œ์งˆ ๊ฐ€๋Šฅ์„ฑ์ด ๋†’๋‹ค.
    • ์ƒ์† ๊ตฌ์กฐ๋Š” ์œ ์—ฐ์„ฑ๊ณผ ํ™•์žฅ์„ฑ์ด ์ œํ•œ๋  ์ˆ˜ ์žˆ๋‹ค. Parent ๋ชจ๋“ˆ์„ ์ƒ์†๋ฐ›์€ Child๋ชจ๋“ˆ์—์„œ ์ƒˆ๋กœ์šด ์˜์กด์„ฑ์„ ์ถ”๊ฐ€ํ•  ๋•Œ ๋ฌธ์ œ๊ฐ€ ๋ฐœ์ƒํ•  ์ˆ˜ ์žˆ์œผ๋ฉฐ, ๋‹น์—ฐํžˆ ์ž์‹์ด ๋งŽ์•„์ง€๊ณ  ๊ตฌ์กฐ๊ฐ€ ๋ณต์žกํ•ด์ง€๋ฉด ๊ฒฐํ•ฉ๋„๊ฐ€ ๊ฐ•ํ•ด์ ธ ๋‹ค๋ฅธ ์˜์กด์„ฑ์„ ์ถ”๊ฐ€ํ•  ๋•Œ ์ œ์•ฝ์ด ๋ฐœ์ƒํ•  ์ˆ˜ ์žˆ๋‹ค.

Maven์„ ๋„˜์–ด Gradle๋กœ ๊ฐ€์ž.

๊ทธ๋ ‡๊ฒŒ ๋“ฑ์žฅํ•œ Gradle

  • Gradle์€ build.gradle๋กœ ๊ด€๋ฆฌ๋œ๋‹ค. Ant์™€ Maven๊ณผ ๋‹ค๋ฅด๊ฒŒ Groovy๊ธฐ๋ฐ˜์˜ DSL(Domain Specific Languages)์„ ์‚ฌ์šฉํ•œ๋‹ค.
    • XML์€ ํƒœ๊ทธ๊ฐ€ ๋งŽ์•„์„œ ๊ฐ€๋…์„ฑ์ด ๋–จ์–ด์กŒ์ง€๋งŒ, Groovy๋ฅผ ํ†ตํ•ด ๋งŽ์ด ๊ฐ„๊ฒฐํ•ด์กŒ๋‹ค.
//์˜ˆ์ œ ์ฝ”๋“œ
plugins {
    id 'org.springframework.boot' version '2.3.4.RELEASE'
    id 'io.spring.dependency-management' version '1.0.10.RELEASE'
    id 'java'
}

group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.8'

configurations {
    compileOnly {
        extendsFrom annotationProcessor
    }
}

repositories {
    mavenCentral()
}

//๋™์  ๋นŒ๋“œ
**def gradleProfile = project.hasProperty("profile") 
										? project.property("profile").tostring() : "local"**

dependencies {
    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'
    }
		//๋™์  ๋นŒ๋“œ
		if (gradleProfile == "local"){
			implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
		}
}

test {
    useJUnitPlatform()
}
  • Gradle์€ Groovy ๊ธฐ๋ฐ˜์œผ๋กœ ๋™์ž‘ํ•˜๊ธฐ ๋•Œ๋ฌธ์— Groovy ์Šคํฌ๋ฆฝํŠธ๋กœ ํ”Œ๋Ÿฌ๊ทธ์ธ์„ ํ˜ธ์ถœํ•˜๊ฑฐ๋‚˜ ์ฝ”๋“œ๋ฅผ ์ž‘์„ฑํ•  ์ˆ˜ ์žˆ๋‹ค. โ‡’ ๋™์ ์ธ ๋นŒ๋“œ๊ฐ€ ๊ฐ€๋Šฅํ•˜๋‹ค!

    • ํ”„๋กœ์ ํŠธ์˜ ์กฐ๊ฑด์„ ์ฒดํฌํ•  ์ˆ˜ ์žˆ๋Š”๋ฐ, ์ด๋ฅผ ํ†ตํ•ด ์œ ์—ฐํ•œ ์„ค์ •์ด ๊ฐ€๋Šฅํ•˜๋‹ค.
    • ํŠน์ • ์ƒํ™ฉ์—์„œ๋งŒ ๋™์ž‘ํ•˜๊ฒŒ๋” ์„ค์ • ๊ฐ€๋Šฅํ•˜๋‹ค. (์œ„ ์ฝ”๋“œ์˜ ์ฃผ์„ ํ™•์ธ)

๊ทธ๋ž˜๋“ค์˜ ์„ฑ๋Šฅ์ƒ ์ด์ 

Daemon

  • Gradle ๋นŒ๋“œ์‹œ์— daemon ์ƒํƒœ๋กœ ๋™์ž‘ํ•˜๊ฒŒ ๋˜์–ด ์ธ์Šคํ„ด์Šค๋ฅผ ์œ ์ง€ํ•˜๊ณ  ๋นŒ๋“œ๊ฐ€ ๋๋‚œ ๋’ค์—๋„ background์—์„œ ๋™์ž‘๋˜์–ด ์‚ฌ๋ผ์ง€์ง€ ์•Š๋Š”๋‹ค.

  • Gradle Daemone ์œ ๋ฌด ์ฐจ์ด

    • ๋นŒ๋“œ ์‹œ๊ฐ„์ด daemon์„ ์‹คํ–‰ํ•˜๊ธฐ ์ „ 59์ดˆ์—์„œ daemon์„ ์‹คํ–‰ํ•œ ํ›„ 2์ดˆ๋กœ ํ™•์—ฐํžˆ ์ค„์–ด๋“  ๊ฒƒ์„ ๋ณผ ์ˆ˜ ์žˆ๋‹ค. (์ด๋Š” ์ฝ”๋“œ ๋ณ€๊ฒฝ ์—†์ด ๊ทธ๋Œ€๋กœ ์žฌ์‹œ์ž‘ ํ–ˆ์„ ๋•Œ์˜ ๊ฒฝ์šฐ๋‹ค.)

๋ณ‘๋ ฌ ์ฒ˜๋ฆฌ(Parallel)

- ํ”„๋กœ์ ํŠธ๋ฅผ ๋ฉ€ํ‹ฐ ๋ชจ๋“ˆ(Multi Module) ํ˜น์€ MSA(Micro Service Architecture)๋ฅผ ๊ตฌ์„ฑํ•  ๋•Œ ๊ฐ ํ”„๋กœ์ ํŠธ๋ฅผ ๊ฐœ๋ณ„์ ์œผ๋กœ ๋นŒ๋“œํ•  ์ˆ˜ ์žˆ๋‹ค.
- ๋‹ค์Œ์€ Gradle ๊ณต์‹ ํ™ˆํŽ˜์ด์ง€์—์„œ ๊ฐ€์ ธ์˜จ ๋ณ‘๋ ฌ์ฒ˜๋ฆฌ ์œ ๋ฌด์— ๋”ฐ๋ฅธ ์‹คํ–‰ ์‹œ๊ฐ„ ๋น„๊ต ๋ถ„์„์ด๋‹ค.

![](https://velog.velcdn.com/images/789456jang/post/566536d8-0547-44f8-a9ea-7a13528a7ba7/image.png)

![](https://velog.velcdn.com/images/789456jang/post/3a9ad394-e09b-435a-a68e-1951ac8421ac/image.png)
  • Paralell ์ฒ˜๋ฆฌ๋ฅผ ํ•˜์ง€ ์•Š๊ณ  ์‹คํ–‰ ํ–ˆ์„ ๋•Œ 8์ดˆ ๊ฐ€๋Ÿ‰ ์†Œ์š”, ๋ฐ˜๋ฉด์— Paralell ์ฒ˜๋ฆฌ๋ฅผ ํ•œ ๊ฒฐ๊ณผ 40% ๊ฐ€๋Ÿ‰ ์‹œ๊ฐ„์ด ๋‹จ์ถ•

์บ์‹œ(cache)

  • ์ด์ „์— ์‹คํ–‰ํ•œ ์ž‘์—…์˜ ๊ฒฐ๊ณผ๋ฅผ ์ €์žฅํ•˜๊ณ  ์žฌ์‚ฌ์šฉํ•˜๋Š” ๋งค์ปค๋‹ˆ์ฆ˜์ด๋‹ค.

  • ๋Œ€ํ‘œ์ ์œผ๋กœ ์˜์กด์„ฑ ์บ์‹ฑ๊ณผ ํƒœ์Šคํฌ ์บ์‹ฑ์ด ์žˆ๋‹ค.

    • ์˜์กด์„ฑ ์บ์‹ฑ: ์™ธ๋ถ€ Repository์—์„œ ๊ฐ€์ ธ์˜จ ์˜์กด์„ฑ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ๋กœ์ปฌ ์บ์‹œ์— ์ €์žฅํ•˜์—ฌ ๋‹ค์Œ ๋นŒ๋“œ์— ์žฌ์‚ฌ์šฉํ•˜๊ฒŒ๋” ๋งŒ๋“ค์–ด์ค€๋‹ค.
    • ํƒœ์Šคํฌ(Task) ์บ์‹ฑ: ํƒœ์Šคํฌ ์ˆ˜ํ–‰ ์ค‘ ์ค‘๋ณต๋˜๋Š” ๋ถ€๋ถ„์„ ์žฌ์‚ฌ์šฉํ•จ์œผ๋กœ์จ ๋นŒ๋“œ ์‹œ๊ฐ„์„ ๋‹จ์ถ•ํ•œ๋‹ค. ํƒœ์Šคํฌ ์บ์‹ฑ์€ ์ด์ „์— ์„ฑ๊ณต์ ์œผ๋กœ ์‹คํ–‰๋œ ํƒœ์Šคํฌ์— ๋™์ผํ•œ ์ž…๋ ฅ ๊ฐ’์ด ์ฃผ์–ด์ง„ ๊ฒฝ์šฐ์—๋งŒ ํƒœ์Šคํฌ๋ฅผ ๋‹ค์‹œ ์‹คํ–‰ํ•ฉ๋‹ˆ๋‹ค.
post-custom-banner

0๊ฐœ์˜ ๋Œ“๊ธ€