[英]How to import a class from a buildscript dependency in Gradle
我想在我的Gradle脚本中访问StringUtils方法。 因此,我在buildscript闭包中定义了它的MavenRepo。 添加导入语句后,我认为我可以使用该类。 但是错误告诉我否则。 我想念什么?
gradle.build
import org.apache.commons.lang.StringUtils
apply plugin: "java"
apply plugin: "application"
mainClassName = "com.xetra11.test.Main"
task execute(){
File file = new File("/log/file.txt")
StringUtils.touch("/log/file.txt")
}
buildscript {
repositories{
mavenCentral()
}
dependencies {
classpath group: 'org.apache.commons', name: 'commons-lang3', version: '3.0'
}
}
repositories{
mavenCentral()
}
dependencies{
compile group: 'org.apache.commons', name: 'commons-lang3', version: '3.0'
}
错误输出
~/Workspace/Development/Java/gradle_test/ gradle buildDependents
gradle buildDependents
FAILURE: Build failed with an exception.
* Where:
Build file '/home/xetra11/Workspace/Development/Java/gradle_test/build.gradle' line: 1
* What went wrong:
Could not compile build file '/home/xetra11/Workspace/Development/Java/gradle_test/build.gradle'.
> startup failed:
build file '/home/xetra11/Workspace/Development/Java/gradle_test/build.gradle': 1: unable to resolve class org.apache.commons.lang.StringUtils
@ line 1, column 1.
import org.apache.commons.lang.StringUtils
^
1 error
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
org.apache.commons.lang.StringUtils
(从其软件包中暗示)是commons-lang2.x。 commons-lang3
软件包名称已更改为org.apache.commons.lang3
。
因此,请使用org.apache.commons:commons-lang:2.6
作为依赖项,或将导入更改为org.apache.commons.lang3.StringUtils
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.