กำหนดค่า maven-publish สำหรับ KMP
เผยแพร่สิ่งประดิษฐ์ของทุกเป้าหมายและโมดูลข้อมูลเมทาดาทา
กำหนดค่า maven-publish สำหรับ KMP เป็นบทเรียน Kotlin Multiplatform Academy ฟรีบน CoddyKit นี่คือบทเรียนที่ 1 จากทั้งหมด 4 บทเรียน คุณสามารถอ่านบทเรียนทั้งหมดด้านล่างฟรี — จากนั้นลองปฏิบัติด้วยตัวคุณเองในเบราว์เซอร์พร้อมตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7 บทเรียนนี้เป็นส่วนหนึ่งของเส้นทางการเรียน Kotlin Multiplatform Academy และความก้าวหน้าของคุณจะซิงค์ข้ามเว็บและแอป CoddyKit คอร์ส Kotlin Multiplatform Academy มีบทเรียนทั้งหมด 4 บทเรียน
บางส่วนของบทเรียนนี้ยังไม่ได้รับการแปล และแสดงเป็นภาษาอังกฤษ
Why Publish at All
Once your shared module is solid, other teams want to reuse it. Publishing turns your code into a versioned artifact they can simply depend on. 📦
Meet maven-publish
The maven-publish Gradle plugin packages your build outputs into artifacts and writes the metadata repositories expect.
plugins {
kotlin("multiplatform")
id("maven-publish")
}KMP Publishes Many Artifacts
A KMP library is not one JAR. Each target gets its own artifact, plus a shared metadata module that ties them together.
The Root Metadata Module
The metadata module is the entry point consumers actually request. Gradle then resolves the right per-platform artifact behind it.
Coordinates Identify You
Every artifact needs coordinates: a group, an artifact name, and a version. Together they form the unique address others depend on.
group = "com.coddykit.shared"
version = "1.0.0"Declare a Repository
Tell Gradle where artifacts go using a publishing block. A local folder is perfect for testing before any remote release.
publishing {
repositories {
maven { url = uri(layout.buildDirectory.dir("repo")) }
}
}Run the Publish Task
The plugin adds Gradle tasks for you. Running publish builds every target and copies all artifacts into your chosen repository.
./gradlew :shared:publishAdd POM Metadata
The POM describes your library: name, description, and license. Public repositories require this so users know what they are pulling in.
pom {
name.set("Shared KMP")
description.set("Shared logic for both apps")
}Test Locally First
Publish to your mavenLocal cache, then add it as a dependency in a sample app. This proves the artifact resolves before you go public.
./gradlew :shared:publishToMavenLocalSources and Docs Jars
Ship a sources jar so consumers can read your code in their IDE. A docs jar adds the generated reference for an even better experience.
Keep Versions Honest
Bump the version on every release. Republishing the same version with new code breaks builds that already cached the old artifact.
Quick Check
Let's check how KMP publishing works.
Recap
Apply maven-publish, set coordinates, add a repository and POM, then publish locally to test before any real release. 🎉
คำถามที่พบบ่อย
บทเรียน “กำหนดค่า maven-publish สำหรับ KMP” ฟรีหรือไม่
ใช่ — ข้อความเต็มของ “กำหนดค่า maven-publish สำหรับ KMP” ฟรีให้อ่านที่นี่บนเว็บ เพื่อปฏิบัติแบบโต้ตอบ (ตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7) และปลดล็อคส่วนที่เหลือของคอร์ส Kotlin Multiplatform Academy ให้อัปเกรดเป็น CoddyKit PRO คอร์ส Kotlin Multiplatform Academy มีบทเรียนทั้งหมด 4 บทเรียน
คุณจะเรียนรู้อะไรในบทเรียน “กำหนดค่า maven-publish สำหรับ KMP”
เผยแพร่สิ่งประดิษฐ์ของทุกเป้าหมายและโมดูลข้อมูลเมทาดาทา คุณปฏิบัติ Kotlin Multiplatform Academy ด้วยโค้ดที่ใช้งานได้จริงที่คุณเรียกใช้โดยตรงในเบราว์เซอร์ และติวเตอร์ AI ตลอด 24/7 ตอบคำถามของคุณขณะที่คุณไปผ่านบทเรียน
คุณต้องมีประสบการณ์ก่อนที่จะเริ่มเรียน Kotlin Multiplatform Academy หรือไม่
ไม่จำเป็นต้องมีประสบการณ์มาก่อน Kotlin Multiplatform Academy บน CoddyKit ออกแบบมาสำหรับผู้เริ่มต้นไปจนถึงผู้เรียนขั้นสูง คุณสามารถเริ่มต้นที่นี่หรือเริ่มจากตัวแรกและเรียนด้วยความเร็วของคุณเอง นี่คือบทเรียนที่ 1 จากทั้งหมด 4 บทเรียน
บทเรียน “กำหนดค่า maven-publish สำหรับ KMP” ใช้เวลานานแค่ไหน
บทเรียน CoddyKit ส่วนใหญ่ใช้เวลาประมาณ 5–10 นาที แต่ละบทเรียนจึงสั้นและเป็นแบบโต้ตอบ คุณสามารถก้าวหน้าอย่างต่อเนื่องและกลับมาเรียนต่อจากตรงที่เพิ่งหยุดบนเว็บและแอปได้เลย
ฉันเขียนและรันโค้ดในบทเรียน Kotlin Multiplatform Academy นี้ได้ไหม
ได้ บทเรียน Kotlin Multiplatform Academy ทุกบทมีตัวแก้ไขโค้ดในตัว คุณจึงเขียนและรันโค้ดจริงได้เลยในเบราว์เซอร์ และได้รับข้อเสนอแนะจาก AI ในทันที — ไม่ต้องติดตั้งในเครื่องของคุณ
บทเรียนทั้งหมดในหลักสูตรนี้
- กำหนดค่า maven-publish สำหรับ KMP
- เผยแพร่ XCFramework สำหรับ iOS
- การกำหนดเวอร์ชันและความเสถียรของ API
- เผยแพร่ไปยัง Maven Central และ SPM