Externalizing Dataweave Script — Why and How?

Sanket Kangle
3 min readApr 26, 2022
Photo by Nick Fewings on Unsplash

DataWeave is the MuleSoft expression language for accessing and transforming data that travels through a Mule app. Transform message component is the dedicated processor which converts input format to required output format using DataWeave language. DataWeave is tightly integrated with the Mule runtime engine, which runs the scripts and expressions in your Mule app. By default, the Transform message component has DataWeave script inline. We can externalize or move this transformation script to a separate dwl file and have XML reference it.

Why Externalize?

Following are the reasons for externalizing DataWeave script:

  • Reusability: By externalizing DataWeave script, the same script can be used at multiple places without code duplication.
  • Maintainability: By externalizing DataWeave script, its maintainability increases as a uniform structure is followed.
  • Best practice: It is the best practice recommended by mulesoft.

How to externalize?

  • Open your Transform message properties.
  • Click on the edit icon as shown in the image below.
  • Select “File” instead by default “inline”
  • Give an appropriate name with .dwl extension and click on “OK”
  • The file should be created under src/main/resources and can be seen in Package Explorer
  • To do that, just give a path while creating the file. An example is shown in the image below
  • It is good practice to externalize all dataweave scripts under one package in src/main/resources as shown in exhibit below. Make it a habit to do this while creating any project.
  • Following is how XML refers to this files


Give claps if you found this article useful. Stay tuned for upcoming articles.

All the images/exhibits are from the author unless given credit

Thanks for reading the article! Wanna connect with me?
Here is a link to my Linkedin Profile