From 3b1de4c3b03fe0a5f20c1ca7c4aebaca6c2f8fc5 Mon Sep 17 00:00:00 2001 From: khalilou88 Date: Tue, 11 Jul 2023 18:04:09 +0200 Subject: [PATCH 1/4] feat(generators): use version catalog --- .../nx-gradle/src/generators/init/schema.d.ts | 1 + .../nx-gradle/src/generators/init/schema.json | 22 ++++++++++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/packages/nx-gradle/src/generators/init/schema.d.ts b/packages/nx-gradle/src/generators/init/schema.d.ts index 98b287a2a..6918972ca 100644 --- a/packages/nx-gradle/src/generators/init/schema.d.ts +++ b/packages/nx-gradle/src/generators/init/schema.d.ts @@ -7,4 +7,5 @@ export interface NxGradleInitGeneratorSchema { gradleRootDirectory: string; preset: PresetType; skipWrapper?: boolean; + versionManagement: 'properties' | 'version-catalog'; } diff --git a/packages/nx-gradle/src/generators/init/schema.json b/packages/nx-gradle/src/generators/init/schema.json index 5a8a26506..423d37587 100644 --- a/packages/nx-gradle/src/generators/init/schema.json +++ b/packages/nx-gradle/src/generators/init/schema.json @@ -97,6 +97,25 @@ "description": "Don't generate Gradle Wrapper", "type": "boolean", "default": false + }, + "versionManagement": { + "description": "Version management", + "type": "string", + "default": "properties", + "x-prompt": { + "message": "Which version management would you like to use?", + "type": "list", + "items": [ + { + "value": "properties", + "label": "use gradle properties" + }, + { + "value": "version-catalog", + "label": "use version catalog" + } + ] + } } }, "required": [ @@ -104,6 +123,7 @@ "dsl", "rootProjectName", "gradleRootDirectory", - "preset" + "preset", + "versionManagement" ] } From 4fa75bcc491dce67d6d34210e5c40e0739a4379d Mon Sep 17 00:00:00 2001 From: khalilou88 Date: Tue, 11 Jul 2023 18:33:48 +0200 Subject: [PATCH 2/4] build: work in progress --- .../kotlin-multiplatform/libs.versions.toml | 5 + .../catalog/micronaut/libs.versions.toml | 5 + .../gradle/catalog/none/libs.versions.toml | 5 + .../gradle/catalog/quarkus/libs.versions.toml | 5 + .../catalog/spring-boot/libs.versions.toml | 5 + .../src/generators/init/generator.ts | 9 ++ .../e2e/nx-gradle-catalog-e2e/jest.config.js | 17 +++ .../e2e/nx-gradle-catalog-e2e/project.json | 18 +++ .../tests/nx-gradle-catalog.spec.ts | 139 ++++++++++++++++++ .../e2e/nx-gradle-catalog-e2e/tsconfig.json | 10 ++ .../nx-gradle-catalog-e2e/tsconfig.spec.json | 9 ++ 11 files changed, 227 insertions(+) create mode 100644 packages/nx-gradle/src/generators/init/files/gradle/catalog/kotlin-multiplatform/libs.versions.toml create mode 100644 packages/nx-gradle/src/generators/init/files/gradle/catalog/micronaut/libs.versions.toml create mode 100644 packages/nx-gradle/src/generators/init/files/gradle/catalog/none/libs.versions.toml create mode 100644 packages/nx-gradle/src/generators/init/files/gradle/catalog/quarkus/libs.versions.toml create mode 100644 packages/nx-gradle/src/generators/init/files/gradle/catalog/spring-boot/libs.versions.toml create mode 100644 testing-projects/e2e/nx-gradle-catalog-e2e/jest.config.js create mode 100644 testing-projects/e2e/nx-gradle-catalog-e2e/project.json create mode 100644 testing-projects/e2e/nx-gradle-catalog-e2e/tests/nx-gradle-catalog.spec.ts create mode 100644 testing-projects/e2e/nx-gradle-catalog-e2e/tsconfig.json create mode 100644 testing-projects/e2e/nx-gradle-catalog-e2e/tsconfig.spec.json 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 ee4d040a0..e1249682b 100644 --- a/packages/nx-gradle/src/generators/init/generator.ts +++ b/packages/nx-gradle/src/generators/init/generator.ts @@ -84,6 +84,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"] +} From c0bec7a3a2ce464c56f4baaad072ed58c506e0b9 Mon Sep 17 00:00:00 2001 From: khalilou88 Date: Wed, 12 Jul 2023 12:39:37 +0200 Subject: [PATCH 3/4] build: work in progress --- .../kotlin-multiplatform/libs.versions.toml | 15 ++++++++++++++- .../gradle/catalog/spring-boot/libs.versions.toml | 11 ++++++++++- .../files/gradle/config/kmp/gradle.properties | 6 +++--- 3 files changed, 27 insertions(+), 5 deletions(-) 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 index 6ed4ba908..af0ecb765 100644 --- 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 @@ -1,5 +1,18 @@ [versions] +java = "<%= javaVersion %>" +kotlin = "<%= kotlinVersion %>" +agp = "<%= agpVersion %>" +compose = "<%= composeVersion %>" +ktlint = "<%= ktlintVersion %>" [libraries] -[plugins] \ No newline at end of file +[plugins] +kotlin-jvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" } +kotlin-multiplatform = { id = "org.jetbrains.kotlin.multiplatform", version.ref = "kotlin" } +kotlin-android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" } +android-application = { id = "com.android.application", version.ref = "agp" } +android-library = { id = "com.android.library", version.ref = "agp" } +jetbrains-compose = { id = "org.jetbrains.compose", version.ref = "compose" } +github-khalilou88-jnxplus = { id = "io.github.khalilou88.jnxplus", version.ref = "<%= jnxplusGradlePluginVersion %>" } + 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 index 6ed4ba908..31d210470 100644 --- 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 @@ -1,5 +1,14 @@ [versions] +java = "<%= javaVersion %>" +kotlin = "<%= kotlinVersion %>" +boot = "<%= springBootVersion %>" [libraries] -[plugins] \ No newline at end of file +[plugins] +springframework-boot = { id = "org.springframework.boot", version.ref = "boot" } +spring-dependency-management = { id = "io.spring.dependency-management", version = "1.1.0" } +github-khalilou88-jnxplus = { id = "io.github.khalilou88.jnxplus", version = "0.2.0" } +jetbrains-kotlin-plugin-spring = { id = "org.jetbrains.kotlin.plugin.spring", version.ref = "kotlin" } +jetbrains-kotlin-jvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" } + diff --git a/packages/nx-gradle/src/generators/init/files/gradle/config/kmp/gradle.properties b/packages/nx-gradle/src/generators/init/files/gradle/config/kmp/gradle.properties index dd8994f2a..0909fd4ee 100644 --- a/packages/nx-gradle/src/generators/init/files/gradle/config/kmp/gradle.properties +++ b/packages/nx-gradle/src/generators/init/files/gradle/config/kmp/gradle.properties @@ -21,9 +21,9 @@ android.minSdk=24 #Versions javaVersion=<%= javaVersion %> -kotlin.version=1.8.20 -agp.version=7.4.2 -compose.version=1.4.1 +kotlin.version=<%= kotlinVersion %> +agp.version=<%= agpVersion %> +compose.version=<%= composeVersion %> jnxplusGradlePluginVersion=<%= jnxplusGradlePluginVersion %> From 3fcafcafc8ba71ca54688b0454da85d5d5b28de1 Mon Sep 17 00:00:00 2001 From: khalilou88 Date: Thu, 30 Nov 2023 17:27:36 +0100 Subject: [PATCH 4/4] build: work in progress --- .github/workflows/plugin-e2e.yml | 1 + .../e2e/nx-gradle-catalog-e2e/jest.config.js | 17 --- .../e2e/nx-gradle-catalog-e2e/project.json | 18 --- .../tests/nx-gradle-catalog.spec.ts | 139 ------------------ .../e2e/nx-gradle-catalog-e2e/tsconfig.json | 10 -- .../nx-gradle-catalog-e2e/tsconfig.spec.json | 9 -- .../tests/nx-gradle/nx-gradle-catalog.spec.ts | 83 +++++++++++ 7 files changed, 84 insertions(+), 193 deletions(-) delete mode 100644 testing-projects/e2e/nx-gradle-catalog-e2e/jest.config.js delete mode 100644 testing-projects/e2e/nx-gradle-catalog-e2e/project.json delete mode 100644 testing-projects/e2e/nx-gradle-catalog-e2e/tests/nx-gradle-catalog.spec.ts delete mode 100644 testing-projects/e2e/nx-gradle-catalog-e2e/tsconfig.json delete mode 100644 testing-projects/e2e/nx-gradle-catalog-e2e/tsconfig.spec.json create mode 100644 testing-projects/jnxplus-e2e/tests/nx-gradle/nx-gradle-catalog.spec.ts diff --git a/.github/workflows/plugin-e2e.yml b/.github/workflows/plugin-e2e.yml index 0aff79ad0..84016b6a7 100644 --- a/.github/workflows/plugin-e2e.yml +++ b/.github/workflows/plugin-e2e.yml @@ -14,6 +14,7 @@ on: - nx-gradle micronaut e2e - nx-gradle micronaut kotlin dsl e2e - nx-gradle all e2e + - nx-gradle version-catalog e2e - nx-gradle all kotlin dsl e2e - nx-gradle quarkus e2e - nx-gradle quarkus kotlin dsl e2e diff --git a/testing-projects/e2e/nx-gradle-catalog-e2e/jest.config.js b/testing-projects/e2e/nx-gradle-catalog-e2e/jest.config.js deleted file mode 100644 index bd6f350d3..000000000 --- a/testing-projects/e2e/nx-gradle-catalog-e2e/jest.config.js +++ /dev/null @@ -1,17 +0,0 @@ -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 deleted file mode 100644 index 691026ae2..000000000 --- a/testing-projects/e2e/nx-gradle-catalog-e2e/project.json +++ /dev/null @@ -1,18 +0,0 @@ -{ - "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 deleted file mode 100644 index 3f79a675e..000000000 --- a/testing-projects/e2e/nx-gradle-catalog-e2e/tests/nx-gradle-catalog.spec.ts +++ /dev/null @@ -1,139 +0,0 @@ -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 deleted file mode 100644 index b36041a2a..000000000 --- a/testing-projects/e2e/nx-gradle-catalog-e2e/tsconfig.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "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 deleted file mode 100644 index 5936dfcb1..000000000 --- a/testing-projects/e2e/nx-gradle-catalog-e2e/tsconfig.spec.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "extends": "./tsconfig.json", - "compilerOptions": { - "outDir": "../../../dist/out-tsc", - "module": "commonjs", - "types": ["jest", "node"] - }, - "include": ["**/*.test.ts", "**/*.spec.ts", "**/*.d.ts"] -} diff --git a/testing-projects/jnxplus-e2e/tests/nx-gradle/nx-gradle-catalog.spec.ts b/testing-projects/jnxplus-e2e/tests/nx-gradle/nx-gradle-catalog.spec.ts new file mode 100644 index 000000000..d35cddd2d --- /dev/null +++ b/testing-projects/jnxplus-e2e/tests/nx-gradle/nx-gradle-catalog.spec.ts @@ -0,0 +1,83 @@ +import { + addTmpToGitignore, + createTestWorkspace, + removeTmpFromGitignore, +} from '@jnxplus/internal/testing'; +import { + checkFilesExist, + readJson, + runNxCommandAsync, + uniq, +} from '@nx/plugin/testing'; +import { execSync } from 'child_process'; +import { rmSync } from 'fs'; + +describe('nx-gradle version-catalog e2e', () => { + let workspaceDirectory: string; + const isCI = + process.env.CI === 'true' || process.env.GITHUB_ACTIONS === 'true'; + const rootProjectName = uniq('root-project-'); + + beforeAll(async () => { + workspaceDirectory = createTestWorkspace(); + + // The plugin has been built and published to a local registry in the jest globalSetup + // Install the plugin built with the latest source code into the test repo + execSync(`npm install -D @jnxplus/nx-gradle@e2e`, { + cwd: workspaceDirectory, + stdio: 'inherit', + env: process.env, + }); + + 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(); + } + // Cleanup the test project + rmSync(workspaceDirectory, { + recursive: true, + force: true, + }); + }); + + 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(); + }, 120000); + + it('shoud works', async () => { + const name = uniq('app-'); + + await runNxCommandAsync(`generate @jnxplus/nx-gradle:app ${name}`); + }, 240000); +});