Release Engineers are inevitable part in software engineering field, who is concerned with compilation, wrapping up or assembly and delivery (deployment) of the source code. These days bigger projects are using Gradle as the build tool since it makes the release of the code much faster and hassle-free. Gradleware is the Enterprise Automation Company supporting Gradle doing a great job in keeping Gradle open source, community developed and they are giving high-quality training in build and automation using Gradle.

In this post, I am sharing few Gradle tips and tricks which are going to be useful for build engineers. You might be aware of most of these tips, but I think it will be useful for newbies.

Gradle tip #1

How to add a line in MANIFEST.MF inside the war/jar which is created.

MANIFEST.MF is generally found in META-INF directory of jar/war that you’ve created which is used to define extensions and package related data. If you want to specify anything in MANIFEST.MF file, you should do it explicitly as Gradle will not take the file in the project automatically to the war/jar. For example, if you want to add a dependency,

     manifest {
         attributes("Manifest-Version" : "1.0", "dependencies" : "org.infinispan export")


Specify the above code inside build.gradle after applying the war plugin(If you are generating a jar, specify ‘jar.doFirst’ instead ). The output will be a MANIFEST.MF with the following lines:

Manifest-Version : 1.0
dependencies : org.infinispan export


Gradle Tip#2

Include extra source directory

The below image shows the project layout that Gradle assumes. It is not mandatory that these directories should exist. If the directory is found, java plugin will compile the files in it.

Also Read:  Best chargers for AA &AAA batteries(2 In 1) in Amazon



The java plugin introduces the concepts of a source set. It is a group of source files which are compiled and executed together. If you have an extra resource directory in your project such as “src/main/examples” it will not be included in your generated war/jar. There is a simple way to include it.

sourceSets.main.resources.scrDir 'src/main/examples'

Make sure that the above code is in your build.gradle file.

Gradle Tip#3

Exclude jars from ear/war

Sometimes you might be noticed that the generated ear/war contains jars which you don’t even specify as a dependency. This is because when you download dependencies from a maven repository online, it will automatically include all the dependent jar files with the required jar. To exclude these jars from the archive,

war {

Insert the above code to build.gradle. If you want to exclude all jars, replace “name_of_the_jar_you_want_to_exclude.jar” with “*.jar”.

Gradle Tip#4

Include dependencies from an independent directory

It is possible to include dependencies from a directory inside your project so that Gradle will find all the files (or selected ones) and include as a dependency for the project.

compile fileTree("../Root/SubProject/EarContent/lib",includes: ['*.jar'])


The above code will include all the jar files from the specified directory as a dependency.

Gradle Tip#5

Install a jar to your Local Maven Repository

Generally all the jar dependencies should be avaialable in the Maven Repository. In case if you do not found the jar in maven repo (Like oracle jdbc driver ojdbc6.jar), you can manually install it your local repo and use it. Gradle can help you with this.

apply plugin: 'maven'
group = 'com.googlecode.gwtgl'
version = '0.9.1'
artifacts {
       archives(file('gwtgl-0.9.1.jar')) {
            name 'gwtgl'
        archives(file('gwtgl-0.9.1-sources.jar')) {
            name 'gwtgl'
            classifier 'sources'
uploadArchives {
               repositories {
                             mavenDeployer {
                                     repository url: 'file://' + new File(System.getProperty('user.home'),'.m2/repository').absolutePath
task install(dependsOn: uploadArchives)


Also Read:  How to Use Google Maps 7.0 Offline

The above code assumes both the files gwtgl-0.9.1-sources.jar and gwtgl-0.9.1.jar is in the same directory as the build.gradle.

Share this article:

Leave a Reply

Your email address will not be published. Required fields are marked *