0Pricing
Groovy & Gradle: JVM Automation and Build Engineering · 강의

하위 프로젝트와 구성

하위 프로젝트를 정의하고 구성하며 다중 프로젝트 빌드에서 서로 상호 작용하는 방식을 이해합니다.

하위 프로젝트와 구성은(는) CoddyKit의 무료 Groovy & Gradle: JVM Automation and Build Engineering 강의입니다. 이것은 4개 중 2번째 강의입니다. 아래에서 전체 강의를 무료로 읽을 수 있으며, 내장 코드 에디터와 24/7 AI 튜터와 함께 브라우저에서 직접 실습할 수 있습니다. 이 강의는 Groovy & Gradle: JVM Automation and Build Engineering 학습 경로의 일부이며, 진행 상황이 웹과 CoddyKit 앱에 동기화됩니다. Groovy & Gradle: JVM Automation and Build Engineering 강의에는 총 4개의 강의가 포함되어 있습니다.

이 강의의 일부는 아직 번역되지 않았으며 영어로 표시됩니다.

Welcome to Subprojects!

In large software projects, keeping everything in one giant build file can get messy. This is where subprojects come in handy!

Subprojects allow you to break down a big project into smaller, manageable modules. Think of them as mini-projects living within your main project.

  • Modularity: Organize code logically.
  • Reusability: Share common logic across modules.
  • Faster Builds: Gradle can optimize builds by only working on changed subprojects.

Declaring Subprojects

To tell Gradle about your subprojects, you use the settings.gradle file. This file lives in your root project directory.

You use the include keyword, followed by the path to your subproject's directory. Each subproject usually resides in its own folder.

/* settings.gradle */
rootProject.name = 'my-multi-project'

include 'app'
include 'library'

Subproject Directory Structure

Once declared in settings.gradle, your project structure will typically look like this:

  • my-multi-project/ (root project)
    • settings.gradle
    • build.gradle (root build file)
    • app/ (subproject 1)
      • build.gradle
      • ... (source code, resources)
    • library/ (subproject 2)
      • build.gradle
      • ... (source code, resources)

Each subproject gets its own build.gradle file.

Subproject Build Files

Just like your root project, each subproject has its own build.gradle file. This allows you to define specific configurations, dependencies, and tasks for that particular module.

For example, your app subproject might build a runnable application, while your library subproject might produce a reusable JAR.

/* library/build.gradle */
plugins {
    id 'java'
}

group 'com.coddykit'
version '1.0-SNAPSHOT'

repositories {
    mavenCentral()
}

dependencies {
    testImplementation platform('org.junit:junit-bom:5.9.1')
    testImplementation 'org.junit.jupiter:junit-jupiter'
}

Defining a Subproject Task

You can define tasks within a subproject's build.gradle file. These tasks are then specific to that subproject.

Let's add a simple task to our library subproject that prints a message.

/* library/build.gradle */
plugins {
    id 'java'
}

group 'com.coddykit'
version '1.0-SNAPSHOT'

repositories {
    mavenCentral()
}

task helloLibrary {
    doLast {
        println "Hello from the Library subproject!"
    }
}

Executing Subproject Tasks

To run a task belonging to a specific subproject from the root directory, you use a colon : to separate the subproject name and the task name.

For example, to run the helloLibrary task from our library subproject:

public class Main {
  public static void main(String[] args) {
    System.out.println("To run the task: gradle :library:helloLibrary");
    System.out.println("Output will be: Hello from the Library subproject!");
  }
}

Common Configuration: allprojects

Sometimes, you want to apply the same configuration to all projects in your multi-project build (the root project and all its subprojects).

You can do this using the allprojects { ... } block in your root build.gradle file.

/* build.gradle (root) */

allprojects {
    group 'com.coddykit.common'
    version '1.0.0'

    repositories {
        mavenCentral()
    }
}

Targeting Specific Subprojects

While allprojects is great for common settings, you often need to configure individual subprojects from the root build file.

You can use the project(':subprojectName') { ... } block to apply configuration specifically to one subproject.

/* build.gradle (root) */

project(':app') {
    apply plugin: 'application'
    mainClassName = 'com.coddykit.app.MainApp'
}

project(':library') {
    apply plugin: 'java-library'
}

Sharing Properties

You can also share properties or variables from your root project to all subprojects. This is useful for things like consistent version numbers or build flags.

Use the ext block (for "extra properties") in the root build.gradle and access it with rootProject.ext.propertyName in subprojects.

/* build.gradle (root) */
ext {
    groovyVersion = '3.0.9'
    springBootVersion = '2.7.5'
}

allprojects {
    // Access properties in subprojects
    println "Groovy Version: ${rootProject.ext.groovyVersion}"
}

Multi-Select Check

Which of the following statements about Gradle subprojects and their configuration are TRUE?

Subprojects Recap

Great job! You've learned the basics of setting up and configuring Gradle subprojects.

  • Subprojects help organize large builds.
  • They are declared in settings.gradle using include.
  • Each subproject has its own build.gradle.
  • You can configure all projects using allprojects { ... } or specific ones using project(':name') { ... }.
  • Tasks are run with the :subproject:task syntax.

Next, we'll explore how subprojects can depend on each other!

자주 묻는 질문

“하위 프로젝트와 구성” 강의는 무료인가요?

네 — “하위 프로젝트와 구성” 전체 내용을 이 웹사이트에서 무료로 읽을 수 있습니다. 인터랙티브하게 실습하려면(내장 코드 에디터와 24/7 AI 튜터), CoddyKit PRO로 업그레이드하면 Groovy & Gradle: JVM Automation and Build Engineering 강의 전체를 잠금 해제할 수 있습니다. Groovy & Gradle: JVM Automation and Build Engineering 강의에는 총 4개의 강의가 포함되어 있습니다.

“하위 프로젝트와 구성”에서 뭘 배우나요?

하위 프로젝트를 정의하고 구성하며 다중 프로젝트 빌드에서 서로 상호 작용하는 방식을 이해합니다. 브라우저에서 직접 실행하는 실습 코드로 Groovy & Gradle: JVM Automation and Build Engineering을(를) 배우며, 24/7 AI 튜터가 강의를 진행하면서 질문에 답변해줍니다.

Groovy & Gradle: JVM Automation and Build Engineering을(를) 시작하는 데 경험이 필요한가요?

사전 경험은 필요하지 않습니다. CoddyKit의 Groovy & Gradle: JVM Automation and Build Engineering은(는) 초급자부터 고급 학습자까지를 위해 구성되어 있으므로, 여기서 시작하거나 처음부터 시작할 수 있으며 자신의 속도대로 진행할 수 있습니다. 이것은 4개 중 2번째 강의입니다.

“하위 프로젝트와 구성” 강의는 얼마나 걸리나요?

대부분의 CoddyKit 강의는 약 5~10분이 소요됩니다. 각 강의는 간결하고 인터랙티브하여 꾸준한 진행이 가능하며, 웹과 앱에서 중단한 부분부터 바로 시작할 수 있습니다.

이 Groovy & Gradle: JVM Automation and Build Engineering 강의에서 코드를 작성하고 실행할 수 있나요?

네. 모든 Groovy & Gradle: JVM Automation and Build Engineering 강의에는 내장 코드 에디터가 포함되어 있으므로, 브라우저에서 바로 실제 코드를 작성하고 실행한 후 즉시 AI 피드백을 받을 수 있습니다 — 로컬 설정이 필요 없습니다.

이 강의의 모든 강의

  1. 모노레포 프로젝트 구조
  2. 하위 프로젝트와 구성
  3. 프로젝트 간 의존성
  4. 합성 빌드와 빌드 조합
← Groovy & Gradle: JVM Automation and Build Engineering(으)로 돌아가기