我正在尝试编译几个WAR文件,所有这些都取决于一个常见的JAR模块.然而,在我的Gradle构建中,我似乎无法获得使用Java插件的"提供"之类的依赖项.
我的编译看起来像这样:
apply plugin: 'java'
configurations{
providedCompile
}
dependencies {
compile module("org.springframework.amqp:spring-amqp:${springAmqpVersion}")
compile module("org.slf4j:slf4j-api:${slf4jVersion}")
compile module("org.slf4j:slf4j-ext:${slf4jVersion}")
providedCompile "javax.servlet:servlet-api:${servletApiVersion}"
runtime module("org.slf4j:jcl-over-slf4j:${slf4jVersion}")
runtime module("org.slf4j:jul-to-slf4j:${slf4jVersion}")
runtime module("org.slf4j:log4j-over-slf4j:${slf4jVersion}")
sourceArchives module("org.springframework.amqp:spring-amqp:${springAmqpVersion}:sources")
sourceArchives module("javax.servlet:servlet-api:${servletApiVersion}:sources")
}
sourceSets {
main { compileClasspath += configurations.providedCompile }
}
Run Code Online (Sandbox Code Playgroud)
但是,最后一位是它获得异常的地方.我已经尝试在运行时依赖项扩展它之后将servlet-api(由Tomcat提供)添加到配置中,或者只是将其作为编译模块放入,然后将其从运行时依赖项中删除.
我尝试了几种不同的修改依赖关系的方法,最接近的结果是:
newRuntime = configurations.runtime.minus(configurations.providedCompile)
configurations.runtime = newRuntime
Run Code Online (Sandbox Code Playgroud)
然而,最后一点将生成具有适当依赖关系的变量newRuntime,但是当我尝试将变量重新分配回运行时配置时,它会抛出"找不到属性异常"
我在Gradle的错误跟踪上发现了很多关于这个确切问题的讨论:Gradle-784
然而,主要的导致是来自Spring,他使用Maven和他们的gradle构建,我不熟悉.
我在SO上找到的最有希望的链接,但不幸的是我无法让这些例子也能正常工作:SO提供 了Stack Overflow问题的注意事项:显示最有希望的一行:
//Include provided for compilation
sourceSets.main.compileClasspath += configurations.provided
Run Code Online (Sandbox Code Playgroud)
此行不会像其他尝试一样给出错误,但似乎提供的Compile(我提供的版本)依赖项实际上并未放在编译类路径上,因为尝试编译时会出现类路径错误.
我不是100%关注你的消息,但提供的编译仅允许'war'插件.
apply plugin: 'war'
dependencies {
// others go here
providedCompile "javax.servlet:javax.servlet-api:${servletVersion}"
}
Run Code Online (Sandbox Code Playgroud)
在"war"步骤中,不包括servlet jar.
您已添加providedCompile
配置,但您没有对其执行任何操作.因此它不会在任何类路径上.要将配置放在主编译类路径上,您可以执行以下操作:
sourceSets.main.compileClasspath += configurations.providedCompile
Run Code Online (Sandbox Code Playgroud)
同样,将它放在测试编译类路径上:
sourceSets.test.compileClasspath += configurations.providedCompile
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
16634 次 |
最近记录: |