กำหนดค่าอุปกรณ์ทดสอบสำหรับสื่อเผยแพร่
จัดทุกอย่างให้เป็นระเบียบอยู่เสมอด้วยคอลเล็กชัน
บันทึกและจัดหมวดหมู่เนื้อหาตามค่ากำหนดของคุณ
ขณะที่การเผยแพร่อุปกรณ์ทดสอบไม่จำเป็นต้องมีการกำหนดค่าใดๆ
ของสื่อเผยแพร่
กลไกความสามารถในการทำงาน
ที่ใช้จัดการอุปกรณ์ต้องมีการกำหนดค่าเพิ่มเติม
สำหรับอาร์ติแฟกต์ที่มีพิกัด groupId:artifactId:version
, Gradle
คาดว่าอาร์ติแฟกต์อุปกรณ์ทดสอบจะประกาศความสามารถพร้อมด้วยพิกัด
groupId:artifactId-test-fixtures:version
ขั้นตอนนี้ยังไม่ดำเนินการในขณะนี้
ผ่านการสนับสนุนอุปกรณ์ทดสอบหรือปลั๊กอิน Maven Publish โดยอัตโนมัติ
ดังนั้นจึงต้องดำเนินการด้วยตนเอง
Gradle สร้างความสามารถจากชื่อ กลุ่ม และเวอร์ชันของโปรเจ็กต์
ต้องตั้งค่าทั้ง 3 รายการให้ตรงกับชุด artifactId
, groupId
และ version
ในสื่อเผยแพร่
ชื่อของโปรเจ็กต์คือกลุ่มสุดท้ายของเส้นทางโดยค่าเริ่มต้น ดังนั้นค่าเริ่มต้น
ชื่อของโปรเจ็กต์ที่มีเส้นทาง :path:to:mylibrary
คือ mylibrary
หากนี่คือ
ไม่ใช่สิ่งที่คุณต้องการใช้สำหรับ artifactId
คุณจะต้องเปลี่ยนโปรเจ็กต์
ชื่อ
การเปลี่ยนชื่อโปรเจ็กต์มี 2 วิธีดังนี้
- เปลี่ยนชื่อโฟลเดอร์ของโปรเจ็กต์ ซึ่งจะเปลี่ยนชื่อโปรเจ็กต์ หรือ
เส้นทาง Gradle ของโปรเจ็กต์ ดังนั้นทรัพยากร Dependency ทั้งหมดในโปรเจ็กต์จะต้อง
อัปเดตแล้ว การเลือกชื่อและโฟลเดอร์ของโปรเจ็กต์ไว้เหมือนเดิม
การจัดโครงสร้างใหม่จะช่วยลดความสับสนลงได้ในช่วงแรก
- เปลี่ยนชื่อโปรเจ็กต์ใน Gradle โดยไม่ต้องเปลี่ยนชื่อโฟลเดอร์ของโปรเจ็กต์ ช่วงเวลานี้
หลีกเลี่ยงผลกระทบต่อการกำหนดเวอร์ชันแหล่งที่มา แต่จะแบ่งตำแหน่งที่ตั้งของโปรเจ็กต์
และชื่อของ
หากต้องการเปลี่ยนชื่อโปรเจ็กต์ใน Gradle ให้แทรกโค้ดต่อไปนี้ใน
settings.gradle
ไฟล์:
ดึงดูด
include ':path:to:mylibrary'
project(':path:to:mylibrary').name = 'my-library'
Kotlin
include(":path:to:mylibrary")
project(":path:to:mylibrary").name = "my-library"
โค้ดนี้จะกำหนดเส้นทางใหม่ของโปรเจ็กต์ให้กับ :path:to:my-library
ค่า groupId
มีค่าเริ่มต้นเป็นชื่อบิลด์ ซึ่งโดยทั่วไปจะเป็นชื่อของ
โฟลเดอร์รูท และค่า version
จะไม่ได้ระบุโดยค่าเริ่มต้น หากต้องการเปลี่ยน
ค่าของรหัสหรือเวอร์ชันกลุ่ม ให้กำหนดพร็อพเพอร์ตี้ group
และ version
ในไฟล์ build.gradle
ระดับโปรเจ็กต์ตามลำดับ (สำหรับ Groovy) หรือ
build.gradle.kts
(สำหรับสคริปต์ Kotlin):
ดึงดูด
group = 'com.my-company'
version = '1.0'
Kotlin
group = "com.my-company"
version = "1.0"
ตัวอย่างเนื้อหาและโค้ดในหน้าเว็บนี้ขึ้นอยู่กับใบอนุญาตที่อธิบายไว้ในใบอนุญาตการใช้เนื้อหา Java และ OpenJDK เป็นเครื่องหมายการค้าหรือเครื่องหมายการค้าจดทะเบียนของ Oracle และ/หรือบริษัทในเครือ
อัปเดตล่าสุด 2025-07-27 UTC
[[["เข้าใจง่าย","easyToUnderstand","thumb-up"],["แก้ปัญหาของฉันได้","solvedMyProblem","thumb-up"],["อื่นๆ","otherUp","thumb-up"]],[["ไม่มีข้อมูลที่ฉันต้องการ","missingTheInformationINeed","thumb-down"],["ซับซ้อนเกินไป/มีหลายขั้นตอนมากเกินไป","tooComplicatedTooManySteps","thumb-down"],["ล้าสมัย","outOfDate","thumb-down"],["ปัญหาเกี่ยวกับการแปล","translationIssue","thumb-down"],["ตัวอย่าง/ปัญหาเกี่ยวกับโค้ด","samplesCodeIssue","thumb-down"],["อื่นๆ","otherDown","thumb-down"]],["อัปเดตล่าสุด 2025-07-27 UTC"],[],[],null,["# Configure test fixtures for publication\n\nWhile publishing test fixtures doesn't require any particular configuration\nof the publication, the\n[capability mechanism](https://docs.gradle.org/current/userguide/component_capabilities.html)\nused to handle fixtures does require an additional configuration.\n\nFor a given artifact with coordinates `groupId:artifactId:version`, Gradle\nexpects that the test fixtures artifact declares a capability with coordinates\n`groupId:artifactId-test-fixtures:version`. This is not currently done\nautomatically by either the test fixture support or the Maven Publish Plugin,\nand therefore must be done manually.\n\nGradle creates the capability from the project's name, group, and version.\nAll three must be set up to match the `artifactId`, `groupId`, and `version` set\nin the publication.\n\nThe project's name is the last segment of its path by default, so the default\nname of a project with the path `:path:to:mylibrary` is `mylibrary`. If this is\nnot what you want to use for `artifactId`, then you need to change your project\nname.\n\nThere are two options for renaming your project:\n\n- Rename the folder of the project. This changes the project name, or the Gradle path of the project, so all dependencies on the project need to be updated. While keeping the project name and folder the same might create more reorganization work initially, it reduces confusion.\n- Rename the project in Gradle without renaming the folder of the project. This avoids the impact on source versioning, but it splits the project location and name.\n\nTo rename the project in Gradle, insert the following code in the\n`settings.gradle` file: \n\n### Groovy\n\n```groovy\ninclude ':path:to:mylibrary'\nproject(':path:to:mylibrary').name = 'my-library'\n```\n\n### Kotlin\n\n```kotlin\ninclude(\":path:to:mylibrary\")\nproject(\":path:to:mylibrary\").name = \"my-library\"\n```\n\nThis code assigns the new path of the project to `:path:to:my-library`.\n\nThe value `groupId` defaults to the build name, which is generally the name of\nthe root folder, and the value `version` is by default unspecified. To change\nthe values of the group ID or version, set the `group` and `version` properties,\nrespectively, in your project-level `build.gradle` file (for Groovy) or\n`build.gradle.kts` (for Kotlin script): \n\n### Groovy\n\n```groovy\ngroup = 'com.my-company'\nversion = '1.0'\n```\n\n### Kotlin\n\n```kotlin\ngroup = \"com.my-company\"\nversion = \"1.0\"\n```"]]