Publish DataWeave Library To MuleSoft Anypoint Exchange

Author: Arif Ali Mansuri

In this blog, I will walk you through the process of publishing and implementing the DataWeave Library.

The important question is: Why do we need this?

DataWeave is the only functional programming language that the MuleSoft developer uses for the whole transformation process, making MuleSoft Integration impossible without it. Writing the same piece of code each time as a business requirement when common mapping across multiple layers of API-led connectivity is required is a waste of time and effort. If there is something that addresses this issue, they should keep the common mapping somewhere and provide it to us as needed.

Let’s start the process.

Prerequisites: 
  • Anypoint Platform.
  • Visual Studio code.
  • DataWeave 2.0 (BETA) Extension.
  • Anypoint Studio.
  • Organization ID – Get it through below simple steps.
  1. Login to Anypoint Platform. 
  2. Tap on Access Management.
  3. Click on Business Groups.  
  4. Click the name of your organization & go to Settings.
  5. Copy Business Group ID this act as Organization ID.
Just follow the below steps:

Step 1:

  • Open Visual Studio Code or Download Visual studio code. Link
  • Go to Extensions. 
  • Search for DataWeave & Installed. 

Step 2:

  • Next, go to view > Command Palette. 
  • Search for DataWeave: Create New Library Project. 
  • Create it by passing default configurations. 
  • Choose a project path.

Step 3:

Now create your desired DataWeave function. Here I am creating a demo function that returns the lowercase of the passed input string.

  • You can try the above-created function by using it in any mapping.
  • As a source code to build perfect UNIT tests, it is important that you can create test cases for unit testing too.

Step 4:

To deploy the above-created DataWeave Library, make the changes to pom.xml mentioned below.

  • Go to the Project path (refer to the last screenshot of Step 2).
  • Go to pom.xml and update groupId & enable the distribution management repository tag.
  • Add groupId.
  • Enable distributionManagement repository.
  • Now go to system/users/*/.m2 and update settings.xml
  • Add server in setting.xml for the same <id> as mentioned above <distributionManagement> and provide your Anypoint credentials

Step 5.

  • Run the below maven command to Publish. 

Now run the mvn deploy command to deploy it on Anypoint exchange.

  • DataWeave Library successfully deployed to Anypoint Exchange.
Now it’s time to utilize our deployed DataWeave Library.

Step 1:

  • Log In to Anypoint Platform.
  • Go to Exchange in root Organization and check on the dropdown for DataWeave Library(BETA).
  • Select deployed DataWeave library.
  • You can also see the function definition in Exchange.
  • Tap on Dependency Snippets > copy it.
<dependency>

  <groupId>*********************************************</groupId>

  <artifactId>custom-logics-arif</artifactId>

  <version>1.0.0</version>

  <classifier>dw-library</classifier>

</dependency>

Step 2:

  • Open any Mule Application in Anypoint Studio.
  • Paste copied Dependency in pom.xml dependencies.

Step 3:

Now open the drag Transform message from Mule Palette and import the created function by the below script.

  • Import demo form MyModule.

We use cookies on this site to enhance your user experience. For a complete overview of how we use cookies, please see our privacy policy.