提供没有战争插件的编译 [英] providedCompile without war plugin
问题描述
我想为许多项目重用某些过滤器,因此我想提取它并使用一个jar将其添加到任何Web应用程序。
我使用Gradle 1.3和以下 build.gradle
文件:
apply插件:'java'
依赖关系{
编译组:'org.slf4j',名称:'slf4j-api',版本:'1.7。+'
testcompile组:'junit',name:'junit',版本:'4. +'
编译组:'org.springframework',名称:'spring-web',版本:'3. +'
编译组:'org.slf4j',名称:'slf4j-log4j12',版本:'1.6。+'
编译组:'log4j', name:'log4j',version:'1.2。+'
providesCompile group:'javax.servlet',name:'javax.servlet-api',version:'3. +'
}
存储库{
mavenCentral()
}
正如你所看到的,我需要servlet api成功编译这个过滤器,所以我想添加它像一个Maven提供的依赖项。
无论如何,在运行 gradle build
之后,出现以下错误:
无法在根上为参数
[{group = javax.servlet,name = javax.servlet-api,version = 3。+}]找到方法provideCompile
project'hibernate-conversation-context'。
现在,我知道我不能在没有WAR插件的情况下使用providedCompile,但我需要该项目成为一个简单的JAR。有没有另外一种方法来做到这一点?
java 插件。但是您可以自己创建它,如下所示:
配置{providedcompile}
依赖关系{
providesCompilejavax.servlet:javax.servlet-api:3. +
sourceSets.main.compileClasspath + = configurations.providedcompile
sourceSets.test.compileClasspath + = configurations.providedcompile
sourceSets.test.runtimeClasspath + = configurations.providedcompile
这增加了配置,并将所有依赖关系放在您的主类和测试类的编译类路径中。您还需要将它添加到runtimeClasspath中,因为根据gradle DSL文档,它不包括编译类路径。
I want to reuse certain filter for many projects so I want to extract it and use a single jar to just add it to any Web App.
For building I am using Gradle 1.3 and the following build.gradle
file:
apply plugin: 'java'
dependencies {
compile group:'org.slf4j', name:'slf4j-api', version:'1.7.+'
testCompile group:'junit', name:'junit', version:'4.+'
compile group:'org.springframework', name:'spring-web', version:'3.+'
compile group:'org.slf4j', name:'slf4j-log4j12', version:'1.6.+'
compile group:'log4j', name:'log4j', version:'1.2.+'
providedCompile group: 'javax.servlet', name: 'javax.servlet-api', version:'3.+'
}
repositories {
mavenCentral()
}
As you can see, I need the servlet api to compile this filter succesfully so I want to add it like a maven provided dependency.
Anyways, after running gradle build
I get the following error:
Could not find method providedCompile() for arguments [{group=javax.servlet, name=javax.servlet-api, version=3.+}] on root project 'hibernate-conversation-context'.
Now, I know that I cannot use providedCompile without the WAR plugin but I need the project to be a simple JAR. Is there another way to do this?
There is no such configuration out of the box for the java
plugin. However you can build it yourself as follows:
configurations { providedCompile }
dependencies {
providedCompile "javax.servlet:javax.servlet-api:3.+"
}
sourceSets.main.compileClasspath += configurations.providedCompile
sourceSets.test.compileClasspath += configurations.providedCompile
sourceSets.test.runtimeClasspath += configurations.providedCompile
This adds the configuration, and puts all the dependencies in there on the compile classpaths of both your main classes and test classes. You also need to add it to the runtimeClasspath, as that doesn't include the compile classpath according to the gradle DSL documentation.
这篇关于提供没有战争插件的编译的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!