DataWeave doesn’t provide a module or package keyword to group files. Until 2.12.0, every .dwl file lived in one global namespace. To make internal meaningful, the language now uses the component concept, which is a named set of DataWeave resources (modules) that are compiled and packaged together.
A component is described by a component descriptor, a .dwl resource located at META-INF/dw-components.dwl inside a .jar file. The descriptor is an array of components, and each component lists the resources it owns:
%dw 2.0
---
[
{
name: "wlang",
resources: {
"dw::Core": {},
"dw::Crypto": {},
"dw::core::Arrays": {},
"dw::core::Strings": {}
// ...
}
}
]
When the compiler resolves a reference to a symbol declared in another module, it consults the descriptors on the classpath to determine the components that own the declaring module and the caller module.
Generating the Descriptor
-
For a production build (data-weave:package), the plugin scans src/main/dw, derives the resource names of every .dwl file, and writes target/generated-dataweave-metadata/dw-components.dwl. The file is added to the produced JAR at META-INF/dw-components.dwl.
-
For a test build (data-weave:test), the plugin scans both src/main/dw and src/test/dw, so test files belong to the same component as the production sources they exercise. This lets tests call internal directives without further configuration.
The component name defaults to the Maven artifactId of the project.
Component Resolution Algorithm
Given a reference from caller A to symbol s declared in module B, the compiler looks up componentOf(B) from the descriptors on the classpath. Access is allowed based on the visibility of s:
-
If s is private, access is allowed only when A == B.
-
If s is internal, access is allowed when componentOf(A) == componentOf(B), or when componentOf(A) appears in the @VisibleTo list on s.
-
If s is public, access is always allowed.
If a module declares internal directives and no descriptor on the classpath claims it, the compiler emits the Module 'X' declares 'internal' members but has no component descriptor error. In that case, package the module with the Maven plugin for DataWeave or add a component descriptor that lists it.