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

다중 언어 프로젝트 빌드

Gradle을 사용해 Scala, Groovy 또는 Android처럼 여러 언어가 포함된 프로젝트를 관리합니다.

레슨 2/411개 단계

다중 언어 프로젝트 빌드은(는) 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개의 강의가 포함되어 있습니다.

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

What are Polyglot Projects?

A polyglot project is one that uses multiple programming languages. This isn't uncommon, especially in large systems or microservices architectures.

For example, you might have a backend service written in Java, a data processing component in Scala, and utility scripts in Groovy, all contributing to a single application.

Gradle excels at managing such diverse projects, allowing you to leverage the strengths of different languages within a unified build system.

Gradle's Language Power

Gradle achieves its polyglot capabilities through its powerful plugin system. Each language typically has a dedicated plugin that understands its compilation, testing, and packaging requirements.

These plugins integrate seamlessly, allowing Gradle to orchestrate builds involving Java, Groovy, Scala, Kotlin, and even native languages like C/C++ (via NDK for Android).

This means you can define dependencies and tasks across different language modules, all within a single Gradle build.

Integrating Groovy Sources

Groovy is a popular choice for scripting and enhancing Java projects. To include Groovy code, you typically apply the groovy plugin and place your source files in src/main/groovy.

Here's a minimal build.gradle for a Groovy project:

plugins {
  id 'groovy'
}

repositories {
  mavenCentral()
}

dependencies {
  implementation 'org.codehaus.groovy:groovy-all:3.0.9'
}

Now, let's see a simple Groovy program.

class Main {
  static void main(String[] args) {
    println "Hello from Groovy!"
  }
}

Scala Integration with Gradle

Scala is another powerful JVM language. Gradle supports Scala projects using the scala plugin. This plugin handles Scala compilation and integrates with Java source compilation.

To set up a Scala project, you'd apply the plugin and define Scala-specific dependencies, typically including the Scala library itself:

plugins {
  id 'scala'
}

repositories {
  mavenCentral()
}

dependencies {
  implementation 'org.scala-lang:scala-library:2.13.6'
  // If mixing with Java, add Java dependencies here too
}

Scala source files usually reside in src/main/scala.

Running Scala Code

With the scala plugin configured, Gradle can compile and run your Scala code. Here's a basic Scala program:

object Main {
  def main(args: Array[String]): Unit = {
    println("Hello from Scala!")
  }
}

Java and Scala Together

One of Gradle's strengths is allowing different JVM languages to coexist within the same project. You can have Java files in src/main/java and Scala files in src/main/scala.

Gradle's scala plugin automatically configures the build to compile both Java and Scala sources, ensuring they can call each other's code. This is crucial for migrating existing Java codebases or building complex polyglot applications.

The Java compiler runs first, then the Scala compiler, which can then see the compiled Java classes.

Android's Polyglot Nature

Android projects are prime examples of polyglot builds. They commonly involve Java, Kotlin, and sometimes even native C/C++ code (via the NDK).

The Android Gradle Plugin (AGP), applied via id 'com.android.application' or id 'com.android.library', is a sophisticated plugin that orchestrates the compilation, resource processing, and packaging for all these languages into an APK or AAR.

This allows developers to choose the best language for different parts of an Android app.

Adding Kotlin to Your Build

Kotlin is fully interoperable with Java and is another excellent choice for polyglot JVM projects. To include Kotlin, you apply the kotlin-jvm plugin and place source files in src/main/kotlin.

Here's a minimal build.gradle:

plugins {
  id 'org.jetbrains.kotlin.jvm' version '1.9.0' // Use a recent version
}

repositories {
  mavenCentral()
}

dependencies {
  implementation 'org.jetbrains.kotlin:kotlin-stdlib'
}

Let's run a simple Kotlin program.

fun main() {
  println("Hello from Kotlin!")
}

Inter-Module Dependencies

In multi-project Gradle builds, you can define dependencies between subprojects written in different languages. For example, a Groovy subproject might depend on a Scala library subproject.

This is handled using standard Gradle project dependencies:

// In settings.gradle
include 'my-scala-lib', 'my-groovy-app'

// In my-groovy-app/build.gradle
dependencies {
  implementation project(':my-scala-lib')
}

Gradle ensures that the dependent project (e.g., Scala) is built and compiled before the consuming project (e.g., Groovy).

Polyglot Plugin Knowledge

Which of these Gradle plugins are specifically used to add language support for a programming language in a polyglot project?

Recap & Next Steps

Congratulations! You've explored how Gradle empowers you to manage polyglot projects, integrating multiple programming languages within a single build.

  • Gradle's plugin system is key to its language-agnostic approach.
  • You learned how to apply plugins for Groovy, Scala, and Kotlin.
  • We discussed how different language sources can coexist and depend on each other.
  • Android projects serve as a powerful example of real-world polyglot builds.

Mastering polyglot builds allows you to choose the best tool for each job, enhancing your project's flexibility and power. Keep experimenting with different language combinations!

무료로 시작

AI 튜터와 함께 Groovy을(를) 배우세요 — 무료

브라우저에서 실제 코드를 작성하고 실행하며, 24/7 AI 튜터로부터 즉각적인 도움을 받고, 웹이나 앱에서 중단한 부분부터 계속 학습하세요.

코스
12
레슨
48

자주 묻는 질문

“다중 언어 프로젝트 빌드” 강의는 무료인가요?

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

“다중 언어 프로젝트 빌드”에서 뭘 배우나요?

Gradle을 사용해 Scala, Groovy 또는 Android처럼 여러 언어가 포함된 프로젝트를 관리합니다. 브라우저에서 직접 실행하는 실습 코드로 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. Gradle용 Kotlin DSL
  2. 다중 언어 프로젝트 빌드
  3. IDE 통합과 도구
  4. Kotlin DSL로 사용자 지정 작업 작성
← Groovy & Gradle: JVM Automation and Build Engineering(으)로 돌아가기