Skip to content

Commit c6ca2ab

Browse files
fix(cli): broken java init template (#13988)
Change the java init templates to not call the stack builder classes and instead call the generated stack class constructor. Change the structure of the comments to correctly allow uncommenting in order to pass env config if needed. fix: #13964 ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent 965f130 commit c6ca2ab

File tree

2 files changed

+40
-29
lines changed

2 files changed

+40
-29
lines changed

packages/aws-cdk/lib/init-templates/v1/app/java/src/main/java/com/myorg/%name.PascalCased%App.template.java

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,38 +2,44 @@
22

33
import software.amazon.awscdk.core.App;
44
import software.amazon.awscdk.core.Environment;
5+
import software.amazon.awscdk.core.StackProps;
56

67
import java.util.Arrays;
78

89
public class %name.PascalCased%App {
910
public static void main(final String[] args) {
1011
App app = new App();
1112

12-
%name.PascalCased%Stack.Builder.create(app, "%name.PascalCased%Stack")
13-
// If you don't specify 'env', this stack will be environment-agnostic.
14-
// Account/Region-dependent features and context lookups will not work,
15-
// but a single synthesized template can be deployed anywhere.
13+
// If you don't specify 'env', this stack will be environment-agnostic.
14+
// Account/Region-dependent features and context lookups will not work,
15+
// but a single synthesized template can be deployed anywhere.
16+
new %name.PascalCased%Stack(app, "%name.PascalCased%Stack");
1617

17-
// Uncomment the next block to specialize this stack for the AWS Account
18-
// and Region that are implied by the current CLI configuration.
19-
/*
18+
// Replace the above stack intialization with the following to specialize
19+
// this stack for the AWS Account and Region that are implied by the current
20+
// CLI configuration.
21+
/*
22+
new %name.PascalCased%Stack(app, "%name.PascalCased%Stack", StackProps.builder()
2023
.env(Environment.builder()
2124
.account(System.getenv("CDK_DEFAULT_ACCOUNT"))
2225
.region(System.getenv("CDK_DEFAULT_REGION"))
2326
.build())
24-
*/
27+
.build());
28+
*/
2529

26-
// Uncomment the next block if you know exactly what Account and Region you
27-
// want to deploy the stack to.
28-
/*
30+
// Replace the above stack initialization with the following if you know exactly
31+
// what Account and Region you want to deploy the stack to.
32+
/*
33+
new %name.PascalCased%Stack(app, "%name.PascalCased%Stack", StackProps.builder()
2934
.env(Environment.builder()
3035
.account("123456789012")
3136
.region("us-east-1")
3237
.build())
33-
*/
3438
35-
// For more information, see https://docs.aws.amazon.com/cdk/latest/guide/environments.html
36-
.build();
39+
.build());
40+
*/
41+
42+
// For more information, see https://docs.aws.amazon.com/cdk/latest/guide/environments.html
3743

3844
app.synth();
3945
}

packages/aws-cdk/lib/init-templates/v2/app/java/src/main/java/com/myorg/%name.PascalCased%App.template.java

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,31 +9,36 @@ public class %name.PascalCased%App {
99
public static void main(final String[] args) {
1010
App app = new App();
1111

12-
%name.PascalCased%Stack.Builder.create(app, "%name.PascalCased%Stack")
13-
// If you don't specify 'env', this stack will be environment-agnostic.
14-
// Account/Region-dependent features and context lookups will not work,
15-
// but a single synthesized template can be deployed anywhere.
16-
17-
// Uncomment the next block to specialize this stack for the AWS Account
18-
// and Region that are implied by the current CLI configuration.
19-
/*
12+
// If you don't specify 'env', this stack will be environment-agnostic.
13+
// Account/Region-dependent features and context lookups will not work,
14+
// but a single synthesized template can be deployed anywhere.
15+
new %name.PascalCased%Stack(app, "%name.PascalCased%Stack");
16+
17+
// Replace the above stack intialization with the following to specialize
18+
// this stack for the AWS Account and Region that are implied by the current
19+
// CLI configuration.
20+
/*
21+
new %name.PascalCased%Stack(app, "%name.PascalCased%Stack", StackProps.builder()
2022
.env(Environment.builder()
2123
.account(System.getenv("CDK_DEFAULT_ACCOUNT"))
2224
.region(System.getenv("CDK_DEFAULT_REGION"))
2325
.build())
24-
*/
26+
.build());
27+
*/
2528

26-
// Uncomment the next block if you know exactly what Account and Region you
27-
// want to deploy the stack to.
28-
/*
29+
// Replace the above stack initialization with the following if you know exactly
30+
// what Account and Region you want to deploy the stack to.
31+
/*
32+
new %name.PascalCased%Stack(app, "%name.PascalCased%Stack", StackProps.builder()
2933
.env(Environment.builder()
3034
.account("123456789012")
3135
.region("us-east-1")
3236
.build())
33-
*/
3437
35-
// For more information, see https://docs.aws.amazon.com/cdk/latest/guide/environments.html
36-
.build();
38+
.build());
39+
*/
40+
41+
// For more information, see https://docs.aws.amazon.com/cdk/latest/guide/environments.html
3742

3843
app.synth();
3944
}

0 commit comments

Comments
 (0)