Tôi hiện đang mô đun hóa bản dựng lớp của chúng tôi để có tệp libs/commons.gradle chứa nhiều nội dung toàn cầu. Tôi cần điều này vì các nhánh khác nhau của phần mềm được phát triển song song và chúng tôi muốn tránh lây lan mọi thay đổi scriptfile trong tất cả các nhánh.Gradle: làm cách nào tôi có thể gọi 'def' từ tập lệnh được nhập?
Vì vậy, tôi tạo ra mà tập tin lib và sử dụng "áp dụng từ" để tải nó:
áp dụng từ: 'gradle/trơn/commons.gradle'
Bên commons.gradle tôi xác định các chức năng svnrevision:
...
def svnRevision = {
ISVNOptions options = SVNWCUtil.createDefaultOptions(true);
SVNClientManager clientManager = SVNClientManager.newInstance(options);
SVNStatusClient statusClient = clientManager.getStatusClient();
SVNStatus status = statusClient.doStatus(projectDir, false);
SVNRevision revision = status.getCommittedRevision();
return revision.getNumber().toString();
}
...
tôi callin g hàm từ bao gồm build.gradle tôi:
...
task writeVersionProperties {
File f = new File(project.webAppDirName+'/WEB-INF/version.properties');
if (f.exists()) { f.delete(); }
f = new File(project.webAppDirName+'/WEB-INF/version.properties');
FileOutputStream os = new FileOutputStream(f);
os.write(("version="+svnRevision()).getBytes());
os.flush();
os.close();
}
...
Nhưng tôi kết thúc trong:
...
FAILURE: Build failed with an exception.
* Where:
Build $PATH_TO/build20.gradle
* What went wrong:
A problem occurred evaluating root project 'DEV_7.X.X_GRADLEZATION'.
> Could not find method svnRevision() for arguments [] on root project 'DEV_7.X.X_GRADLEZATION'.
...
Vì vậy, nhiệm vụ của tôi là: Làm cách nào tôi có thể gọi một hàm phụ ở chế độ gradle, được xác định trong tập lệnh được bao gồm?
Bất kỳ trợ giúp nào được đánh giá cao!
tính năng này phù hợp với tôi. cảm ơn rất nhiều! – gorefest