Oracle ADF and Gradle integration – part#3: Dependency Management

Oracle ADF and Gradle integration – part#3: Dependency Management

Library dependency management is one of  the most missing tools in Oracle JDeveloper 11g. It is true that Maven support has been added in JDeveloper 12c. Nevertheless, in the older projects you may want to use Gralde integration described in this article. This approach also works with JDeveloper 12c.


I. Overview

This tutorial is intended for both JDeveloper 11g and 12c. There is only one difference between them, which I will discuss when we get to it.

From the tutorial you will learn how to:

  • write custom Groovy/Java helper class and use it in Gradle script;
  • design custom dependency model using Gradle dependency management;
  • integrate Gradle dependency management with Oracle ADF application.


But before we start

If you have not read the following articles yet, I will recommend that you do so because it will be much easier to understand you the tutorial.


The Idea

Before the release of JDeveloper 12c, the standard way to add library to Oracle ADF application was by creating and attaching *.library  file into the project. The file contains entries pointed to jar files used in the project. Here is an example:


Let’s think what would happened if we could generate custom library file and attach it into project. It sounds good, doesn’t it? I will tell you more – it works as it should. Attaching a library file to the project is relatively easy so, most of the tutorial is about how to generate the right *.library file in the right place.

In this tutorial, we will create two library files for both the Model and ViewController projects. Files will be located in  adf-gradle/build/libraries/ADFGradle_model and adf-gradle/build/libraries/ADFGradle_vc directories. They will be generated based on previously downloaded jar files. Jars will be located in the same folders as library files and will be downloaded by newly created Gradle task. The task will use an utility class written in groovy.  This is what the idea from the end looks like.


Sample Application

For the purposes of the tutorial I prepared an exemplary application which you can download from here.  The application is compatible with JDeveloper but it is also possible to open it in JDeveloper 12c. It has already been integrated with Gradle as I explained it in this tutorial.


As you probably noticed,  the ViewController project contains class. The class imports external packages like com.fasterxml.jackson.core.type.TypeReference and it depends on jackson-databind library (which also depends on two other libraries:  jackson-core  and jackson-annotations). The project does not compile because of missing dependencies. Your goal is to make is to make it work.


II. Gradle Task: downloadDependencies

In this part of the tutorial you will see how to write a Gradle script which allows you to:

  • configure dependencies for both Model and ViewController projects;
  • download all previously configured libraries (with theirs dependencies) into the right directories;
  • create ADF Library files for both Model and ViewController projects;


Utility class: AdfGradleUtils.groovy

Although there is a possibility to write whole code directly in build.gradle file I decided to put it into separated groovy class. We can advantage the fact that every class placed in the  adf-gradle/buildSrc/src/main/groovy directory is automatically compiled and ready to use in build.gradle script. By the way, it is also possible to write Java class using the following location adf-gradle/buildSrc/src/main/java.

At  this moment we will prepare a mocked utility class adf-gradle/buildSrc/src/main/groovy/AdfGradleUtils.groovy  with the following content:


The class contains two methods. The first one is responsible for downloading all dependencies defined in configuration parameter. The second method is responsible for creating ADF library file based on previously downloaded libraries. The methods are not finished yet. We will finish it later.


Integration: build.gradle

Heaving a separate utility class makes the integration process much more clearer. At first we have to define repositories and both configurations for our application(for Model and ViewController projects). In this case we will use Central Maven Repository as default source of artifacts.


Then we have to define project properties which helps us to stick to canons:

  • librariesDir – property defines a target directory for libraries downloaded by downloadDependencies  task.
  • jdevVersion – property will be used to select the right ADF library file template( 11g or 12c).


The last thing that’s left is to define downloadDependencies  task and set it as dependency of assemble task.


The final result of build.gradle file you can see on the listing below.


Time for test

Run ./gradlew downloadDependencies and check if everything went OK.


Implementation: AdfGradleUtils.groovy

It is time to finish the AdfGradleUtils.groovy class, but before we do this we have to prepare some xml files with ADF library templates. It makes our code much clearer than without it.


ADF Library template

Prepare files like below. You can add one or both pairs of files. There is a small difference between them that you can see when comparing individual files.

For ADF 11g – you have to add template-library-11g.xml and  template-entry-11g.xml files with the following content:



For ADF 12c – you have to add  template-library-12c.xml and  template-entry-12c.xml files with the following content:



Finishing implementation

Edit AdfGradleUtils.groovy class and finish the  processDependencies method with the following code:


Let’s think for a moment what processDependencies method actually do. It prepares the right directory structure and copies all jars (with dependencies) into the directory. At The end the method calls generateAdfLibraryFile.

The  generateAdfLibraryFile  method is responsible for generating ADF Library file with entries pointed to previously downloaded jars. The idea of the method is very simple – just list all jar files from the directory and add it into library. The body of the  method may looks like below.


Below you can see the final version of  AdfGradleUtils.groovy class.


Time for test

Run ./gradlew downloadDependencies and check if everything went OK. A this moment both empty ADF libraries should be generated.


III. Configure ADF project

The last thing we have to do is to attach generated ADF library files into ADF Application. Run JDeveloper and open Project Properties menu. Then go to  Libraries and Classpath , click Add Library , click Load  and choose the directory with generated ADFGradle_vc  library. Then select the library.


Repeat above for Model project and try to rebuild the project. You should got a compilation error, because we have not defined any library yet.


To add the required libraries put the following lines to build.gradle  file:


and refresh dependencies by running ./gradlew downloadDependencies command.


The final test

Now it is time to rebuild your project again.


Everything went perfect! . You can download the final version of application from here.


What’s next?

Please leave me a comment what do you think about this tutorial and what do you want to read about in the next tutorial

If this tutorial was interesting to you can help me to reach a larger group of receivers by sharing this post.

Thank you!



Leave a Reply

Notify of
Close Menu