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

feat: improve multi-module support #210

Merged
merged 12 commits into from
Feb 11, 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
5 changes: 5 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@
"mounts": [
"source=nxrocks-node_modules,target=${containerWorkspaceFolder}/node_modules,type=volume"
],

// Use 'forwardPorts' to make a list of ports inside the container available locally.
"forwardPorts": [
4211
],
"runArgs": [],
"postCreateCommand": "./.devcontainer/postCreateCommand.sh",
"customizations": {
Expand Down
27 changes: 22 additions & 5 deletions packages/common-jvm/src/lib/utils/gradle-utils.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
} from './gradle-utils';
import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing';
import { stripIndent } from '@nxrocks/common';
import { SPOTLESS_GRADLE_PLUGIN_ID } from '.';
import { SPOTLESS_GRADLE_PLUGIN_ID, checkForMultiModuleGradleProject } from '.';

const BUILD_GRADLE_FILE = `plugins {
id 'org.springframework.boot' version '2.6.2'
Expand Down Expand Up @@ -442,32 +442,49 @@ describe('gradle-utils', () => {
tree.write(`./${rootFolder}/settings.gradle`, MULTI_MODULE_SETTINGS_FILE);

expect(hasGradleModuleInTree(tree, rootFolder, 'libraryX')).toBe(false);
expect(addGradleModule(tree, rootFolder, 'libraryX', false)).toBe(true);
expect(addGradleModule(tree, rootFolder, 'libraryX', '', false)).toBe(true);
expect(hasGradleModuleInTree(tree, rootFolder, 'libraryX')).toBe(true);
});

it('should not add gradle module when already present', ()=>{
tree.write(`./${rootFolder}/build.gradle`, BUILD_GRADLE_FILE);
tree.write(`./${rootFolder}/settings.gradle`, MULTI_MODULE_SETTINGS_FILE);

expect(addGradleModule(tree, rootFolder, 'library1', false)).toBe(false);
expect(addGradleModule(tree, rootFolder, 'library1', '', false)).toBe(false);
});

it('should add kotlin gradle module when not already present', ()=>{
tree.write(`./${rootFolder}/build.gradle.kts`, BUILD_GRADLE_KOTLIN_FILE);
tree.write(`./${rootFolder}/settings.gradle.kts`, MULTI_MODULE_SETTINGS_KTS_FILE);

expect(hasGradleModuleInTree(tree, rootFolder, 'libraryX')).toBe(false);
expect(addGradleModule(tree, rootFolder, 'libraryX', true)).toBe(true);
expect(addGradleModule(tree, rootFolder, 'libraryX', '', true)).toBe(true);
expect(hasGradleModuleInTree(tree, rootFolder, 'libraryX')).toBe(true);
});

it('should not add kotlin gradle module when already present', ()=>{
tree.write(`./${rootFolder}/build.gradle.kts`, BUILD_GRADLE_KOTLIN_FILE);
tree.write(`./${rootFolder}/settings.gradle.kts`, MULTI_MODULE_SETTINGS_KTS_FILE);

expect(addGradleModule(tree, rootFolder, 'library1', true)).toBe(false);
expect(addGradleModule(tree, rootFolder, 'library1', '', true)).toBe(false);
});
});

describe('checkForMultiModuleGradleProject', ()=>{

it('should return true if the given settings.gradle represents a multi-module gradle project', ()=>{
const settings = `
// For more information about Spring boot multi-modules projects, go to: https://spring.io/guides/gs/multi-module/
rootProject.name = 'gboot-parent'


include 'gbootlib'
include 'gbootapp'
`;

expect(checkForMultiModuleGradleProject(settings)).toBe(true)
});
});

});

Loading
Loading