Skip to content

Commit

Permalink
enable renovate for gradle-wrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
mshima committed Mar 31, 2024
1 parent 979a777 commit 61eea70
Show file tree
Hide file tree
Showing 9 changed files with 57 additions and 22 deletions.
2 changes: 0 additions & 2 deletions generators/bootstrap-application-server/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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';

Expand Down
1 change: 0 additions & 1 deletion generators/gradle/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
10 changes: 2 additions & 8 deletions generators/gradle/files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
},
],
};
18 changes: 13 additions & 5 deletions generators/gradle/generator.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -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',
});
Expand All @@ -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();
Expand All @@ -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}-`);
});
});
});
39 changes: 39 additions & 0 deletions generators/gradle/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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 }) {
Expand Down Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions generators/gradle/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,6 @@ export type GradleSourceType = {
};

export type GradleApplication = {
gradleVersion?: string;
gradleBuildSrc?: string;
};
4 changes: 0 additions & 4 deletions generators/server/templates/build.gradle.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -274,10 +274,6 @@ task cleanResources(type: Delete) {
delete "build/resources"
}

wrapper {
gradleVersion = "<%= gradleVersion %>"
}

<%_ if (embeddableLaunchScript) { _%>
bootJar {
Expand Down
2 changes: 1 addition & 1 deletion renovate.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
"extends": ["config:recommended", ":disableDependencyDashboard"],
"enabledManagers": ["maven-wrapper"]
"enabledManagers": ["maven-wrapper", "gradle-wrapper"]
}

0 comments on commit 61eea70

Please sign in to comment.