diff --git a/packages/nx-gradle/src/generators/init/files/gradle/catalog/kotlin-multiplatform/libs.versions.toml b/packages/nx-gradle/src/generators/init/files/gradle/catalog/kotlin-multiplatform/libs.versions.toml new file mode 100644 index 000000000..6ed4ba908 --- /dev/null +++ b/packages/nx-gradle/src/generators/init/files/gradle/catalog/kotlin-multiplatform/libs.versions.toml @@ -0,0 +1,5 @@ +[versions] + +[libraries] + +[plugins] \ No newline at end of file diff --git a/packages/nx-gradle/src/generators/init/files/gradle/catalog/micronaut/libs.versions.toml b/packages/nx-gradle/src/generators/init/files/gradle/catalog/micronaut/libs.versions.toml new file mode 100644 index 000000000..6ed4ba908 --- /dev/null +++ b/packages/nx-gradle/src/generators/init/files/gradle/catalog/micronaut/libs.versions.toml @@ -0,0 +1,5 @@ +[versions] + +[libraries] + +[plugins] \ No newline at end of file diff --git a/packages/nx-gradle/src/generators/init/files/gradle/catalog/none/libs.versions.toml b/packages/nx-gradle/src/generators/init/files/gradle/catalog/none/libs.versions.toml new file mode 100644 index 000000000..6ed4ba908 --- /dev/null +++ b/packages/nx-gradle/src/generators/init/files/gradle/catalog/none/libs.versions.toml @@ -0,0 +1,5 @@ +[versions] + +[libraries] + +[plugins] \ No newline at end of file diff --git a/packages/nx-gradle/src/generators/init/files/gradle/catalog/quarkus/libs.versions.toml b/packages/nx-gradle/src/generators/init/files/gradle/catalog/quarkus/libs.versions.toml new file mode 100644 index 000000000..6ed4ba908 --- /dev/null +++ b/packages/nx-gradle/src/generators/init/files/gradle/catalog/quarkus/libs.versions.toml @@ -0,0 +1,5 @@ +[versions] + +[libraries] + +[plugins] \ No newline at end of file diff --git a/packages/nx-gradle/src/generators/init/files/gradle/catalog/spring-boot/libs.versions.toml b/packages/nx-gradle/src/generators/init/files/gradle/catalog/spring-boot/libs.versions.toml new file mode 100644 index 000000000..6ed4ba908 --- /dev/null +++ b/packages/nx-gradle/src/generators/init/files/gradle/catalog/spring-boot/libs.versions.toml @@ -0,0 +1,5 @@ +[versions] + +[libraries] + +[plugins] \ No newline at end of file diff --git a/packages/nx-gradle/src/generators/init/generator.ts b/packages/nx-gradle/src/generators/init/generator.ts index d2991e28a..a98de2963 100644 --- a/packages/nx-gradle/src/generators/init/generator.ts +++ b/packages/nx-gradle/src/generators/init/generator.ts @@ -86,6 +86,15 @@ function addFiles(tree: Tree, options: NormalizedSchema) { options.gradleRootDirectory, templateOptions, ); + + if (options.versionManagement === 'version-catalog') { + generateFiles( + tree, + path.join(__dirname, 'files', 'gradle', 'catalog', options.preset), + 'gradle', + templateOptions + ); + } } export default initGenerator; diff --git a/testing-projects/e2e/nx-gradle-catalog-e2e/jest.config.js b/testing-projects/e2e/nx-gradle-catalog-e2e/jest.config.js new file mode 100644 index 000000000..bd6f350d3 --- /dev/null +++ b/testing-projects/e2e/nx-gradle-catalog-e2e/jest.config.js @@ -0,0 +1,17 @@ +module.exports = { + displayName: 'nx-gradle-catalog-e2e', + preset: '../../../jest.preset.js', + globals: {}, + testEnvironment: 'node', + transform: { + '^.+\\.[tj]s$': [ + 'ts-jest', + { + tsconfig: '/tsconfig.spec.json', + }, + ], + }, + moduleFileExtensions: ['ts', 'js', 'html'], + coverageDirectory: + '../../../coverage/e2e/nx-gradle-catalog-e2e', +}; diff --git a/testing-projects/e2e/nx-gradle-catalog-e2e/project.json b/testing-projects/e2e/nx-gradle-catalog-e2e/project.json new file mode 100644 index 000000000..691026ae2 --- /dev/null +++ b/testing-projects/e2e/nx-gradle-catalog-e2e/project.json @@ -0,0 +1,18 @@ +{ + "name": "nx-gradle-catalog-e2e", + "$schema": "../../../node_modules/nx/schemas/project-schema.json", + "projectType": "application", + "sourceRoot": "testing-projects/e2e/nx-gradle-catalog-e2e/src", + "targets": { + "e2e": { + "executor": "@nx/jest:jest", + "options": { + "jestConfig": "testing-projects/e2e/nx-gradle-catalog-e2e/jest.config.js", + "runInBand": true + }, + "dependsOn": ["nx-gradle:build"] + } + }, + "tags": [], + "implicitDependencies": ["nx-gradle"] +} diff --git a/testing-projects/e2e/nx-gradle-catalog-e2e/tests/nx-gradle-catalog.spec.ts b/testing-projects/e2e/nx-gradle-catalog-e2e/tests/nx-gradle-catalog.spec.ts new file mode 100644 index 000000000..3f79a675e --- /dev/null +++ b/testing-projects/e2e/nx-gradle-catalog-e2e/tests/nx-gradle-catalog.spec.ts @@ -0,0 +1,139 @@ +import { names, workspaceRoot } from '@nx/devkit'; +import { + checkFilesExist, + cleanup, + readFile, + readJson, + runNxCommandAsync, + tmpProjPath, + uniq, + updateFile, +} from '@nx/plugin/testing'; +import * as fse from 'fs-extra'; +import * as path from 'path'; + +import { checkstyleVersion } from '@jnxplus/common'; +import { + addTmpToGitignore, + patchPackageJson, + patchRootPackageJson, + removeTmpFromGitignore, + runNxNewCommand, + runPackageManagerInstallLinks, +} from '@jnxplus/internal/testing'; + +describe('nx-gradle version-catalog e2e', () => { + const isCI = + process.env.CI === 'true' || process.env.GITHUB_ACTIONS === 'true'; + const isWin = process.platform === 'win32'; + const isMacOs = process.platform === 'darwin'; + const rootProjectName = uniq('boot-root-project-'); + + beforeAll(async () => { + fse.ensureDirSync(tmpProjPath()); + cleanup(); + runNxNewCommand('', true); + + const pluginName = '@jnxplus/nx-gradle'; + const nxGradleDistAbsolutePath = path.join( + workspaceRoot, + 'dist', + 'packages', + 'nx-gradle' + ); + + const commonDistAbsolutePath = path.join( + workspaceRoot, + 'dist', + 'packages', + 'common' + ); + + const gradleDistAbsolutePath = path.join( + workspaceRoot, + 'dist', + 'packages', + 'gradle' + ); + + patchRootPackageJson(pluginName, nxGradleDistAbsolutePath); + patchRootPackageJson('@jnxplus/common', commonDistAbsolutePath); + patchRootPackageJson('@jnxplus/gradle', gradleDistAbsolutePath); + + patchPackageJson( + gradleDistAbsolutePath, + '@jnxplus/common', + commonDistAbsolutePath + ); + + patchPackageJson( + nxGradleDistAbsolutePath, + '@jnxplus/common', + commonDistAbsolutePath + ); + patchPackageJson( + nxGradleDistAbsolutePath, + '@jnxplus/gradle', + gradleDistAbsolutePath + ); + + runPackageManagerInstallLinks(); + + await runNxCommandAsync( + `generate @jnxplus/nx-gradle:init --dsl kotlin --rootProjectName ${rootProjectName} --preset spring-boot --versionManagement version-catalog` + ); + + if (isCI) { + removeTmpFromGitignore(); + } + }, 120000); + + afterAll(async () => { + if (isCI) { + addTmpToGitignore(); + } + + // `nx reset` kills the daemon, and performs + // some work which can help clean up e2e leftovers + await runNxCommandAsync('reset'); + }); + + it('should set NX_VERBOSE_LOGGING to true', async () => { + expect(process.env['NX_VERBOSE_LOGGING']).toBe('true'); + }, 120000); + + it('should use dsl option when initiating the workspace', async () => { + // Making sure the package.json file contains the @jnxplus/nx-gradle dependency + const packageJson = readJson('package.json'); + expect(packageJson.devDependencies['@jnxplus/nx-gradle']).toBeTruthy(); + + // Making sure the nx.json file contains the @jnxplus/nx-gradle inside the plugins section + const nxJson = readJson('nx.json'); + expect(nxJson.plugins.includes('@jnxplus/nx-gradle')).toBeTruthy(); + + expect(() => + checkFilesExist( + 'gradle/wrapper/gradle-wrapper.jar', + 'gradle/wrapper/gradle-wrapper.properties', + 'gradlew', + 'gradlew.bat', + 'gradle.properties', + 'settings.gradle.kts', + 'tools/linters/checkstyle.xml' + ) + ).not.toThrow(); + + expect(() => + checkFilesExist( + `node_modules/@jnxplus/tools/linters/checkstyle/checkstyle-${checkstyleVersion}-all.jar`, + `node_modules/@jnxplus/tools/linters/ktlint/ktlint` + ) + ).not.toThrow(); + }, 120000); + + it('shoud works', async () => { + const name = uniq('app-'); + + await runNxCommandAsync(`generate @jnxplus/nx-gradle:app ${name}`); + }, 240000); +}); diff --git a/testing-projects/e2e/nx-gradle-catalog-e2e/tsconfig.json b/testing-projects/e2e/nx-gradle-catalog-e2e/tsconfig.json new file mode 100644 index 000000000..b36041a2a --- /dev/null +++ b/testing-projects/e2e/nx-gradle-catalog-e2e/tsconfig.json @@ -0,0 +1,10 @@ +{ + "extends": "../../../tsconfig.base.json", + "files": [], + "include": [], + "references": [ + { + "path": "./tsconfig.spec.json" + } + ] +} diff --git a/testing-projects/e2e/nx-gradle-catalog-e2e/tsconfig.spec.json b/testing-projects/e2e/nx-gradle-catalog-e2e/tsconfig.spec.json new file mode 100644 index 000000000..5936dfcb1 --- /dev/null +++ b/testing-projects/e2e/nx-gradle-catalog-e2e/tsconfig.spec.json @@ -0,0 +1,9 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "outDir": "../../../dist/out-tsc", + "module": "commonjs", + "types": ["jest", "node"] + }, + "include": ["**/*.test.ts", "**/*.spec.ts", "**/*.d.ts"] +}