配置测试固件以供发布
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
虽然发布测试固件不需要任何特定配置
的
功能机制
处理夹具时,需要进行额外配置。
对于坐标为 groupId:artifactId:version
的给定工件,Gradle 希望测试固件工件能够声明坐标为 groupId:artifactId-test-fixtures:version
的功能。测试固件支持功能或 Maven Publish 插件目前均无法自动完成上述设置,因此必须手动完成。
Gradle 会根据项目名称、群组和版本创建相应功能。这 3 个元素必须全部设为与发布内容中设置的 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
默认为 build 名称(通常是根文件夹的名称),而值 version
则默认为未指定。如需更改群组 ID 或版本的值,请在项目级 build.gradle
文件(适用于 Groovy)或 build.gradle.kts
(适用于 Kotlin 脚本)中分别设置 group
和 version
属性:
Groovy
group = 'com.my-company'
version = '1.0'
Kotlin
group = "com.my-company"
version = "1.0"
本页面上的内容和代码示例受内容许可部分所述许可的限制。Java 和 OpenJDK 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-07-27。
[null,null,["最后更新时间 (UTC):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```"]]