Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
299 views
in Technique[技术] by (71.8m points)

gradle - providedCompile without war plugin

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?

question from:https://stackoverflow.com/questions/13925724/providedcompile-without-war-plugin

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...