我目前模块化我们的gradle构建,以便有一个包含许多全局内容的libs/commons.gradle文件.我需要这个,因为并行开发的软件的各个分支,我们希望避免在所有分支之间传播每个脚本文件的变化.
所以我创建了lib文件并使用"apply from"来加载它:
申请自:'gradle/glib/commons.gradle'
在commons.gradle里面我定义了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(); }
...
我正在调用包含build.gradle的函数:
...
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(); }
...
但我最终进入:
...
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'.
...
所以我的问题是:如何在gradle中调用子函数,这是在包含的脚本中定义的?
任何帮助赞赏!