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/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..af0ecb765 --- /dev/null +++ b/packages/nx-gradle/src/generators/init/files/gradle/catalog/kotlin-multiplatform/libs.versions.toml @@ -0,0 +1,18 @@ +[versions] +java = "<%= javaVersion %>" +kotlin = "<%= kotlinVersion %>" +agp = "<%= agpVersion %>" +compose = "<%= composeVersion %>" +ktlint = "<%= ktlintVersion %>" + +[libraries] + +[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/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..31d210470 --- /dev/null +++ b/packages/nx-gradle/src/generators/init/files/gradle/catalog/spring-boot/libs.versions.toml @@ -0,0 +1,14 @@ +[versions] +java = "<%= javaVersion %>" +kotlin = "<%= kotlinVersion %>" +boot = "<%= springBootVersion %>" + +[libraries] + +[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 %> 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/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" ] } 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); +});