From 71debad9c79be80e5cf8d7e9a40925e2a8ebf1ce Mon Sep 17 00:00:00 2001 From: Frederik Hahne Date: Tue, 12 Dec 2023 23:45:26 +0100 Subject: [PATCH 1/3] [gradle] generate initial files for convention plugin usage udpates 19615 --- generators/git/templates/.gitignore.jhi.ejs | 2 ++ .../gradle/__snapshots__/generator.spec.js.snap | 6 ++++++ generators/gradle/files.ts | 2 +- generators/gradle/generator.ts | 3 +++ generators/gradle/internal/needles.ts | 6 ++++++ generators/gradle/needles.spec.ts | 5 +++++ generators/gradle/templates/buildSrc/build.gradle.ejs | 11 +++++++++++ generators/gradle/types.d.ts | 1 + 8 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 generators/gradle/templates/buildSrc/build.gradle.ejs diff --git a/generators/git/templates/.gitignore.jhi.ejs b/generators/git/templates/.gitignore.jhi.ejs index dd56626b707b..7a412246ff75 100644 --- a/generators/git/templates/.gitignore.jhi.ejs +++ b/generators/git/templates/.gitignore.jhi.ejs @@ -79,6 +79,8 @@ out/ ###################### .gradle/ /build/ +/buildSrc/.gradle/ +/buildSrc/build/ ###################### # Package Files diff --git a/generators/gradle/__snapshots__/generator.spec.js.snap b/generators/gradle/__snapshots__/generator.spec.js.snap index 72044f263c10..3f8da453990e 100644 --- a/generators/gradle/__snapshots__/generator.spec.js.snap +++ b/generators/gradle/__snapshots__/generator.spec.js.snap @@ -5,6 +5,9 @@ exports[`generator - gradle with empty configuration should generate only gradle ".yo-rc.json": { "stateCleared": "modified", }, + "buildSrc/build.gradle": { + "stateCleared": "modified" + } "gradle/wrapper/gradle-wrapper.jar": { "stateCleared": "modified", }, @@ -25,6 +28,9 @@ exports[`generator - gradle with valid configuration should generate only gradle ".yo-rc.json": { "stateCleared": "modified", }, + "buildSrc/build.gradle": { + "stateCleared": "modified" + } "gradle/wrapper/gradle-wrapper.jar": { "stateCleared": "modified", }, diff --git a/generators/gradle/files.ts b/generators/gradle/files.ts index 89644403eb11..a0f6c6b09d6b 100644 --- a/generators/gradle/files.ts +++ b/generators/gradle/files.ts @@ -20,7 +20,7 @@ export default { gradle: [ { - templates: ['.prettierignore.jhi.gradle', 'gradle/wrapper/gradle-wrapper.properties'], + templates: ['.prettierignore.jhi.gradle', 'gradle/wrapper/gradle-wrapper.properties', 'buildSrc/build.gradle'], }, { transform: false, diff --git a/generators/gradle/generator.ts b/generators/gradle/generator.ts index df9af5c6d939..b5926baf1316 100644 --- a/generators/gradle/generator.ts +++ b/generators/gradle/generator.ts @@ -32,6 +32,7 @@ import { addGradlePluginCallback, addGradlePluginManagementCallback, addGradlePropertyCallback, + addGradleBuildSrcDependencyCallback, } from './internal/needles.js'; export default class GradleGenerator extends BaseApplicationGenerator { @@ -73,6 +74,8 @@ export default class GradleGenerator extends BaseApplicationGenerator { source.addGradleMavenRepository = repository => this.editFile('build.gradle', addGradleMavenRepositoryCallback(repository)); source.addGradlePluginManagement = plugin => this.editFile('settings.gradle', addGradlePluginManagementCallback(plugin)); source.addGradleProperty = property => this.editFile('gradle.properties', addGradlePropertyCallback(property)); + source.addGradleBuildSrcDependency = dependency => + this.editFile('buildSrc/build.gradle', addGradleBuildSrcDependencyCallback(dependency)); }, }); } diff --git a/generators/gradle/internal/needles.ts b/generators/gradle/internal/needles.ts index db748c6c898c..cf1b4e09fb7e 100644 --- a/generators/gradle/internal/needles.ts +++ b/generators/gradle/internal/needles.ts @@ -31,6 +31,12 @@ export const addGradleDependencyCallback = ({ groupId, artifactId, version, scop contentToAdd: `${scope} "${groupId}:${artifactId}${version ? `:${version}` : ''}"`, }); +export const addGradleBuildSrcDependencyCallback = ({ groupId, artifactId, version, scope }: GradleDependency) => + createNeedleCallback({ + needle: 'gradle-build-src-dependency', + contentToAdd: `${scope} "${groupId}:${artifactId}${version ? `:${version}` : ''}"`, + }); + export const addGradlePluginCallback = ({ id, version }: GradlePlugin) => createNeedleCallback({ needle: 'gradle-plugins', diff --git a/generators/gradle/needles.spec.ts b/generators/gradle/needles.spec.ts index b1fff842b1c2..7c8e970d2ad9 100644 --- a/generators/gradle/needles.spec.ts +++ b/generators/gradle/needles.spec.ts @@ -18,6 +18,7 @@ class mockBlueprintSubGen extends BaseApplicationGenerator { source.addGradleDependency?.({ scope: 'scope4', groupId: 'group4', artifactId: 'name4' }); source.applyFromGradle?.({ script: 'name.gradle' }); source.addGradleMavenRepository?.({ url: 'url', username: 'username', password: 'password' }); + source.addGradleBuildSrcDependency?.({ scope: 'scope5', groupId: 'group5', artifactId: 'name5', version: 'version5' }); }, }); } @@ -71,4 +72,8 @@ describe('needle API server gradle: JHipster server generator with blueprint', ( ' }', ); }); + + it('Assert buildSrc/build.gradle has the Dependency with version added', () => { + runResult.assertFileContent('buildSrc/build.gradle', 'scope5 "group5:name5:version5"'); + }); }); diff --git a/generators/gradle/templates/buildSrc/build.gradle.ejs b/generators/gradle/templates/buildSrc/build.gradle.ejs new file mode 100644 index 000000000000..71395bf948e7 --- /dev/null +++ b/generators/gradle/templates/buildSrc/build.gradle.ejs @@ -0,0 +1,11 @@ +plugins { + id 'groovy-gradle-plugin' +} + +repositories { + gradlePluginPortal() +} + +dependencies { + // jhipster-needle-gradle-build-src-dependency - JHipster will add additional dependencies for convention plugins here +} \ No newline at end of file diff --git a/generators/gradle/types.d.ts b/generators/gradle/types.d.ts index 9bba609e4dee..7d083cb91878 100644 --- a/generators/gradle/types.d.ts +++ b/generators/gradle/types.d.ts @@ -15,4 +15,5 @@ export type GradleSourceType = { addGradlePluginManagement?(pluginManagement: GradlePlugin): void; addGradleProperty?(property: GradleProperty): void; addGradleMavenRepository?(repository: GradleRepository): void; + addGradleBuildSrcDependency?(dependency: GradleDependency): void; }; From 3b115cfb83652a6bcddec731bd845ad29441e920 Mon Sep 17 00:00:00 2001 From: Frederik Hahne Date: Wed, 13 Dec 2023 07:49:22 +0100 Subject: [PATCH 2/3] fix gradle snapshots updates #19615 --- generators/gradle/__snapshots__/generator.spec.js.snap | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/generators/gradle/__snapshots__/generator.spec.js.snap b/generators/gradle/__snapshots__/generator.spec.js.snap index 3f8da453990e..c34c4e44ae3a 100644 --- a/generators/gradle/__snapshots__/generator.spec.js.snap +++ b/generators/gradle/__snapshots__/generator.spec.js.snap @@ -6,8 +6,8 @@ exports[`generator - gradle with empty configuration should generate only gradle "stateCleared": "modified", }, "buildSrc/build.gradle": { - "stateCleared": "modified" - } + "stateCleared": "modified", + }, "gradle/wrapper/gradle-wrapper.jar": { "stateCleared": "modified", }, @@ -29,8 +29,8 @@ exports[`generator - gradle with valid configuration should generate only gradle "stateCleared": "modified", }, "buildSrc/build.gradle": { - "stateCleared": "modified" - } + "stateCleared": "modified", + }, "gradle/wrapper/gradle-wrapper.jar": { "stateCleared": "modified", }, From 9e0c0bded6fe2980d6f5d1ba86d2092039fbb4c3 Mon Sep 17 00:00:00 2001 From: Frederik Hahne Date: Thu, 14 Dec 2023 07:30:47 +0100 Subject: [PATCH 3/3] apply checkstyle dependency resolution workaround updates #19615 --- generators/server/templates/build.gradle.ejs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/generators/server/templates/build.gradle.ejs b/generators/server/templates/build.gradle.ejs index 3c3a7012f7a9..3e671a7090f1 100644 --- a/generators/server/templates/build.gradle.ejs +++ b/generators/server/templates/build.gradle.ejs @@ -235,6 +235,13 @@ configurations { implementation.exclude module: "spring-boot-starter-tomcat" } +// workaround for https://github.com/checkstyle/checkstyle/issues/14123 +configurations.checkstyle { + resolutionStrategy.capabilitiesResolution.withCapability("com.google.collections:google-collections") { + select("com.google.guava:guava:0") + } +} + repositories { // Local maven repository is required for libraries built locally with maven like development jhipster-bom. <%= !jhipsterDependenciesVersion.includes('-SNAPSHOT') && !jhipsterDependenciesVersion.includes('-CICD') ? '// ' : '' %>mavenLocal()