I have a project with 1 subproject:
projroot/
settings.gradle
build.gradle
mod1/
build.gradle
In mod1/build.gradle
there is a "provided" dependency:
apply plugin: 'java'
configurations {
provided
}
repositories {
mavenCentral()
}
dependencies {
provided group: 'javax.servlet', name: 'javax.servlet-api', version: '3.1.0'
}
This doesn't seem to work when mod1/src/main/java/One.java
imports javax.servlet.ServletContext
:
> Task :mod1:compileJava FAILED
/home/x/groot/mod1/src/main/java/One.java:1: error: package javax.servlet does not exist
import javax.servlet.ServletContext;
^
1 error
...
BUILD FAILED in 0s
2 actionable tasks: 1 executed, 1 up-to-date
Using gradle-4.4.1.
Am I defining the dependency in an incorrect place?
Since Gradle 2.12 introduced compileOnly
dependencies I rather recommend to use this. Especially when it comes to a Servlet API that will be provided by the servlet container once you deploy your web application on eg Tomcat, JBoss, ....
dependencies {
compileOnly group: 'javax.servlet', name: 'javax.servlet-api', version: '3.1.0'
}
provided
is a scope used in Maven project that haven't found place in Gradle so far. But compileOnly
is very close to Mavens provided
scope.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.