Gradle compile and providedCompile Example

By Arvind Rai, 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'
Compile configuration will add abobe jar its tarsitive dependency with the version provided. If we are using only JAR plugin, then the JAR and its transitive dependency JAR will be available at compile time and if we are using WAR plugin, then those JAR will also be added in WAR file.

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'
The above JAR and its transitive dependency will only be available at compile time but it will not be available at runtime. It means, those JAR will not be included in archive.

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'
POSTED BY
ARVIND RAI
ARVIND RAI
LEARN MORE








©2024 concretepage.com | Privacy Policy | Contact Us