Groovy Libraries allow custom Groovy functions and helpers to be shared and reused across all Groovy scripts in FlexDeploy
Table of Contents | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
...
Code Block | ||
---|---|---|
| ||
// imports omitted for brevity // create a new instance of our custom library // the LOG variable should be passed in the constructor for any imported custom library instance def logger = new com.flexagon.groovy.custom.LIB_LOGGER(LOG) void myPipelineFunction() { logger.logMessage("Logger library import") // code omitted for brevity } |
Circular Imports
Warning |
---|
Circular imports of custom libraries are not allowed and if found an error will be thrown |
The below example demonstrates a circular library import and why its a problem:
...
FlexDeploy will iterate through all your Groovy Libraries and create instances of each
A new instance of
LIB_ONE
is created.During initialization of
LIB_ONE
it will create a new instance ofLIB_TWO
as declared on line 1 ofLIB_ONE
An instance of
LIB_TWO
is created during step 3. This in turn creates an instance ofLIB_ONE
as declared on line 1 ofLIB_TWO
.We are now stuck in a loop between steps 3 and 4, infinitely creating new instances. This is what is known as a circular dependency and will result in an error being thrown.
Tip | ||||
---|---|---|---|---|
If it is absolutely necessary to have a circular dependency between libraries then the creation of library instances should be done within a function scope.
|