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

플러그인 적용과 게시

사용자 지정 플러그인을 프로젝트에 적용하고 로컬 또는 원격 저장소에 게시하는 방법을 배웁니다.

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

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

Reusing Your Gradle Plugins

So you've learned to create custom Gradle plugins. Great! But how do you actually use them in different projects, and how can you share them with others?

This lesson explores how to apply your custom plugins to a Gradle project and how to publish them to a local or remote repository for wider use.

Plugin Application Review

Before diving into custom plugins, let's quickly recall how you apply standard plugins.

  • Most plugins are applied using the plugins { id 'plugin-id' } block in your build.gradle file.
  • This method is preferred for its declarative nature and better tooling support.
  • It works for plugins from Gradle Plugin Portal, local buildSrc plugins, and published plugins.

Applying Script Plugins

You can define build logic directly within your build.gradle or include it from another script. This is the simplest form of reusing logic.

Below, a custom task myCustomTask is defined. It's available to your build script just like any other task.

task myCustomTask {
    doLast {
        println "Hello from my custom task!"
    }
}

task executeMyTask {
    dependsOn myCustomTask
    doLast {
        println "Main build script finished after custom task."
    }
}
// To run: gradle executeMyTask

Plugins from buildSrc

For more complex, project-specific plugins, Gradle automatically compiles and makes available any plugins defined in the buildSrc directory.

If you create a plugin in buildSrc/src/main/groovy/com/example/MyPlugin.groovy, it can be applied directly by its ID:

  • Define plugin: buildSrc/src/main/groovy/my.project.plugin.gradle
  • Apply plugin: plugins { id 'my.project.plugin' }

Gradle ensures buildSrc is built before your main project, making its plugins ready for use.

Why Publish Plugins?

While buildSrc is great for single-project or monorepo plugins, what if you want to share your plugin across completely separate projects, or even with the community?

This is where publishing comes in. Publishing makes your plugin available in a repository, just like any other library you use (e.g., from Maven Central).

  • Local: Share within your machine for personal use.
  • Remote: Share within your organization (Artifactory, Nexus) or globally (Gradle Plugin Portal, Maven Central).

Publishing with maven-publish

Gradle's maven-publish plugin is the standard way to publish your plugin artifacts to Maven-compatible repositories.

By applying this plugin, you gain access to a publishing block in your build.gradle, where you'll define the details of what gets published and how.

It also introduces tasks like publishToMavenLocal and publish.

plugins {
    id 'java-library' // Or 'groovy' for Groovy plugins
    id 'maven-publish'
}

group = 'com.coddykit.example'
version = '1.0.0'

// Applying maven-publish plugin
// This is part of setting up for publication.
// No direct output from this snippet alone.

Defining Publication Details

Inside the publishing block, you configure the details of your artifact: its name, what components to include (like JARs), and where it should go.

A "publication" defines a set of artifacts and their metadata (group, artifact ID, version).

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

group = 'com.coddykit.example'
version = '1.0.0'

publishing {
    publications {
        maven(MavenPublication) {
            // The artifact ID is usually derived from project name,
            // but can be explicitly set.
            artifactId 'my-groovy-plugin'
            from components.java // Publish the Java library component
        }
    }
}
// This defines how the plugin will be published.
// No direct output from this snippet alone.

Publishing to Maven Local

After configuring your publication, you can publish your plugin to your local Maven repository. This is great for local testing and development.

Gradle provides a task for each publication you define (e.g., publishMavenPublicationToMavenLocal if your publication is named maven).

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

group = 'com.coddykit.example'
version = '1.0.0'

publishing {
    publications {
        maven(MavenPublication) { // 'maven' is the publication name
            artifactId 'my-groovy-plugin'
            from components.java
        }
    }
    repositories {
        mavenLocal() // Explicitly declare mavenLocal for publishing
    }
}
// To publish: gradle publishMavenPublicationToMavenLocal
// This command will build your plugin and place its artifacts
// into your local Maven cache (~/.m2/repository).

Applying a Published Plugin

To use a plugin you've published to mavenLocal() in another project, you need two things:

  1. Declare mavenLocal(): Add mavenLocal() to the pluginManagement.repositories block in your consuming project's settings.gradle.
  2. Apply by ID and Version: Use the plugins { id '...' version '...' } block in your consuming project's build.gradle.

This tells Gradle to look for the plugin in your local Maven repository.

// settings.gradle (consuming project)
pluginManagement {
    repositories {
        mavenLocal()
        gradlePluginPortal()
    }
}

// build.gradle (consuming project)
plugins {
    id 'com.coddykit.example.my-groovy-plugin' version '1.0.0'
    // Replace 'com.coddykit.example.my-groovy-plugin' with your plugin's actual ID
}

// This code snippet shows how to apply a published plugin.
// It assumes the plugin has been published and is available locally.

Publishing Remotely

To share your plugin beyond your local machine, you publish it to a remote repository. This could be:

  • Company Artifactory/Nexus: For internal team use.
  • Gradle Plugin Portal: For public plugins, requiring the com.gradle.plugin-publish plugin.
  • Maven Central: The largest public repository.

The configuration in the publishing.repositories block specifies the URL and credentials for these remote destinations.

plugins {
    id 'maven-publish'
    // id 'com.gradle.plugin-publish' // For Gradle Plugin Portal
}

publishing {
    publications {
        maven(MavenPublication) { /* ... */ }
    }
    repositories {
        maven {
            name = "myCompanyRepo"
            url = uri("https://your.company.repo/releases")
            credentials {
                username = project.properties.get("repoUsername")
                password = project.properties.get("repoPassword")
            }
        }
    }
}
// This snippet shows how to define a remote repository.
// Credentials should be managed securely, not hardcoded.

Plugin Application Check

Time to test your understanding of applying and publishing plugins.

Recap: Apply & Publish

You've learned how to make your custom Gradle plugins truly reusable!

  • You can apply simple script plugins using apply from:.
  • Plugins in buildSrc are automatically available by ID.
  • The maven-publish plugin allows you to define and publish your plugin artifacts.
  • Publishing to mavenLocal() is great for local testing.
  • To use a published plugin, configure mavenLocal() in settings.gradle and apply it by ID and version.
  • Remote repositories enable sharing plugins across teams or publicly.

Now you can build powerful, shareable build logic!

자주 묻는 질문

“플러그인 적용과 게시” 강의는 무료인가요?

네 — “플러그인 적용과 게시” 전체 내용을 이 웹사이트에서 무료로 읽을 수 있습니다. 인터랙티브하게 실습하려면(내장 코드 에디터와 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개 중 3번째 강의입니다.

“플러그인 적용과 게시” 강의는 얼마나 걸리나요?

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

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

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

이 강의의 모든 강의

  1. Gradle 플러그인 이해하기
  2. 바이너리 플러그인 구축
  3. 플러그인 적용과 게시
  4. 플러그인 확장과 구성 가능한 DSL
← Groovy & Gradle: JVM Automation and Build Engineering(으)로 돌아가기