Code Library Overview
What are Code Libraries?
Code Libraries are reusable Groovy classes that provide shared functionality across multiple services within Journey Manager (JM). Unlike traditional Groovy services that include files using fileIncludes, Code Libraries are first-class service definitions that can be instantiated, passed by reference between services, and support full object-oriented programming features including inheritance, interfaces, and polymorphism.
Think of Code Libraries as building blocks for your JM solutions that you build to encapsulate common logic, data models, and utilities that can be shared across forms, services, and workflows without code duplication.
Key Benefits
- Reusability - Write once, use across multiple services and solutions
- Maintainability - Update shared logic in one place, propagate changes everywhere
- Type Safety - Full Groovy type checking support to catch errors at compile time
- Version Control - Isolate different versions of libraries for different solutions
- Pass by Reference - Objects maintain state across service invocations without serialization
- Object-Oriented - Full support for inheritance, interfaces, composition, and polymorphism
Why use Code Libraries?
The problem they solve
Before Code Libraries, sharing classes between services required:
- Using
fileIncludesto duplicate class definitions across services. - Manual serialization/deserialization when passing objects between services.
- Updating multiple service definitions when a shared class changed.
- No true object-oriented programming with inheritance and interfaces.
The solution
Code Libraries eliminate these pain points by:
- Eliminating Duplication: Define a class once as a Code Library, use it everywhere
- Passing Objects by Reference: Share live objects between services without serialization—changes to an object in one service are immediately visible to others
- Enabling True OOP: Create inheritance hierarchies, implement interfaces, and compose complex objects
- Centralized Updates: Modify a Code Library once, all dependent services automatically use the updated version
- Version Isolation: Run multiple versions of the same library simultaneously for different solutions
Common use cases
- Data Models - Define
Customer,Application,Addressclasses shared across services - Business Logic - Encapsulate validation rules, calculations, or workflows
- Utility Functions - Common operations like date formatting, string manipulation, API helpers
- Integration Adapters - Reusable classes for connecting to external systems
- Framework Components - Build internal frameworks for consistent solution development
Supported constructs
Currently, Code Libraries support the following reference types in Java:
- Class types →
class - Interface types →
interface - Enumeration types →
enum
How Code Libraries work
Object-oriented programming support
Code Libraries support full object-oriented programming in Groovy. The services shown in the diagram illustrate how inheritance works:

The IVehicle interface serves as a blueprint that defines what every vehicle should include, such as the numWheels property and a getType() method, without providing any actual implementation. The Car class implements this interface, giving a concrete definition by returning 'Car' in the getType() method. The Hybrid class then extends Car, inheriting its behavior while overriding getType() to return 'Hybrid', showing how inheritance and polymorphism allow classes to build upon and customize existing functionality.
With Code Libraries, you can use:
- Interfaces to define contracts
- Inheritance to extend base classes
- Composition to build complex objects from simpler ones
- Polymorphism to write flexible, extensible code
Passing by reference
Code Libraries provides a straightforward approach to passing objects by reference between services. The logic flow doesn't need to go through a central invoker. Instead, a Code Library instance can be passed directly from one service to another.

This diagram shows how Code Libraries contain shared logic that multiple services can call without duplicating code. Each Groovy service can directly access one or more libraries to perform specific tasks, while libraries themselves can also call other libraries. As a result, functionality can flow between services and libraries without needing to pass everything through a central invoker.
Code Library types
There are two primary types of Code Libraries, each suited for different scenarios:
| Type | Centralized Code Libraries | Solution-Specific Code Libraries |
|---|---|---|
| Purpose | Shared across multiple solutions and organizations | Packaged within a specific solution |
| Development | Developed in a dedicated SDK project | Developed within the Solution SDK project |
| Deployment | Generates .zip archive for deployment to JM | Deployed automatically with the solution |
| Maven Artifact | Optionally generates .jar artifact for use as Maven dependency | No separate Maven artifact needed |
| Hierarchy Level | Typically assigned to Global or Org level | Typically assigned to Org or Org/Tag level for isolation |
| Versioning | Versioned independently of solutions | Versioned with the solution |
| Best For | • Common utilities (date helpers, validation rules) • Enterprise-wide data models • Shared integration adapters • Internal framework components | • Solution-specific business logic • Data models unique to one application • Classes that won't be reused by other solutions |
| Learn More | Centralized Code Libraries | Solution Code Libraries |
Both approaches also work together. Use a Centralized Code Libraries for common functionality along with Solution-Specific libraries for application-unique logic. Additionally, solution projects can depend on Centralized libraries via Maven dependencies.