Building Mule Apps with Gradle in Eclipse

Building Mule Apps with Gradle in Eclipse, i.e., you are going to create Mule project outside Mule Studio. We will build the Mule project in Eclipse using Gradle script. Gradle is becoming more and more popularity as a build system. It combines the power of scripting with the simplicity of conventions, where customization does not end up in tons of messy configurations. Over the times we have done building Mule apps through Mule Studio using Maven plugin. Here you will create build.gradle script with your own hand to build the Mule project in Eclipse.

Here we will use the Mule community repository as we have to setup user credentials(username/password) for accessing the Mule enterprise repository. By default Mule enterprise repository is turned on. So to make it off, please set mule.muleEnterprise to false. We will see all these things in our Gradle build script. We will also run command gradle initMuleProject to make the eclipse project structure as Mule project structure.

Let’s get started on building mule apps with gradle in eclipse.
Prerequisites
Knowledge of Mule, Gradle, Java
Softwares
Eclipse
JDK 8
Gradle 4.x

Please go through the following instructions to create and build the mule project in Eclipse.

Step 1. Please create Gradle based project called mule-gradle in Eclipse. Here I am using Eclipse Oxygen 2.

Step 2. Modify the build.gradle script with the below configurations in order to building mule apps with gradle. Here you may or may not use apply plugin: "java" depending on your project requirements. As I said initially that I am not using enterprise version of mule so I have not setup any enterprise credentials for mule repository.

buildscript {
	repositories {
		mavenLocal()
		maven {
			url 'https://repository-master.mulesoft.org/releases'
		}
	}
	dependencies {
		classpath "org.mulesoft.build:mule-gradle-plugin:1.2.2"
	}
}
apply plugin: 'java'
apply plugin: 'mule'
mule.version = '3.5.0'
mule.muleEnterprise = false

In the above build script I have set mule.muleEnterprise = false (by default true) in order to use community version of mule. If you want to use the enterprise repository then you need to setup your credentials. You can find more information on how to setup repository credentials in mulesoft website.

Step 3. Open cmd prompt and navigate to the project’s root directory and run the below command in order to building mule apps with gradle. You should see BUILD SUCCESSFUL after downloading the required jar libraries from the maven repositories. If you find this step is successful then only you will be able to run the next step for updating to mule project structure.

gradle build

Step 4. Now run below command to make the project structure as Mule project structure. In the command prompt you will see BUILD SUCCESSFUL, i.e., you project structure has been updated to mule project structure.

gradle initMuleProject
building mule apps with gradle

Step 5. Now refresh the project in Eclipse, you will see the project structure has been updated to mule project structure with additional directories like src/main/app as shown in below image. If you expand the directory src/main/app then you will find few files such as mule-app.properties, mule-config.xml and mule-deploy.properties have been created.

building mule apps with gradle

Congratulations! You have successfully done building Mule apps with Gradle in Eclipse.

Thanks for reading.

Leave a Reply

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