Posts ๐Ÿต Gradle ๋นŒ๋“œ ๋„๊ตฌ๋กœ ์ž๋ฐ” ํ”„๋กœ์ ํŠธ ๋งŒ๋“ค๊ธฐ
Post
Cancel

๐Ÿต Gradle ๋นŒ๋“œ ๋„๊ตฌ๋กœ ์ž๋ฐ” ํ”„๋กœ์ ํŠธ ๋งŒ๋“ค๊ธฐ

0. gradle์„ ์‚ฌ์šฉํ•˜๋Š” ์ด์œ 

ํ”„๋กœ๊ทธ๋ž˜๋ฐ ์ค‘์— ์ƒ์„ฑ๋˜๋Š” ํŒŒ์ผ์„ ๋‘๋Š” ํด๋”๊ฐ€ ํ”„๋กœ์ ํŠธ ํด๋”์ด๋‹ค. ๋‹ค์–‘ํ•œ ์ข…๋ฅ˜์˜ ํŒŒ์ผ์„ ํ•œ ํด๋”์— ๋‘๋ฉด ๊ด€๋ฆฌํ•˜๊ธฐ๊ฐ€ ๋ถˆํŽธํ•˜๊ธฐ ๋•Œ๋ฌธ์— ํ•˜์œ„ ํด๋”๋ฅผ ๋งŒ๋“ค์–ด ๊ตฌ๋ถ„ํ•œ๋‹ค. ํ”„๋กœ์ ํŠธ์˜ ํ•˜์œ„ ํด๋”๋ฅผ ๋งŒ๋“ค ๋•Œ๋Š” ๊ตญ๊ฐ€, ํšŒ์‚ฌ, ๊ฐœ๋ฐœ์ž, ํ”„๋กœ์ ํŠธ์— ์ƒ๊ด€ ์—†์ด ์ผ๊ด€๋œ ๋ฐฉ์‹์œผ๋กœ ๋‹ค๋ฃจ๊ธฐ ์œ„ํ•ด ๋ฉ”์ด๋ธ(Maven) ๋นŒ๋“œ ๋„๊ตฌ์˜ ํ‘œ์ค€ ๋””๋ ‰ํ† ๋ฆฌ ๊ตฌ์กฐ๋ฅผ ์‚ฌ์šฉํ•œ๋‹ค.

1
2
3
4
5
6
7
8
9
๋ฉ”์ด๋ธ ํ”„๋กœ์ ํŠธ ํด๋”
โ””โ”€โ”€ src
    โ”œโ”€โ”€ main  <== ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ๊ด€๋ จ ํŒŒ์ผ์„ ๋‘๋Š” ํด๋”
    โ”‚ย ย  โ”œโ”€โ”€ java    <== ์˜ˆ) ํŒจํ‚ค์ง€ ํด๋” ๋ฐ ์ž๋ฐ” ์†Œ์Šค ํŒŒ์ผ(.java)
    โ”‚ย ย  โ””โ”€โ”€ resources  <== ์˜ˆ) ํŒจํ‚ค์ง€ ํด๋” ๋ฐ ์„ค์ • ํŒŒ์ผ(.xml, .properties ๋“ฑ)
    โ”‚ย ย  โ””โ”€โ”€ webapp  <== ์›น ํŒŒ์ผ์„ ๋‘๋Š” ํด๋”
    โ””โ”€โ”€ test  <== ๋‹จ์œ„ ํ…Œ์ŠคํŠธ ๊ด€๋ จ ํŒŒ์ผ์„ ๋‘๋Š” ํด๋”
        โ”œโ”€โ”€ java    <== ํŒจํ‚ค์ง€ ํด๋” ๋ฐ ๋‹จ์œ„ ํ…Œ์ŠคํŠธ ์ž๋ฐ” ์†Œ์Šค ํŒŒ์ผ
        โ””โ”€โ”€ resources  <== ๋‹จ์œ„ ํ…Œ์ŠคํŠธ ๊ด€๋ จ ์„ค์ • ํŒŒ์ผ(.xml, .properties ๋“ฑ)

Gradle์ด๋ผ๋Š” ๋„๊ตฌ๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด ์œ„์™€ ๊ฐ™์€ ํ”„๋กœ์ ํŠธ ํด๋”๋ฅผ ์‰ฝ๊ฒŒ ๊ตฌ์„ฑํ•  ์ˆ˜ ์žˆ๋‹ค. Gradle์€ ํ”„๋กœ์ ํŠธ ํด๋” ๊ตฌ์„ฑ์—์„œ ์ปดํŒŒ์ผ, ํ…Œ์ŠคํŠธ, ๋ฐฐํฌ ํŒŒ์ผ ์ƒ์„ฑ ๋“ฑ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ์ƒ์„ฑ์— ํ•„์š”ํ•œ ์ „๋ฐ˜์ ์ธ ์ž‘์—…์„ ๋„์™€์ค€๋‹ค.

1. ์ž๋ฐ” ํ”„๋กœ์ ํŠธ ์‹œ์ž‘ํ•˜๊ธฐ

gradle init

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
bitcamp-java-project git:(master) โœ— gradle init
Starting a Gradle Daemon (subsequent builds will be faster)

Select type of project to generate:  <== ํ”„๋กœ์ ํŠธ ์œ ํ˜• ์„ ํƒ
  1: basic
  2: application
  3: library
  4: Gradle plugin
Enter selection (default: basic) [1..4] 2

Select implementation language: <== ํ”„๋กœ๊ทธ๋ž˜๋ฐ์— ์‚ฌ์šฉํ•  ์–ธ์–ด ์„ ํƒ
  1: C++
  2: Groovy
  3: Java
  4: Kotlin
  5: Swift
Enter selection (default: Java) [1..5] 3

Select build script DSL:
  1: Groovy <== ๋นŒ๋“œ ์Šคํฌ๋ฆฝํŠธ ํŒŒ์ผ์„ ์ž‘์„ฑํ•  ๋•Œ ์‚ฌ์šฉํ•  ์–ธ์–ด ์„ ํƒ
  2: Kotlin
Enter selection (default: Groovy) [1..2] 1

Select test framework:
  1: JUnit 4  <== ๋‹จ์œ„ ํ…Œ์ŠคํŠธ๋กœ ์‚ฌ์šฉํ•  ํ”„๋ ˆ์ž„์›Œํฌ ์„ ํƒ
  2: TestNG
  3: Spock
  4: JUnit Jupiter
Enter selection (default: JUnit 4) [1..4] 1

Project name (default: bitcamp-java-project): <== ํ”„๋กœ์ ํŠธ ์ด๋ฆ„ ์„ค์ •
Source package (default: bitcamp.java.project): com.eomcs.pms <== ์ž๋ฐ” ํŒจํ‚ค์ง€ ์„ค์ •

> Task :init
Get more help with your project: https://docs.gradle.org/6.5.1/userguide/tutorial_java_projects.html

BUILD SUCCESSFUL in 53s
2 actionable tasks: 2 executed

Gradle๋กœ ์ƒ์„ฑํ•œ ํ”„๋กœ์ ํŠธ ์„ค์ • ํŒŒ์ผ๊ณผ ํด๋”๋ฅผ ํ™•์ธํ•˜์ž.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
โ”œโ”€โ”€ build.gradle
โ”œโ”€โ”€ gradle
โ”‚ย ย  โ””โ”€โ”€ wrapper
โ”‚ย ย      โ”œโ”€โ”€ gradle-wrapper.jar <== (1)
โ”‚ย ย      โ””โ”€โ”€ gradle-wrapper.properties
โ”œโ”€โ”€ gradlew <== (2)
โ”œโ”€โ”€ gradlew.bat
โ”œโ”€โ”€ settings.gradle <== (3)
โ””โ”€โ”€ src
    โ”œโ”€โ”€ main
    โ”‚ย ย  โ”œโ”€โ”€ java
    โ”‚ย ย  โ”‚ย ย  โ””โ”€โ”€ com
    โ”‚ย ย  โ”‚ย ย      โ””โ”€โ”€ eomcs
    โ”‚ย ย  โ”‚ย ย          โ””โ”€โ”€ pms
    โ”‚ย ย  โ”‚ย ย              โ””โ”€โ”€ App.java
    โ”‚ย ย  โ””โ”€โ”€ resources
    โ””โ”€โ”€ test
        โ”œโ”€โ”€ java
        โ”‚ย ย  โ””โ”€โ”€ com
        โ”‚ย ย      โ””โ”€โ”€ eomcs
        โ”‚ย ย          โ””โ”€โ”€ pms
        โ”‚ย ย              โ””โ”€โ”€ AppTest.java
        โ””โ”€โ”€ resources

  • (2)gradlew: gradle๋กœ ๋นŒ๋“œํ•œ ํ”„๋กœ์ ํŠธ๋ฅผ ๋ˆ„๊ตฐ๊ฐ€ ์„œ๋ฒ„์— ์˜ฌ๋ฆฌ๊ณ  ๋™๋ฃŒ๊ฐ€ ํด๋ก ํ–ˆ์„ ๋•Œ, ๋™๋ฃŒ๋Š” ๊ตณ์ด ๋”ฐ๋กœ gradle์„ ์„ค์น˜ํ•˜์ง€ ์•Š์•„๋„ gradlew ํŒŒ์ผ์ด (1) gradle-wrapper.jar๋ฅผ ํ’€์–ด์„œ ์‹คํ–‰ํ•  ์ˆ˜ ์žˆ๊ฒŒ ํ•œ๋‹ค.
  • (3)settings.gradle: ํ”„๋กœ์ ํŠธ ์ด๋ฆ„์€ settings.gradle ํŒŒ์ผ ์•ˆ์— rootProject.name = 'ํ”„๋กœ์ ํŠธ์ด๋ฆ„'์œผ๋กœ ์ ํ˜€ ์žˆ๋‹ค.

2. ์ž๋ฐ” ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ์‹คํ–‰ํ•˜๊ธฐ

gradle run

  • gradle ๋„๊ตฌ๊ฐ€ ํด๋ž˜์Šค๋ฅผ ์‹คํ–‰ํ•œ๋‹ค.
  • ์‹คํ–‰ํ•˜๋Š” ํด๋ž˜์Šค๋ฅผ ๋ฐ”๊ฟ€ ๋•Œ๋งˆ๋‹ค build.gradle์— ์ ์–ด์ค˜์•ผ ํ•œ๋‹ค.
1
2
3
4
application {
    // Define the main class for the application.
    mainClassName = 'com.eomcs.pms.App'
}
  • ๊ทธ๋Ÿฌ๋ฉด ๊ท€์ฐฎ์ง€ ์•Š๋‚˜?? => ์‹ค๋ฌด์—์„œ ์•„๋ฌด๋ฆฌ ๋งŽ์€ ํŒŒ์ผ์„ ๋งŒ๋“ค์–ด๋„ ์‹คํ–‰ํ•˜๋Š” ํด๋ž˜์Šค๋Š” ํ•˜๋‚˜๋ฐ–์— ์—†์Œ(main)!

3. ์ž๋ฐ” ํ”„๋กœ์ ํŠธ ๋นŒ๋“œํ•˜๊ธฐ

  • ์ผ๋ฐ˜ ์‚ฌ์šฉ์ž์—๊ฒŒ ๋ฐฐํฌํ•  ํŒŒ์ผ์„ ๋งŒ๋“ ๋‹ค
  • ์šฐ๋ฆฌ๊ฐ€ ๋งŒ๋“  ํ”„๋กœ์ ํŠธ๋ฅผ ์ œํ’ˆ์œผ๋กœ ํŒจํ‚นํ•˜๋Š” ๊ณผ์ •

gradle build

๋นŒ๋“œ ์ ˆ์ฐจ

  • ์†Œ์Šค ํŒŒ์ผ ์ปดํŒŒ์ผ
  • ๋‹จ์œ„ ํ…Œ์ŠคํŠธ ์ˆ˜ํ–‰
  • .jar ์•„์นด์ด๋ธŒ ํŒŒ์ผ ์ƒ์„ฑ
  • ์‹คํ–‰๊ณผ ๊ด€๋ จ๋œ ํŒŒ์ผ ์ƒ์„ฑ
  • .tar, .zip ๋ฐฐํฌ ํŒŒ์ผ ์ƒ์„ฑ

๋นŒ๋“œํ•˜๋ฉด ๋‹ค์Œ๊ณผ ๊ฐ™์ด /build/distributions/์— ๋ฐฐํฌํŒŒ์ผ์ด ์ƒ๊ธด๋‹ค.

1
2
3
4
โ”œโ”€โ”€ build
โ”‚ย ย  โ”œโ”€โ”€ distributions
โ”‚ย ย  โ”‚ย ย  โ”œโ”€โ”€ bitcamp-java-project.tar  <== Unix/Linux ์‚ฌ์šฉ์ž์—๊ฒŒ ๋ฐฐํฌํ•˜๋Š” ํŒŒ์ผ
โ”‚ย ย  โ”‚ย ย  โ””โ”€โ”€ bitcamp-java-project.zip  <== Windows ์‚ฌ์šฉ์ž์—๊ฒŒ ๋ฐฐํฌํ•˜๋Š” ํŒŒ์ผ

๋ฐฐํฌ ํŒŒ์ผ์˜ ์••์ถ•์„ ํ”Œ๊ณ  ๊ทธ ์•ˆ์˜ ์Šคํฌ๋ฆฝํŠธ ํŒŒ์ผ์„ ์‹คํ–‰ํ•ด๋ณด์ž.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
โžœ  distributions git:(master) โœ— tar -xvf *.tar  <== ์••์ถ•ํŒŒ์ผ ํ‘ธ๋Š” ๋ช…๋ น์–ด 
โžœ  distributions git:(master) โœ— cd bitcamp-java-project 
โžœ  bitcamp-java-project git:(master) โœ— tree
.
โ”œโ”€โ”€ bin
โ”‚ย ย  โ”œโ”€โ”€ bitcamp-java-project
โ”‚ย ย  โ””โ”€โ”€ bitcamp-java-project.bat
โ””โ”€โ”€ lib
    โ”œโ”€โ”€ bitcamp-java-project.jar
    โ”œโ”€โ”€ checker-qual-2.11.1.jar
    โ”œโ”€โ”€ error_prone_annotations-2.3.4.jar
    โ”œโ”€โ”€ failureaccess-1.0.1.jar
    โ”œโ”€โ”€ guava-29.0-jre.jar
    โ”œโ”€โ”€ j2objc-annotations-1.3.jar
    โ”œโ”€โ”€ jsr305-3.0.2.jar
    โ””โ”€โ”€ listenablefuture-9999.0-empty-to-avoid-conflict-with-guava.jar

2 directories, 10 files
โžœ  bitcamp-java-project git:(master) โœ— cd bin 
โžœ  bin git:(master) โœ— ./bitcamp-java-project  <== ์Šคํฌ๋ฆฝํŠธ ํŒŒ์ผ ์‹คํ–‰
Hello world.
  • ์ด๋•Œ Windows os์˜ ๊ฒฝ์šฐ batํŒŒ์ผ์„ ์‹คํ–‰ํ•œ๋‹ค.
  • ํŠนํžˆ ์šฐ๋ฆฌ๊ฐ€ ๋งŒ๋“  app.class ๊ฐ€ lib์•ˆ์˜ bitcamp-java-project.jar์— ์žˆ๋‹ค.
  • ์—ฌ๊ธฐ์— ์žˆ๋Š” app.class๋ฅผ ์‹คํ–‰ํ•˜๋Š” ๋ช…๋ น์–ด๊ฐ€ bin์— ์žˆ๋Š” ๊ฑฐ!!! => ์ด๊ฒŒ ๋ฐ”๋กœ shell script์ด๋‹ค.
  • ์ด ์Šคํฌ๋ฆฝํŠธ๋Š” ๊ณ ๊ฐ ์ปดํ“จํ„ฐ๊ฐ€ ์–ด๋–ค์ง€ ๋ชจ๋ฅด๋‹ˆ๊นŒ ๋ชจ๋“  ๊ฒฝ์šฐ์˜ ์ˆ˜๋ฅผ ๋‹ค ๋”ฐ์ ธ๋ด์„œ ์‹คํ–‰ํ•  ์ˆ˜ ์žˆ๊ฒŒ ๋งŒ๋“ค์–ด์กŒ๋‹ค.
  • ๊ฐœ๋ฐœ์ž๋ผ๋ฉด ๊ทธ๋ƒฅ jvm์˜ java ๋ช…๋ น์–ด๋กœ ์‹คํ–‰ํ•  ์ˆ˜ ์žˆ๊ฒ ์ง€๋งŒ ๋นŒ๋“œ๋Š” ์ผ๋ฐ˜ ์‚ฌ์šฉ์ž๋ฅผ ์œ„ํ•ด ๋ฐฐํฌํŒŒ์ผ์„ ๋งŒ๋“œ๋Š” ๊ณผ์ •์ด๋‹ค.
  • gradle clean: ๋นŒ๋“œํ•œ ๊ฑธ ์‚ญ์ œํ•˜๋Š” ๋ช…๋ น์–ด
This post is licensed under CC BY 4.0 by the author.

๐Ÿ› zsh ์„ค์น˜ ์—๋Ÿฌ: PAM Authentication failures

oh-my-zsh ํ”Œ๋Ÿฌ๊ทธ์ธ์„ ํ™œ์šฉํ•œ ํ„ฐ๋ฏธ๋„ ํ…Œ๋งˆ ๋ฐ”๊พธ๊ธฐโœจ

Loading comments from Disqus ...