Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add basePackage option #795

Merged
merged 2 commits into from
Jan 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/common/src/lib/utils/generators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,7 @@ export function isCustomPortFunction(options: {
export function parseProjects(projects: string | undefined) {
return projects ? projects.split(',').map((s) => s.trim()) : [];
}

export function generateBasePackage(groupId: string) {
return groupId.replace(new RegExp(/-/, 'g'), '');
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication<% if(!minimal) { %>(scanBasePackages = "<%= groupId %>")<% } %>
@SpringBootApplication<% if(!minimal) { %>(scanBasePackages = "<%= basePackage %>")<% } %>
public class <%= appClassName %> {

public static void main(String[] args) {
Expand Down
16 changes: 5 additions & 11 deletions packages/nx-gradle/src/generators/application/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
VersionManagementType,
clearEmpties,
generateAppClassName,
generateBasePackage,
generatePackageDirectory,
generatePackageName,
generateProjectDirectory,
Expand Down Expand Up @@ -54,23 +55,13 @@ interface NormalizedSchema extends NxGradleAppGeneratorSchema {
quarkusVersion: string;
gradleRootDirectory: string;
versionManagement: VersionManagementType;
}

function removeHyphenFromGroupId(
options: NxGradleAppGeneratorSchema,
): NxGradleAppGeneratorSchema {
return {
...options,
groupId: options.groupId.replace(new RegExp(/-/, 'g'), ''),
};
basePackage: string;
}

function normalizeOptions(
tree: Tree,
options: NxGradleAppGeneratorSchema,
): NormalizedSchema {
options = removeHyphenFromGroupId(options);

const simpleProjectName = generateSimpleProjectName({
name: options.name,
});
Expand Down Expand Up @@ -118,6 +109,8 @@ function normalizeOptions(
versionManagement,
);

const basePackage = generateBasePackage(options.groupId);

return {
...options,
projectName,
Expand All @@ -133,6 +126,7 @@ function normalizeOptions(
quarkusVersion: qVersion,
gradleRootDirectory,
versionManagement,
basePackage,
};
}

Expand Down
16 changes: 5 additions & 11 deletions packages/nx-maven/src/generators/application/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
micronautVersion,
quarkusVersion,
springBootVersion,
generateBasePackage,
} from '@jnxplus/common';
import {
ProjectConfiguration,
Expand Down Expand Up @@ -57,23 +58,13 @@ interface NormalizedSchema extends NxMavenAppGeneratorSchema {
micronautVersion: string;
dependencyManagement: DependencyManagementType;
mavenRootDirectory: string;
}

function removeHyphenFromGroupId(
options: NxMavenAppGeneratorSchema,
): NxMavenAppGeneratorSchema {
return {
...options,
groupId: options.groupId.replace(new RegExp(/-/, 'g'), ''),
};
basePackage: string;
}

function normalizeOptions(
tree: Tree,
options: NxMavenAppGeneratorSchema,
): NormalizedSchema {
options = removeHyphenFromGroupId(options);

const simpleProjectName = generateSimpleProjectName({
name: options.name,
});
Expand Down Expand Up @@ -121,6 +112,8 @@ function normalizeOptions(
options.framework,
);

const basePackage = generateBasePackage(options.groupId);

return {
...options,
projectName,
Expand All @@ -140,6 +133,7 @@ function normalizeOptions(
micronautVersion,
dependencyManagement,
mavenRootDirectory,
basePackage,
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ describe('nx-gradle spring-boot e2e', () => {
const port = 8181;

await runNxCommandAsync(
`generate @jnxplus/nx-gradle:application ${randomName} --framework spring-boot --tags e2etag,e2ePackage --directory ${appDir} --groupId com.jnxplus --projectVersion 1.2.3 --packaging war --configFormat .yml --port ${port} --simplePackageName false --simpleName false`,
`generate @jnxplus/nx-gradle:application ${randomName} --framework spring-boot --tags e2etag,e2ePackage --directory ${appDir} --groupId com.j-nx-plus --projectVersion 1.2.3 --packaging war --configFormat .yml --port ${port} --simplePackageName false --simpleName false`,
);

expect(() =>
Expand All @@ -221,7 +221,7 @@ describe('nx-gradle spring-boot e2e', () => {

// Making sure the build.gradle file contains the good information
const buildGradle = readFile(`${appDir}/${randomName}/build.gradle`);
expect(buildGradle.includes('com.jnxplus')).toBeTruthy();
expect(buildGradle.includes('com.j-nx-plus')).toBeTruthy();
expect(buildGradle.includes('1.2.3')).toBeTruthy();
expect(buildGradle.includes('war')).toBeTruthy();
expect(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ describe('nx-maven spring-boot-parent-pom e2e', () => {

// Making sure the pom.xml file contains the correct information
const pomXml = readFile(`${appDir}/${randomName}/pom.xml`);
expect(pomXml.includes('com.jnxplus')).toBeTruthy();
expect(pomXml.includes('com.j-nx-plus')).toBeTruthy();
expect(pomXml.includes('1.2.3')).toBeTruthy();
expect(pomXml.includes('war')).toBeTruthy();
expect(pomXml.includes('spring-boot-starter-tomcat')).toBeTruthy();
Expand Down