Skip to content

CDK: How to manage multiple Maven profiles ?

0

In Java applications it's very common to use Maven profiles in order to customize builds. This is done by using the mvn -P<profile-name ... command. However, with the CDK, the Maven command to be used for building is the one taken from the cdk.json file. This command is statically generated by cdk init and, accordingly, it's always the same: mvn -e -q compile exec:java. I'd need to be able to use a parameter or something with the cdk deploy command such that the build command to become mvn -e -q -P<profile-name> compile exec:java. How could I accomplish that ? Many thanks in advance.

1 Answer
1
Accepted Answer

I figured out the solution that I was looking for. Instead of using Maven profiles one could use environment variables by the --context key=value option with the cdk deploy command and then get this value in the code:

String myValue = (String)this.getNode().tryGetContext("value");

This way, no need to modify cdk.json file.

answered 2 years ago

EXPERT

reviewed 2 years ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.