Skip to content

Commit

Permalink
fix: use codemaker output in java
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielMSchmidt committed Oct 13, 2023
1 parent bdef3df commit 34eeebe
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 7 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@

Since the long-term support for Node.js 16 ended on 2023-09-11, we updated our minimum compatible Node.js version to 18.12.

### Java: `codeMakerOutput` needs to be set to a company identifier

We did not honor the `codeMakerOutput` setting in the `cdktf.json` previously, this is fixed now.
To have no changes in the generated code you can set `codeMakerOutput: "imports"`.
If you like, you can now set it to your company name, e.g. `codeMakerOutput: "com.hashicorp"` so that the provider is generated under the `com.hashicorp.aws` generated.

## 0.18.2

Fixes a bug in 0.18.1 that broke crash reporting due to a partial dependency upgrade.
Expand Down
2 changes: 1 addition & 1 deletion examples/java/documentation-gradle/cdktf.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"language": "java",
"app": "./gradlew run",
"codeMakerOutput": "src/main/java/imports",
"codeMakerOutput": "imports",
"terraformProviders": [
"aws@~> 3.0",
"kubernetes@~> 2.0",
Expand Down
2 changes: 1 addition & 1 deletion examples/java/documentation/cdktf.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"language": "java",
"app": "mvn -e -q compile exec:java",
"codeMakerOutput": "src/main/java/imports",
"codeMakerOutput": "imports",
"terraformProviders": [
"aws@~> 3.0",
"kubernetes@~> 2.0",
Expand Down
2 changes: 1 addition & 1 deletion examples/java/gradle-shared-module/common/cdktf.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"language": "java",
"app": "../gradlew -q :common:run",
"output": "./",
"codeMakerOutput": "./src/main/java/imports",
"codeMakerOutput": "imports",
"terraformProviders": [
"hashicorp/vsphere@~> 2.0.2"
],
Expand Down
2 changes: 1 addition & 1 deletion examples/java/gradle-shared-module/module-a/cdktf.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"language": "java",
"app": "../gradlew -q :module-a:run",
"output": "./",
"codeMakerOutput": "./src/main/java/imports",
"codeMakerOutput": "imports",
"terraformProviders": [],
"context": {}
}
2 changes: 1 addition & 1 deletion examples/java/gradle-shared-module/module-b/cdktf.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"app": "../gradlew -q :module-b:run",
"//": "The target output directory is set to the current working directory so that definitions generated by cdk can be referenced in local HCL sources",
"output": "./",
"codeMakerOutput": "./src/main/java/imports",
"codeMakerOutput": "imports",
"terraformProviders": [],
"context": {}
}
2 changes: 1 addition & 1 deletion packages/@cdktf/cli-core/templates/java/cdktf.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"app": "./gradlew run",
"projectId": "{{projectId}}",
"sendCrashReports": "{{sendCrashReports}}",
"codeMakerOutput": "src/main/java/imports",
"codeMakerOutput": "imports",
"terraformProviders": [],
"terraformModules": [],
"context": {
Expand Down
11 changes: 10 additions & 1 deletion packages/@cdktf/provider-generator/lib/get/constructs-maker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -410,9 +410,18 @@ export class ConstructsMaker {
}

if (this.isJavaTarget) {
if (
this.options.codeMakerOutput.includes("/") ||
this.options.codeMakerOutput.includes("\\")
) {
throw Errors.Usage(
`When using Java the "codeMakerOutput" option in the cdktf.json must be the organization identifier for your project (e.g. com.my-company), not a path. The generated Java code will be placed in a subdirectory of the given directory.`
);
}

opts.java = {
outdir: ".", // generated java files aren't packaged, so just include directly in app
package: `imports.${target.srcMakName}`,
package: `${this.options.codeMakerOutput}.${target.srcMakName}`,
};
}

Expand Down

0 comments on commit 34eeebe

Please sign in to comment.