Định cấu hình môi trường kiểm thử cố định cho ấn phẩm
Sử dụng bộ sưu tập để sắp xếp ngăn nắp các trang
Lưu và phân loại nội dung dựa trên lựa chọn ưu tiên của bạn.
Mặc dù việc xuất bản môi trường thử nghiệm cố định không yêu cầu cấu hình cụ thể nào
cho ấn bản, phần
cơ chế chức năng
dùng để xử lý thiết bị cố định cần có cấu hình bổ sung.
Đối với cấu phần phần mềm cho trước có chỉ số phối trí groupId:artifactId:version
, Gradle kỳ vọng rằng cấu phần phần mềm của môi trường thử nghiệm cố định sẽ khai báo một chức năng có chỉ số phối trí groupId:artifactId-test-fixtures:version
. Hiện nay, tính năng hỗ trợ môi trường thử nghiệm cố định hay trình bổ trợ phát hành của Maven đều chưa thể tự động định cấu hình, nên bạn sẽ phải thực hiện theo cách thủ công.
Gradle sẽ tạo chức năng dựa trên tên, nhóm và phiên bản của dự án.
Cả ba đều phải được thiết lập sao cho khớp với artifactId
, groupId
và version
như trong ấn bản.
Theo mặc định, tên dự án là phân đoạn cuối cùng của đường dẫn dự án; do đó, tên mặc định của dự án có đường dẫn :path:to:mylibrary
là mylibrary
. Nếu đây không phải là tên bạn muốn dùng cho artifactId
, thì bạn phải thay đổi tên dự án.
Có 2 cách để đổi tên dự án:
- Đổi tên thư mục của dự án. Thao tác này sẽ đổi tên dự án hay tên đường dẫn Gradle của dự án, vậy nên mọi phần phụ thuộc trên dự án đều cần phải được cập nhật. Tuy việc giữ nguyên tên dự án và thư mục có thể khiến bạn tốn nhiều công sức tổ chức lại lúc ban đầu, nhưng điều này sẽ giúp giảm sự nhầm lẫn.
- Đổi tên dự án trong Gradle mà không cần đổi tên thư mục của dự án. Điều này
giúp tránh gây tác động lên việc phân chia phiên bản nguồn, nhưng lại làm chia tách vị trí
và tên dự án.
Để đổi tên dự án trong Gradle, hãy thêm đoạn mã sau vào
tệp 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"
Đoạn mã này chỉ định đường dẫn mới của dự án thành :path:to:my-library
.
Theo mặc định, giá trị groupId
sẽ lấy tên bản dựng (thường là tên của thư mục gốc), còn giá trị version
thì không xác định. Để thay đổi giá trị của phiên bản hoặc mã nhận dạng nhóm, hãy đặt các thuộc tính của group
và version
trong tệp build.gradle
ở cấp độ dự án (đối với Groovy) hoặc build.gradle.kts
(đối với tập lệnh Kotlin) tương ứng:
Groovy
group = 'com.my-company'
version = '1.0'
Kotlin
group = "com.my-company"
version = "1.0"
Nội dung và mã mẫu trên trang này phải tuân thủ các giấy phép như mô tả trong phần Giấy phép nội dung. Java và OpenJDK là nhãn hiệu hoặc nhãn hiệu đã đăng ký của Oracle và/hoặc đơn vị liên kết của Oracle.
Cập nhật lần gần đây nhất: 2025-07-27 UTC.
[[["Dễ hiểu","easyToUnderstand","thumb-up"],["Giúp tôi giải quyết được vấn đề","solvedMyProblem","thumb-up"],["Khác","otherUp","thumb-up"]],[["Thiếu thông tin tôi cần","missingTheInformationINeed","thumb-down"],["Quá phức tạp/quá nhiều bước","tooComplicatedTooManySteps","thumb-down"],["Đã lỗi thời","outOfDate","thumb-down"],["Vấn đề về bản dịch","translationIssue","thumb-down"],["Vấn đề về mẫu/mã","samplesCodeIssue","thumb-down"],["Khác","otherDown","thumb-down"]],["Cập nhật lần gần đây nhất: 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```"]]