設定發布項目的測試韌體
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
發布測試韌體時不需要任何特定設定
出版品
運作機制
用於處理韌體的程式碼需要額外設定。
假如指定成果的座標為 groupId:artifactId:version
,Gradle 預期測試韌體成果會宣告座標為 groupId:artifactId-test-fixtures:version
的功能。目前測試韌體支援功能或 Maven Publish Plugin 不會自動完成這項設定,因此您必須手動設定。
Gradle 會根據專案的名稱、群組和版本建立功能。這三個項目的設定都必須與發布項目的 artifactId
、groupId
和 version
值相符。
專案名稱預設為專案路徑的最後一個部分,因此預設值為
路徑為 :path:to:mylibrary
的專案名稱為 mylibrary
。如果您不想為 artifactId
使用這個名稱,請務必變更專案名稱。
您可以透過以下兩種做法重新命名專案:
- 重新命名專案所屬的資料夾。這會變更專案名稱
專案的 Gradle 路徑,因此專案的所有依附元件都需要
已更新。雖然維持專案名稱和資料夾名稱相同,但這樣做可能會產生
剛開始必須完成更多工作,這樣可以減少混淆。
- 在 Gradle 中重新命名專案,不為專案的資料夾重新命名。這可以避免對來源版本管理造成影響,但會導致專案的位置和名稱不一致。
如要在 Gradle 中重新命名專案,請在 settings.gradle
檔案中插入下列程式碼:
Groovy
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
值預設為未指定如要變更
或是群組 ID 或版本的值,請設定 group
和 version
屬性。
分別位於專案層級的 build.gradle
檔案 (適用於 Groovy),或
build.gradle.kts
(適用於 Kotlin 指令碼):
Groovy
group = 'com.my-company'
version = '1.0'
Kotlin
group = "com.my-company"
version = "1.0"
這個頁面中的內容和程式碼範例均受《內容授權》中的授權所規範。Java 與 OpenJDK 是 Oracle 和/或其關係企業的商標或註冊商標。
上次更新時間:2025-07-27 (世界標準時間)。
[[["容易理解","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 (世界標準時間)。"],[],[],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```"]]