From 61eea707c281517ed815422eba61a3452456da37 Mon Sep 17 00:00:00 2001 From: Marcelo Shima Date: Sat, 30 Mar 2024 08:37:02 -0300 Subject: [PATCH] enable renovate for gradle-wrapper --- .../bootstrap-application-server/generator.ts | 2 - generators/gradle/constants.js | 1 - generators/gradle/files.ts | 10 +---- generators/gradle/generator.spec.js | 18 ++++++--- generators/gradle/generator.ts | 39 +++++++++++++++++++ ...operties.ejs => gradle-wrapper.properties} | 2 +- generators/gradle/types.d.ts | 1 + generators/server/templates/build.gradle.ejs | 4 -- renovate.json | 2 +- 9 files changed, 57 insertions(+), 22 deletions(-) rename generators/gradle/templates/gradle/wrapper/{gradle-wrapper.properties.ejs => gradle-wrapper.properties} (85%) diff --git a/generators/bootstrap-application-server/generator.ts b/generators/bootstrap-application-server/generator.ts index 99876f1fc288..d0ed63e61655 100644 --- a/generators/bootstrap-application-server/generator.ts +++ b/generators/bootstrap-application-server/generator.ts @@ -43,7 +43,6 @@ import { getGradleLibsVersionsProperties } from '../gradle/support/index.js'; import { getPomVersionProperties } from '../maven/support/index.js'; import { prepareField as prepareFieldForLiquibaseTemplates } from '../liquibase/support/index.js'; import { getDockerfileContainers } from '../docker/utils.js'; -import { GRADLE_VERSION } from '../gradle/constants.js'; import { normalizePathEnd } from '../base/support/path.js'; import { getFrontendAppName, mutateData } from '../base/support/index.js'; import { getMainClassName } from '../java/support/index.js'; @@ -73,7 +72,6 @@ export default class BoostrapApplicationServer extends BaseApplicationGenerator loadConfig(serverCommand.configs, { config: this.jhipsterConfigWithDefaults, application }); loadServerConfig({ config: this.jhipsterConfigWithDefaults, application }); - (application as any).gradleVersion = this.useVersionPlaceholders ? 'GRADLE_VERSION' : GRADLE_VERSION; application.javaVersion = this.useVersionPlaceholders ? 'JAVA_VERSION' : JAVA_VERSION; application.backendType = this.jhipsterConfig.backendType ?? 'Java'; diff --git a/generators/gradle/constants.js b/generators/gradle/constants.js index 234fe133b4c1..a4d3d13a4f62 100644 --- a/generators/gradle/constants.js +++ b/generators/gradle/constants.js @@ -16,7 +16,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -export const GRADLE_VERSION = '8.6'; export const GRADLE = 'gradle'; export const GRADLE_DESCRIPTION = 'Gradle'; export const BUILD_DESTINATION_VALUE = 'build'; diff --git a/generators/gradle/files.ts b/generators/gradle/files.ts index 33c6bcfaea07..07edd18862e8 100644 --- a/generators/gradle/files.ts +++ b/generators/gradle/files.ts @@ -20,17 +20,11 @@ export default { gradle: [ { - templates: [ - '.prettierignore.jhi.gradle', - 'gradle/wrapper/gradle-wrapper.properties', - 'buildSrc/build.gradle', - 'buildSrc/gradle/libs.versions.toml', - 'gradle/libs.versions.toml', - ], + templates: ['.prettierignore.jhi.gradle', 'buildSrc/build.gradle', 'buildSrc/gradle/libs.versions.toml', 'gradle/libs.versions.toml'], }, { transform: false, - templates: ['gradlew', 'gradlew.bat', 'gradle/wrapper/gradle-wrapper.jar'], + templates: ['gradlew', 'gradlew.bat', 'gradle/wrapper/gradle-wrapper.jar', 'gradle/wrapper/gradle-wrapper.properties'], }, ], }; diff --git a/generators/gradle/generator.spec.js b/generators/gradle/generator.spec.js index b98bf9cd1f35..8ee34a1d5518 100644 --- a/generators/gradle/generator.spec.js +++ b/generators/gradle/generator.spec.js @@ -20,7 +20,7 @@ import { basename, dirname, join } from 'path'; import { fileURLToPath } from 'url'; import { before, it, describe, expect } from 'esmocha'; import { testBlueprintSupport } from '../../test/support/tests.js'; -import { defaultHelpers as helpers } from '../../testing/index.js'; +import { defaultHelpers as helpers, runResult } from '../../testing/index.js'; import { GENERATOR_JHIPSTER } from '../generator-constants.js'; import { GENERATOR_GRADLE } from '../generator-list.js'; @@ -35,9 +35,8 @@ describe(`generator - ${generator}`, () => { }); describe('blueprint support', () => testBlueprintSupport(generator)); describe('with valid configuration', () => { - let runResult; before(async () => { - runResult = await helpers.run(generatorFile).withJHipsterConfig({ + await helpers.run(generatorFile).withJHipsterConfig({ baseName: 'existing', packageName: 'tech.jhipster', }); @@ -50,9 +49,8 @@ describe(`generator - ${generator}`, () => { }); }); describe('with empty configuration', () => { - let runResult; before(async () => { - runResult = await helpers.run(generatorFile).withJHipsterConfig(); + await helpers.run(generatorFile).withJHipsterConfig(); }); it('should generate only gradle files', () => { expect(runResult.getStateSnapshot()).toMatchSnapshot(); @@ -61,4 +59,14 @@ describe(`generator - ${generator}`, () => { runResult.assertJsonFileContent('.yo-rc.json', { [GENERATOR_JHIPSTER]: { buildTool: 'gradle' } }); }); }); + + describe('with custom gradleVersion', () => { + const gradleVersion = 'fooVersion'; + before(async () => { + await helpers.run(generatorFile).withSharedApplication({ gradleVersion }).withJHipsterConfig(); + }); + it('should set gradleVersion at gradle-wrapper.properties', () => { + runResult.assertFileContent('gradle/wrapper/gradle-wrapper.properties', `-${gradleVersion}-`); + }); + }); }); diff --git a/generators/gradle/generator.ts b/generators/gradle/generator.ts index 097c38f272db..4c5dfa2129f5 100644 --- a/generators/gradle/generator.ts +++ b/generators/gradle/generator.ts @@ -41,8 +41,11 @@ import { sortDependencies, gradleNeedleOptionsWithDefaults, } from './internal/needles.js'; +import { mutateData } from '../base/support/config.js'; export default class GradleGenerator extends BaseApplicationGenerator { + gradleVersionFromWrapper; + async beforeQueue() { if (!this.fromBlueprint) { await this.composeWithBlueprints(GENERATOR_GRADLE); @@ -69,6 +72,25 @@ export default class GradleGenerator extends BaseApplicationGenerator { return this.delegateTasksToBlueprint(() => this.configuring); } + get loading() { + return this.asLoadingTaskGroup({ + loadGradleVersion({ application }) { + const propFile = this.readTemplate(this.jhipsterTemplatePath('gradle/wrapper/gradle-wrapper.properties')); + this.gradleVersionFromWrapper = propFile?.toString().match(/gradle-(\d+\.\d+(?:\.\d+)?)-/)?.[1]; + if (!this.gradleVersionFromWrapper) { + throw new Error('Could not determine Gradle version from gradle-wrapper.properties'); + } + mutateData(application, { + gradleVersion: this.useVersionPlaceholders ? 'GRADLE_VERSION' : this.gradleVersionFromWrapper, + }); + }, + }); + } + + get [BaseApplicationGenerator.LOADING]() { + return this.delegateTasksToBlueprint(() => this.loading); + } + get preparing() { return this.asPreparingTaskGroup({ async verify({ application }) { @@ -141,4 +163,21 @@ export default class GradleGenerator extends BaseApplicationGenerator { get [BaseApplicationGenerator.WRITING]() { return this.delegateTasksToBlueprint(() => this.writing); } + + get postWriting() { + return this.asPostWritingTaskGroup({ + updateGradleVersion({ application }) { + const { gradleVersion } = application; + if (gradleVersion !== this.gradleVersionFromWrapper) { + this.editFile('gradle/wrapper/gradle-wrapper.properties', content => + content.replace(`-${this.gradleVersionFromWrapper!}-`, `-${gradleVersion!}-`), + ); + } + }, + }); + } + + get [BaseApplicationGenerator.POST_WRITING]() { + return this.delegateTasksToBlueprint(() => this.postWriting); + } } diff --git a/generators/gradle/templates/gradle/wrapper/gradle-wrapper.properties.ejs b/generators/gradle/templates/gradle/wrapper/gradle-wrapper.properties similarity index 85% rename from generators/gradle/templates/gradle/wrapper/gradle-wrapper.properties.ejs rename to generators/gradle/templates/gradle/wrapper/gradle-wrapper.properties index 9699ce996268..17655d0ef2b9 100644 --- a/generators/gradle/templates/gradle/wrapper/gradle-wrapper.properties.ejs +++ b/generators/gradle/templates/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-<%= gradleVersion %>-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/generators/gradle/types.d.ts b/generators/gradle/types.d.ts index afcdff862789..f488f15fb771 100644 --- a/generators/gradle/types.d.ts +++ b/generators/gradle/types.d.ts @@ -56,5 +56,6 @@ export type GradleSourceType = { }; export type GradleApplication = { + gradleVersion?: string; gradleBuildSrc?: string; }; diff --git a/generators/server/templates/build.gradle.ejs b/generators/server/templates/build.gradle.ejs index 1b3be055661b..3253e8aa6b51 100644 --- a/generators/server/templates/build.gradle.ejs +++ b/generators/server/templates/build.gradle.ejs @@ -274,10 +274,6 @@ task cleanResources(type: Delete) { delete "build/resources" } -wrapper { - gradleVersion = "<%= gradleVersion %>" -} - <%_ if (embeddableLaunchScript) { _%> bootJar { diff --git a/renovate.json b/renovate.json index e1a8cfb121ae..17ff71a92d0a 100644 --- a/renovate.json +++ b/renovate.json @@ -1,5 +1,5 @@ { "$schema": "https://docs.renovatebot.com/renovate-schema.json", "extends": ["config:recommended", ":disableDependencyDashboard"], - "enabledManagers": ["maven-wrapper"] + "enabledManagers": ["maven-wrapper", "gradle-wrapper"] }