Oracle ADF and Gradle integration – part#1: Assembling ADF project using OJDeploy

Oracle ADF and Gradle integration – part#1: Assembling ADF project using OJDeploy

Gradle is a very powerful build automation system which allows you to build near everything – starting from Java through .NET ending up C++ projects. In this post I’ll show you basic ADF-Gradle integration that is a good starting point for further extensions like libraries dependency management or integration with Jenkins.

After this tutorial you should be able to integrate any ADF project with Gradle.  In next tutorials I’ll show you how to use Gradle to manage ADF library dependencies.

Overview:

  • Before we start
    • Sample application
    • Gradle – what you should know
      • Installation
      • Initializing Gradle project
      • Running tasks
  • Gradle – integration with ADF project
    • Prepare ojdeploy-buildfile.xml file
    • Create custom Gradle tasks
    • Tasks implementation
      • Task: checkAdfEnvironment
      • Task: clean
      • Task: assemble
    • Collecting all together – Test
  • What’s next?

 


Before we start

Sample application

For the purposes of this tutorial I’ll use an application from my previous post, where I showed you how to create simple ADF application which use Oracle Database Express Edition 11g installed in Docker container. You can do it yourself by watching the video start from 5:55 or you can download sample application.

The zip archive contains ADF workspace and gradle-wrapper.

 

Gradle – what you should know

Gradle is a very similar tool to Maven and Ant. In my opinion it combines the best features of both build tools. I hope you will see it too.

Gradle project contains build.gradle file which is the equivalent of Maven pom.xml file.

Installation

You have several ways to run Gralde project tasks:

  • You can download and install Gradle tool in your OS.
  • You can install it via package manager i.e.
  • You can use an IDE like IntelliJ IDEA which supports Gradle.
  • You can use Gradle Wrapper. It’ll download necessary Gradle distribution during the first use.

Initializing Gradle project

For initialize Gradle project go to your project directory and run one of the commands listed below:

Running tasks

Go to the project the Gradle project directory and run:

 


Gradle – integration with ADF project

Download sample ADF application, unzip it and go to the ADF workspace directory.

 

Create adf-gradle directory and initialize Gradle project inside. If you don’t have Gradle installed, you can copy files from  gradle-wrapper into the  ADFGradle/adf-gradle directory.

After all create both build.gradle and  ojdeploy-buildfile.xml files in ADFGradle/adf-gradle directory

Our workspace should look like below.

Prepare ojdeploy-buildfile.xml file

Put the following content into ojdeploy-buildfile.xml file. If you want to know more about the file just write me a message in comments at the bottom.

 

Create custom Gradle tasks

Edit build.gradle file and specify project group and version . Define two tasks as below:

  • clean – this is equivalent of mvn clean task
  • assemble – this is equivalent of mvn package task

Pay attention to tasks properties (group, description, dependsOn, mustRunAfter) and doLast section. At this moment let’s mock doLast sections by printing appropriate messages. We will finish them later.

Run gradlew tasks command to display available tasks.

As you can see  Oracle-adf task group appeared after standard Gradle tasks.

Let’s test assemble task. Run gradlew assemble command.

As you can see both clean and assemble tasks fired in proper order.

 

Tasks implementation

Edit build.gradle file and define project external properties as below:

  • middlewareHome – this property will be passed from command line using -PmiddlewareHome=<MIDDLEWARE_HOME>
  • ojDeployExec – path to ojdeploy tool (linux version)
  • adfWorkspace – realitive path to your ADF workspace – in our case it’s parent directory.
  • adfWorkspaceDeployDir – relative path to ADF deploy directory. This is directory configured in application deployment profile as a target for EAR file.
  • gradleTargetDir – relative path to directory for final artefacts.
  • ojDeployBuildfile – relative path to  ojdeploy-buildfile.xml you’ve already prepared.
  • ojDeployAppWorkspaceDir – absolute path to adfWorkspace.

 

Task: checkAdfEnvironment

Add another task  checkAdfEnvironment responsible for checking if all environment variables, project external properties and other stuff are configured properly. The task will be called before both clean and assemble tasks. GradleException is thrown when  middlewareHome project property is not specified.

 

Task: clean

At first define order and dependency to  checkAdfEnvironment task and then finish doLast section body to delete both  adfWorkspaceDeployDir and  adfWorkspaceDeployDir directories.

 

Task: assemble

As in previous task, define order and dependency to  checkAdfEnvironment task.

In doLast section call exec task like below.

 

Collecting all together – Test

The final build.gradle file should now look like below.

 

Lets run assemble task. Remember to pass path to MIDDLEWARE_HOME as a middlewareHome project property.

 

Everything went perfect!

Here you can download final application.

 


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!

 

8
Leave a Reply

avatar
6 Comment threads
2 Thread replies
0 Followers
 
Most reacted comment
Hottest comment thread
3 Comment authors
Oracle ADF and Gradle integration – part#2: SonarQube – Better-Codinglukasz.cieslaPriyaOracle ADF and Gradle integration – part#3: Dependency Management – Better-CodingAhmad Abutalib Recent comment authors
  Subscribe  
newest oldest most voted
Notify of
trackback

[…] ADF and Gradle integration – part#1: Assembling ADF project using OJDeploy […]

Ahmad Abutalib
Guest
Ahmad Abutalib

For windows you must use: ojdeploy64.exe

Ahmad Abutalib
Guest
Ahmad Abutalib

Jenkins integration should be next

trackback

[…] Oracle ADF and Gradle integration – part#1: Assembling ADF project using OJDeploy […]

Priya
Guest
Priya

Hi,
Which Jdev version does this support. Can build an ADF application developed in jdev 11.1.1.7 ?

Regards,
Priya

trackback

[…] You can use your own application or just download sample application. If you use your own application remember to integrate it with Gradle  as I showed you in this post. […]

Close Menu