cds:generate
Full name:
com.sap.cds:cds-maven-plugin:3.4.0:generate
Description:
Generates Java POJOs for type-safe access to the CDS model.
This goal scans the resource directory for a csn.json file and uses it for Java source code generation. It also adds the code output directory to the project's source code directories configuration. This allows you to use the generated Java classes in your custom code without any additional configuration in the project.
Note: If you call this goal from the command line (mvn cds:generate
) and you want to leverage the configuration (e.g. basePackage
) from the pom.xml, you have to specify the execution id (mvn cds:generate@<execution.id>
) of this goal from the pom.xml
:
...
<execution>
<id>cds.generate</id>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<basePackage>cds.gen</basePackage>
</configuration>
</execution>
...
For this example, the required command line is mvn cds:generate@cds.generate
.
If you call this goal without the execution id, you have to provide the configuration with properties on the command line (
mvn cds:generate -Dcds.generate.basePackage=cds.gen
).
Attributes:
- Requires a Maven project to be executed.
- Executes as an aggregator goal.
- The goal is not marked as thread-safe and thus does not support parallel builds.
- Since version:
1.7.0
. - Binds by default to the lifecycle phase:
generate-resources
.
Required Parameters
Name | Type | Since | Description |
---|---|---|---|
<codeOutputDirectory> |
File |
- |
The output directory for generated Java classes. This directory is added to the source directories of your project. Default: ${project.basedir}/src/gen/ User Property: cds.codeOutputDirectory |
Optional Parameters
Name | Type | Since | Description |
---|---|---|---|
<annotationDetailLevel> |
GeneratedAnnotationDetailLevel |
2.1.0 |
Defines the level of the details of the annotation @javax.annotation.processing.Generated that is added to the accessor interfaces. Following levels of the details are available:
Default: FULL User Property: cds.generate.annotationDetailLevel |
<basePackage> |
String |
- |
Base package of generated Java classes. User Property: cds.generate.basePackage |
<cqnService> |
Boolean |
2.0.4 |
Determine whether to create interfaces for CqnServices. Default: true User Property: cds.generate.cqnService |
<csnFile> |
File |
1.8.0 |
Location of the csn file used for Java source code generation. If not specified, all resource directories are scanned for a csn.json file. If multiple csn.json files are found, the first one is used.User Property: cds.generate.csnFile |
<documentation> |
boolean |
1.17.0 |
Determine whether to generate Javadoc for the generated interfaces. Default: true User Property: cds.documentation |
<eventContext> |
boolean |
- |
Determine whether to generate interfaces extending EventContext for actions and functions. Default: true User Property: cds.generate.eventContext |
<excludes> |
List<String> |
- |
Namespaces/definitions of CDS model to be excluded from source code generation. From the set of all included definitions, the following namespaces/definitions will be excluded. An exclude always overrules an include.
For example, the exclude my.bookshop.* will exclude all definitions with namespace my.bookshop and the exclude my.bookshop.** will exclude all definitions with fully qualified name beginning with my.bookshop. Default: localized.** User Property: cds.generate.excludes |
<feature> |
String |
3.2.0 |
Specifies the generation feature to execute. If a feature is specified, this goal may only be called from the command line.
Supported features are:
Note: This parameter must not be used in a pom.xml , it is intended for other tools to provide additional features for code generation.User Property: cds.generate.feature |
<generatedHandlersPackage> |
String |
3.2.0 |
Defines the package within the application service package where the generated handlers will be created.
Note: This parameter must not be used in a pom.xml , it is intended for other tools to provide additional features for code generation.
Default: handlers User Property: cds.generate.handlers.package |
<includes> |
List<String> |
1.21.0 |
Namespaces/definitions of CDS model to be included into source code generation. By default, all definitions/namespaces are included unless an includes is specified explicitly. In which case, only the explicitly specified definitions/namespaces are included.
For example, the include my.bookshop.orders.* will include only those definitions with namespace my.bookshop.orders and the include my.bookshop.books.** will include all definitions with fully qualified name beginning with my.bookshop.books. User Property: cds.generate.includes |
<interfacesForAspects> |
boolean |
3.0.0 |
Enables the generation of accessor interfaces for entities representing the targets of compositions of aspects. This might be incompatible with existing code as the type of the getters and setters for compositions will change. Default: false User Property: cds.generate.interfacesForAspects |
<methodStyle> |
MethodStyle |
- |
Defines method styling for accessor interface methods; follows either the Java Bean style method naming for getters & setters denoted by BEAN or the Fluent style denoted by FLUENT .
Valid values: BEAN or FLUENT .Default: BEAN User Property: cds.generate.methodStyle |
<overwrite> |
boolean |
3.2.0 |
Overwrite existing files during code generation. If set to true , existing files will be overwritten.
Note:Use carefully, as it overwrites existing files without confirmation and does not back up existing files. This parameter must not be used in a pom.xml , it is intended for other tools to provide additional features for code generation.
Default: false User Property: cds.generate.overwrite |
<sharedInterfaces> |
boolean |
2.8.0 |
Deprecated. Will be removed in a future release and the default behaviour will be used. Enables the usage of interfaces generated for the global types with inline anonymous arrayed types in the interfaces generated for actions and functions. With this switch off, the interfaces for an actions or functions always represent these types as inner interfaces which might lead to a duplication of code. With this switch on, the globally generated interfaces will be preferred over the inline interfaces. This might be incompatible with existing code that uses the inline interfaces. Default: true User Property: cds.generate.sharedInterfaces |
<skip> |
boolean |
- |
Skip execution of this goal. Default: false User Property: cds.generate.skip |
<strictSetters> |
boolean |
3.3.0 |
Enables strict setters for generated accessor interfaces. This enforces usage of typed interfaces in setters of associations, instead of using more generic Map<String, Object> or List<Map<String, Object>> argument types.Default: false User Property: cds.generate.strictSetters |
<testSources> |
boolean |
1.31.0 |
Determine whether to add generated sources to compile or test sources. Default: false User Property: cds.generate.testSources |
<uniqueEventContexts> |
boolean |
2.9.0 |
Deprecated. Will be removed in a future release and the default behaviour will be used. Determines whether the event context interfaces should be unique for bound actions and functions. If set to true , the event context interface name of bound actions and functions will be prefixed with the entity name.
Note: This is incompatible with existing code that uses the event context interfaces for bound actions or functions. Default: true User Property: cds.generate.uniqueEventContexts |
Parameter Details
<annotationDetailLevel>
Defines the level of the details of the annotation @
javax.annotation.processing.Generated
that is added to the accessor interfaces. Following levels of the details are available:
NONE
annotation is not added
MINIMAL
annotation is added with the name of the plugin.
FULL
annotation is added with full details
- Type:
com.sap.cds.generator.GeneratedAnnotationDetailLevel
- Since:
2.1.0
- Required:
No
- User Property:
cds.generate.annotationDetailLevel
- Default:
FULL
<basePackage>
Base package of generated Java classes.
- Type:
java.lang.String
- Required:
No
- User Property:
cds.generate.basePackage
<codeOutputDirectory>
The output directory for generated Java classes. This directory is added to the source directories of your project.
- Type:
java.io.File
- Required:
Yes
- User Property:
cds.codeOutputDirectory
- Default:
${project.basedir}/src/gen/
<cqnService>
Determine whether to create interfaces for CqnServices.
- Type:
java.lang.Boolean
- Since:
2.0.4
- Required:
No
- User Property:
cds.generate.cqnService
- Default:
true
<csnFile>
Location of the csn file used for Java source code generation. If not specified, all resource directories are scanned for a
csn.json
file. If multiple csn.json
files are found, the first one is used.- Type:
java.io.File
- Since:
1.8.0
- Required:
No
- User Property:
cds.generate.csnFile
<documentation>
Determine whether to generate Javadoc for the generated interfaces.
- Type:
boolean
- Since:
1.17.0
- Required:
No
- User Property:
cds.documentation
- Default:
true
<eventContext>
Determine whether to generate interfaces extending EventContext for actions and functions.
- Type:
boolean
- Required:
No
- User Property:
cds.generate.eventContext
- Default:
true
<excludes>
Namespaces/definitions of CDS model to be excluded from source code generation. From the set of all included definitions, the following namespaces/definitions will be excluded. An exclude always overrules an include.
For example, the exclude my.bookshop.* will exclude all definitions with namespace my.bookshop and the exclude my.bookshop.** will exclude all definitions with fully qualified name beginning with my.bookshop.
For example, the exclude my.bookshop.* will exclude all definitions with namespace my.bookshop and the exclude my.bookshop.** will exclude all definitions with fully qualified name beginning with my.bookshop.
- Type:
java.util.List<java.lang.String>
- Required:
No
- User Property:
cds.generate.excludes
- Default:
localized.**
<feature>
Specifies the generation feature to execute. If a feature is specified, this goal may only be called from the command line.
Supported features are:
Note: This parameter must not be used in a
Supported features are:
- EVENT_HANDLERS Generate event handler classes for actions and functions
Note: This parameter must not be used in a
pom.xml
, it is intended for other tools to provide additional features for code generation.- Type:
java.lang.String
- Since:
3.2.0
- Required:
No
- User Property:
cds.generate.feature
<generatedHandlersPackage>
Defines the package within the application service package where the generated handlers will be created.
Note: This parameter must not be used in a
Note: This parameter must not be used in a
pom.xml
, it is intended for other tools to provide additional features for code generation.
- Type:
java.lang.String
- Since:
3.2.0
- Required:
No
- User Property:
cds.generate.handlers.package
- Default:
handlers
<includes>
Namespaces/definitions of CDS model to be included into source code generation. By default, all definitions/namespaces are included unless an includes is specified explicitly. In which case, only the explicitly specified definitions/namespaces are included.
For example, the include my.bookshop.orders.* will include only those definitions with namespace my.bookshop.orders and the include my.bookshop.books.** will include all definitions with fully qualified name beginning with my.bookshop.books.
For example, the include my.bookshop.orders.* will include only those definitions with namespace my.bookshop.orders and the include my.bookshop.books.** will include all definitions with fully qualified name beginning with my.bookshop.books.
- Type:
java.util.List<java.lang.String>
- Since:
1.21.0
- Required:
No
- User Property:
cds.generate.includes
<interfacesForAspects>
Enables the generation of accessor interfaces for entities representing the targets of compositions of aspects. This might be incompatible with existing code as the type of the getters and setters for compositions will change.
- Type:
boolean
- Since:
3.0.0
- Required:
No
- User Property:
cds.generate.interfacesForAspects
- Default:
false
<methodStyle>
Defines method styling for accessor interface methods; follows either the Java Bean style method naming for getters & setters denoted by
Valid values:
BEAN
or the Fluent style denoted by FLUENT
.
Valid values:
BEAN
or FLUENT
.- Type:
com.sap.cds.generator.MethodStyle
- Required:
No
- User Property:
cds.generate.methodStyle
- Default:
BEAN
<overwrite>
Overwrite existing files during code generation. If set to
Note:Use carefully, as it overwrites existing files without confirmation and does not back up existing files.
This parameter must not be used in a
true
, existing files will be overwritten.
Note:Use carefully, as it overwrites existing files without confirmation and does not back up existing files.
This parameter must not be used in a
pom.xml
, it is intended for other tools to provide additional features for code generation.
- Type:
boolean
- Since:
3.2.0
- Required:
No
- User Property:
cds.generate.overwrite
- Default:
false
<sharedInterfaces>
Deprecated.
Will be removed in a future release and the default behaviour will be used.
Will be removed in a future release and the default behaviour will be used.
Enables the usage of interfaces generated for the global types with inline anonymous arrayed types in the interfaces generated for actions and functions. With this switch off, the interfaces for an actions or functions always represent these types as inner interfaces which might lead to a duplication of code. With this switch on, the globally generated interfaces will be preferred over the inline interfaces. This might be incompatible with existing code that uses the inline interfaces.
- Type:
boolean
- Since:
2.8.0
- Required:
No
- User Property:
cds.generate.sharedInterfaces
- Default:
true
<skip>
Skip execution of this goal.
- Type:
boolean
- Required:
No
- User Property:
cds.generate.skip
- Default:
false
<strictSetters>
Enables strict setters for generated accessor interfaces. This enforces usage of typed interfaces in setters of associations, instead of using more generic
Map<String, Object>
or List<Map<String, Object>>
argument types.- Type:
boolean
- Since:
3.3.0
- Required:
No
- User Property:
cds.generate.strictSetters
- Default:
false
<testSources>
Determine whether to add generated sources to compile or test sources.
- Type:
boolean
- Since:
1.31.0
- Required:
No
- User Property:
cds.generate.testSources
- Default:
false
<uniqueEventContexts>
Deprecated.
Will be removed in a future release and the default behaviour will be used.
Will be removed in a future release and the default behaviour will be used.
Determines whether the event context interfaces should be unique for bound actions and functions. If set to
Note: This is incompatible with existing code that uses the event context interfaces for bound actions or functions.
true
, the event context interface name of bound actions and functions will be prefixed with the entity name.
Note: This is incompatible with existing code that uses the event context interfaces for bound actions or functions.
- Type:
boolean
- Since:
2.9.0
- Required:
No
- User Property:
cds.generate.uniqueEventContexts
- Default:
true