gpt4 book ai didi

gradle - gradle构建在类路径中不包含jar

转载 作者:行者123 更新时间:2023-12-03 05:18:31 26 4
gpt4 key购买 nike

大家

这是构建脚本

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'
}

jar 存在于本地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开关,但没有帮助。

最佳答案

如本杰明所说,您可能缺少依赖项声明。请注意,使用@jar会禁用传递依赖项解析。 @jar的意思是“我只想要这个Jar,而不想要它的POM中声明的任何依赖项”。

声明本地Maven存储库的首选方法是repositories { mavenLocal() }。除非您在本地Maven存储库中安装了其他版本,并且从该版本中拉出该版本,否则既不建议也没有必要声明mavenLocal()。如果它们的校验和匹配,Gradle足够聪明,可以自动从本地Maven存储库中窃取Jar(避免下载它们)。

您的configurations块可以完全删除。所有这些已经由java插件配置了。

关于gradle - gradle构建在类路径中不包含jar,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11445346/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com