大家
这是构建脚本
apply{
plugin 'java'
}
sourceCompatibility=1.5
List spring = ["org.springframework:spring-webmvc:$springVersion@jar",
"org.springframework:spring-orm:$springVersion@jar",
"org.springframework:spring-context-support:$springVersion@jar"]
List spring_js = [ "org.springframework.webflow:spring-js:2.0.7.RELEASE@jar",
"org.apache.ibatis:com.springsource.com.ibatis:2.3.4.726@jar",
"com.caucho:com.springsource.com.caucho:3.2.1@jar",
"org.apache.axis:com.springsource.org.apache.axis:1.4.0@jar",
"javax.wsdl:com.springsource.javax.wsdl:1.6.1@jar"]
configurations {
compile {
description = 'compile classpath'
transitive = true
}
runtime {
extendsFrom compile
}
}
def localMavenRepo = 'file://' + new File(System.getProperty('user.home'), '.m2/repository').absolutePath
repositories{
mavenCentral()
maven{
url localMavenRepo
}
}
dependencies{
compile spring, spring_js, 'commons-fileupload:commons-fileupload:1.2.1','org.apache.struts:com.springsource.org.apache.struts:1.2.9',
'javax.xml.rpc:com.springsource.javax.xml.rpc:1.1.0','org.apache.commons:com.springsource.org.apache.commons.dbcp:1.2.2.osgi',
'commons-io:commons-io:1.3.2','hsqldb:hsqldb:1.8.0.7','org.apache.tiles:tiles-jsp:2.2.0','org.tuckey:urlrewritefilter:3.1.0',
'org.apache.tiles:tiles-core:2.2.0'
runtime 'javax.servlet:jstl:1.2','org.aspectj:aspectjweaver:1.6.5','javax.servlet:servlet-api:2.5','javax.servlet.jsp:jsp-api:2.1'
testCompile 'junit:junit:4.6'
}
罐子存在于本地maven仓库中,但是当我运行gradle --info clean build时,构建失败并出现错误,例如
/home/anadi/Code/gradle-samples/java-proj/gradleSpringJpetStore/src/main/java/org/springframework/samples/jpetstore/web/spring/SignonInterceptor.java:17: cannot find symbol
symbol : class HttpServletResponse
location: class org.springframework.samples.jpetstore.web.spring.SignonInterceptor
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
^
/home/anadi/Code/gradle-samples/java-proj/gradleSpringJpetStore/src/main/java/org/springframework/samples/jpetstore/web/spring/RemoveItemFromCartController.java:9: package org.springframework.web.util does not exist
import org.springframework.web.util.WebUtils;
^
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':compileJava'.
> Compilation failed; see the compiler error output for details.
* Try:
Run with --stacktrace option to get the stack trace. Run with --debug option to get more log output.
BUILD FAILED
Total time: 4.969 secs
如果我使用maven运行相同的构建,它会从本地存储库中获取所有依赖项并成功编译。我也尝试过--refresh-dependencies开关,但没有帮助。
答案 0 :(得分:1)
正如本杰明所说,你可能错过了依赖声明。请注意,使用@jar
会禁用传递依赖项解析。 @jar
表示“我只想要这个Jar,而不是其POM中声明的任何依赖项”。
声明本地Maven仓库的首选方式是repositories { mavenLocal() }
。除非你有一些其他构建安装到本地Maven存储库并且这个构建从中提取,否则既不建议也不必声明mavenLocal()
。如果他们的校验和匹配,Gradle足够聪明,可以自动从当地Maven仓库窃取Jars(以避免下载)。
您的configurations
块可以完全删除。所有这些都已由java
插件配置。