Gradle compile and providedCompile Example
September 23, 2014
In this page we will see how to use gradle compile and providedCompile in our gradle script. compile configuration downloads the JAR dependency and its transitive dependency. All the JAR dependency will be collected in archive if using WAR plugin. providedCompile is also a configuration in gradle script, which enables any JAR and its transitive dependency not to go in WAR archive but be available at compile time. Find the Sample Example
apply plugin: 'java' apply plugin: 'eclipse' apply plugin: 'war' repositories { mavenCentral() } dependencies { compile 'org.springframework.boot:spring-boot-starter-websocket:1.1.6.RELEASE' providedCompile 'org.springframework.boot:spring-boot-starter-tomcat:1.1.6.RELEASE' }
Gradle compile
To get jar dependency at compile time and runtime we use compile in gradle. Jar plugin provides compile configuration. Find the cod snippet how to use compile in gradle script.compile 'org.springframework.boot:spring-boot-starter-websocket:1.1.6.RELEASE'
Gradle providedCompile
There are some cases when we do not want to archive some JAR in WAR file. To achieve this we use providedCompile . providedCompile is used as below.providedCompile 'org.springframework.boot:spring-boot-starter-tomcat:1.1.6.RELEASE'
If we do not want to exclude transitive dependency in archive , then we can do using @jar
providedCompile 'org.springframework.boot:spring-boot-starter-tomcat:1.1.6.RELEASE@jar'