今天为了学习 怎样使用 Groovy 写 Groovy 的測试代码, 所以到 http://groovy.codehaus.org/Download 下载了 Groovy 2.3.8 的源码包.
Groovy 是採用 Gradle 作为 构建工具的. 先看我本地的 Gradle 的相关环境:
>gradle -v ------------------------------------------------------------ Gradle 2.2 ------------------------------------------------------------ Build time: 2014-11-10 13:31:44 UTC Build number: none Revision: aab8521f1fd9a3484cac18123a72bcfdeb7006ec Groovy: 2.3.6 Ant: Apache Ant(TM) version 1.9.3 compiled on December 23 2013 JVM: 1.8.0_25 (Oracle Corporation 25.25-b02) OS: Windows 7 6.1 amd64
然后我在加压缩之后的源代码根文件夹下输入 gradle tasks ,
gradle 開始从 jcenter 下载须要的 jar 包,
然后開始编译,
最后出现这个错误:
Detected development environment Deployment environment set to Bintray FAILURE: Build failed with an exception. * Where: Script 'H:\TDDownload\groovy-src-2.3.8\groovy-2.3.8\gradle\pomconfigurer.gradle' line: 10 * What went wrong: A problem occurred evaluating script. > Could not find property 'groovy' on configuration container. * Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. BUILD FAILED Total time: 5 mins 7.403 secs
我接着用 gradle tasks --info 命令再跑一遍, 还是出现以下的错误:
Detected development environment Deployment environment set to Bintray FAILURE: Build failed with an exception. * Where: Script 'H:\TDDownload\groovy-src-2.3.8\groovy-2.3.8\gradle\pomconfigurer.gradle' line: 10 * What went wrong: A problem occurred evaluating script. > Could not find property 'groovy' on configuration container. * Try: Run with --stacktrace option to get the stack trace. Run with --debug option to get more log output. BUILD FAILED Total time: 7.911 secs Stopped 0 compiler daemon(s). Received result DaemonCommandResult[type=CommandFailure, value=org.gradle.launcher.exec.ReportedException: org.gradle.internal.exceptions.LocationAwareException : Script 'H:\TDDownload\groovy-src-2.3.8\groovy-2.3.8\gradle\pomconfigurer.gradle' line: 10 A problem occurred evaluating script.] from daemon DaemonInfo{pid=7252, address=[65f71eaa-6377-4a8a-9370-d90fced0f265 port:50883, addresses:[/127.0.0.1, /0:0:0: 0:0:0:0:1]], idle=false, context=DefaultDaemonContext[uid=581b3403-93ac-4a93-bcd9-d5374bbb9a86,javaHome=H:\ProgramFiles\Java\jdk1.8.0_25,daemonRegistryDir=C:\Us ers\chenjo\.gradle\daemon,pid=7252,idleTimeout=120000,daemonOpts=-XX:MaxPermSize=196m,-XX:+CMSClassUnloadingEnabled,-XX:+CMSPermGenSweepingEnabled,-Xmx640m,-Dfi le.encoding=GBK,-Duser.country=CN,-Duser.language=zh,-Duser.variant]}.
如何绕过这个错误呢? 难道是我的 Gradle 的版本号问题?
于是我打开文件 H:\TDDownload\groovy-src-2.3.8\groovy-2.3.8\README.adoc ,
发现里面说到:
To build everything using Gradle (the command below will download Gradle automatically, you do not need to download it first). ./gradlew clean dist
于是我就打开 命令行 窗体 到 源代码文件夹下, 键入: gradlew clean dist
我发现这个命令会首先下载一个 gradle-1.12 -all 到本地
C:\Users\chenjo\.gradle\wrapper\dists\gradle-1.12-all
然后加压缩, 然后在以该版本号下载 jar 包 以及进行 编译, 汇总.... 尽管中间有一些警告, 或是下载 jar 包时网络受阻, 我就中断命令又一次运行几次, 最后 build 成功.
Applying Javadoc fix tool (see http://www.kb.cert.org/vuls/id/225657) into H:\TDDownload\groovy-src-2.3.8\groovy-2.3.8\target\alljavadoc :doc :distDoc :distSrc :groovydoc :javadoc Applying Javadoc fix tool (see http://www.kb.cert.org/vuls/id/225657) into H:\TDDownload\groovy-src-2.3.8\groovy-2.3.8\target\docs\javadoc :syncDoc :dist BUILD SUCCESSFUL Total time: 18 mins 2.66 secs
然后我看到 生成的 target 目录 竟然有 500 多 M 字节.
在 项目文件夹\target\distributions\ 下, 有例如以下生成的公布文件:
groovy-binary-2.3.8.zip
groovy-docs-2.3.8.zip
groovy-sdk-2.3.8.zip
groovy-src-2.3.8.zip