From a896b33f52796377d0692fb3871f2e99192984ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcin=20Bia=C5=82o=C5=84?= Date: Fri, 5 Jan 2024 14:56:48 +0100 Subject: [PATCH] feat: make maven group ID overridable --- API.md | 13 +++++++++++++ src/index.ts | 9 +++++++-- test/index.test.ts | 26 ++++++++++++++++++++++++++ 3 files changed, 46 insertions(+), 2 deletions(-) diff --git a/API.md b/API.md index c00c25a0..882c6e77 100644 --- a/API.md +++ b/API.md @@ -1675,6 +1675,7 @@ const cdktfProviderProjectOptions: CdktfProviderProjectOptions = { ... } | githubNamespace | string | defaults to "cdktf" previously was "hashicorp". | | isDeprecated | boolean | Whether or not this prebuilt provider is deprecated. | | mavenEndpoint | string | *No description.* | +| mavenGroupId | string | defaults to "com.${mavenOrg}". | | mavenOrg | string | defaults to "hashicorp". | | namespace | string | defaults to "cdktf". | | nugetOrg | string | defaults to "HashiCorp". | @@ -4000,6 +4001,18 @@ public readonly mavenEndpoint: string; --- +##### `mavenGroupId`Optional + +```typescript +public readonly mavenGroupId: string; +``` + +- *Type:* string + +defaults to "com.${mavenOrg}". + +--- + ##### `mavenOrg`Optional ```typescript diff --git a/src/index.ts b/src/index.ts index 87211801..e18449de 100644 --- a/src/index.ts +++ b/src/index.ts @@ -48,6 +48,10 @@ export interface CdktfProviderProjectOptions extends cdk.JsiiProjectOptions { * defaults to "hashicorp" */ readonly mavenOrg?: string; + /** + * defaults to "com.${mavenOrg}" + */ + readonly mavenGroupId?: string; /** * The year of the creation of the repository, for copyright purposes. * Will fall back to the current year if not specified. @@ -123,7 +127,8 @@ export class CdktfProviderProject extends cdk.JsiiProject { const nugetName = `${nugetOrg}.${pascalCase( namespace )}.Providers.${pascalCase(providerName)}`; - const mavenName = `com.${mavenOrg}.${namespace}.providers.${getMavenName( + const mavenGroupId = options.mavenGroupId ?? `com.${mavenOrg}`; + const mavenName = `${mavenGroupId}.${namespace}.providers.${getMavenName( providerName )}`; const repositoryUrl = `github.com/${githubNamespace}/${namespace}-provider-${providerName.replace( @@ -151,7 +156,7 @@ export class CdktfProviderProject extends cdk.JsiiProject { }, publishToMaven: { javaPackage: mavenName, - mavenGroupId: `com.${mavenOrg}`, + mavenGroupId: mavenGroupId, mavenArtifactId: `${namespace}-provider-${providerName}`, mavenEndpoint, }, diff --git a/test/index.test.ts b/test/index.test.ts index 5c5e6ac8..6cf824d8 100644 --- a/test/index.test.ts +++ b/test/index.test.ts @@ -151,3 +151,29 @@ test("has a custom workflow and README if the project is deprecated", () => { ) ); }); + +test("override maven org", () => { + const snapshot = synthSnapshot(getProject({ mavenOrg: "gofer" })); + + expect(JSON.parse(snapshot["package.json"])).toHaveProperty( + "jsii.targets.java.maven.groupId", + "com.gofer" + ); + expect(JSON.parse(snapshot["package.json"])).toHaveProperty( + "jsii.targets.java.package", + "com.gofer.cdktf.providers.random_provider" + ); +}); + +test("override maven group id", () => { + const snapshot = synthSnapshot(getProject({ mavenGroupId: "dev.gofer" })); + + expect(JSON.parse(snapshot["package.json"])).toHaveProperty( + "jsii.targets.java.maven.groupId", + "dev.gofer" + ); + expect(JSON.parse(snapshot["package.json"])).toHaveProperty( + "jsii.targets.java.package", + "dev.gofer.cdktf.providers.random_provider" + ); +});