Skip to content

Commit

Permalink
Merge pull request #25501 from mshima/spring-boot-dependencies-bom
Browse files Browse the repository at this point in the history
inject springDependencies using spring-boot-dependencies bom file
  • Loading branch information
DanielFran authored Mar 16, 2024
2 parents a2dde89 + 5124c94 commit ff6f51f
Show file tree
Hide file tree
Showing 13 changed files with 3,053 additions and 39 deletions.
62 changes: 62 additions & 0 deletions .github/workflows/update-spring-boot-dependencies.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#
# Copyright the original author or authors from the JHipster project.
#
# This file is part of the JHipster project, see https://www.jhipster.tech/
# for more information.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

name: update spring-boot-dependencies bom
on:
workflow_dispatch:
inputs:
springBootVersion:
description: 'Spring Boot version'
required: true
type: string

permissions:
contents: read

jobs:
build:
permissions:
contents: write # for peter-evans/create-pull-request to create branch
pull-requests: write # for peter-evans/create-pull-request to create a PR
name: update spring-boot-dependencies bom
if: github.repository == 'jhipster/generator-jhipster'
runs-on: ubuntu-latest
steps:
- uses: actions/setup-node@v4
with:
node-version: 20
- uses: actions/checkout@v4
- uses: jhipster/actions/setup-git@v0
- uses: jhipster/actions/restore-cache@v0
with:
npm: true
- name: Create commit
run: |
wget -O spring-boot-dependencies.pom https://repo1.maven.org/maven2/org/springframework/boot/spring-boot-dependencies/${{ inputs.springBootVersion }}/spring-boot-dependencies-${{ inputs.springBootVersion }}.pom
git add .
git commit -a -m "update spring-boot-dependencies bom to v${{ inputs.springBootVersion }}"
working-directory: generators/spring-boot/resources
- name: Create Pull Request
uses: peter-evans/create-pull-request@v6
with:
token: ${{ secrets.GITHUB_TOKEN }}
commit-message: 'update spring-boot-dependencies bom to v${{ inputs.springBootVersion }}'
title: 'update spring-boot-dependencies bom to v${{ inputs.springBootVersion }}'
body: update spring-boot-dependencies bom to v${{ inputs.springBootVersion }}
labels: 'theme: dependencies'
12 changes: 6 additions & 6 deletions generators/app/__snapshots__/generator.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,6 @@ exports[`generator - app with default config should match snapshot 1`] = `
"archunit-junit5": "'ARCHUNIT-JUNIT-5-VERSION'",
"awaitility": "'AWAITILITY-VERSION'",
"blockhound-junit-platform": "'BLOCKHOUND-JUNIT-PLATFORM-VERSION'",
"cassandra": "'CASSANDRA-VERSION'",
"checkstyle": "'CHECKSTYLE-VERSION'",
"checksum-maven-plugin": "'CHECKSUM-MAVEN-PLUGIN-VERSION'",
"common-custom-user-data-gradle-plugin": "'COMMON-CUSTOM-USER-DATA-GRADLE-PLUGIN-VERSION'",
Expand All @@ -487,10 +486,10 @@ exports[`generator - app with default config should match snapshot 1`] = `
"h2": "'H-2-VERSION'",
"hazelcast-hibernate53": "'HAZELCAST-HIBERNATE-53-VERSION'",
"hazelcast-spring": "'HAZELCAST-SPRING-VERSION'",
"hibernate": "'HIBERNATE-VERSION'",
"jackson-databind-nullable": "'JACKSON-DATABIND-NULLABLE-VERSION'",
"jacoco-maven-plugin": "'JACOCO-MAVEN-PLUGIN-VERSION'",
"jaxb-runtime": "'JAXB-RUNTIME-VERSION'",
"jhipster-dependabot": "'JHIPSTER-DEPENDABOT-VERSION'",
"jib-maven-plugin": "'JIB-MAVEN-PLUGIN-VERSION'",
"junit-platform-launcher": "'JUNIT-PLATFORM-LAUNCHER-VERSION'",
"lifecycle-mapping": "'LIFECYCLE-MAPPING-VERSION'",
Expand Down Expand Up @@ -730,6 +729,7 @@ exports[`generator - app with default config should match snapshot 1`] = `
"skipJhipsterDependencies": undefined,
"skipServer": undefined,
"skipUserManagement": false,
"springBootDependencies": Any<Object>,
"srcMainDir": "src/main/",
"srcMainJava": "src/main/java/",
"srcMainResources": "src/main/resources/",
Expand Down Expand Up @@ -1040,7 +1040,6 @@ exports[`generator - app with gateway should match snapshot 1`] = `
"archunit-junit5": "'ARCHUNIT-JUNIT-5-VERSION'",
"awaitility": "'AWAITILITY-VERSION'",
"blockhound-junit-platform": "'BLOCKHOUND-JUNIT-PLATFORM-VERSION'",
"cassandra": "'CASSANDRA-VERSION'",
"checkstyle": "'CHECKSTYLE-VERSION'",
"checksum-maven-plugin": "'CHECKSUM-MAVEN-PLUGIN-VERSION'",
"common-custom-user-data-gradle-plugin": "'COMMON-CUSTOM-USER-DATA-GRADLE-PLUGIN-VERSION'",
Expand All @@ -1058,10 +1057,10 @@ exports[`generator - app with gateway should match snapshot 1`] = `
"h2": "'H-2-VERSION'",
"hazelcast-hibernate53": "'HAZELCAST-HIBERNATE-53-VERSION'",
"hazelcast-spring": "'HAZELCAST-SPRING-VERSION'",
"hibernate": "'HIBERNATE-VERSION'",
"jackson-databind-nullable": "'JACKSON-DATABIND-NULLABLE-VERSION'",
"jacoco-maven-plugin": "'JACOCO-MAVEN-PLUGIN-VERSION'",
"jaxb-runtime": "'JAXB-RUNTIME-VERSION'",
"jhipster-dependabot": "'JHIPSTER-DEPENDABOT-VERSION'",
"jib-maven-plugin": "'JIB-MAVEN-PLUGIN-VERSION'",
"junit-platform-launcher": "'JUNIT-PLATFORM-LAUNCHER-VERSION'",
"lifecycle-mapping": "'LIFECYCLE-MAPPING-VERSION'",
Expand Down Expand Up @@ -1302,6 +1301,7 @@ exports[`generator - app with gateway should match snapshot 1`] = `
"skipJhipsterDependencies": undefined,
"skipServer": undefined,
"skipUserManagement": false,
"springBootDependencies": Any<Object>,
"srcMainDir": "src/main/",
"srcMainJava": "src/main/java/",
"srcMainResources": "src/main/resources/",
Expand Down Expand Up @@ -1611,7 +1611,6 @@ exports[`generator - app with microservice should match snapshot 1`] = `
"archunit-junit5": "'ARCHUNIT-JUNIT-5-VERSION'",
"awaitility": "'AWAITILITY-VERSION'",
"blockhound-junit-platform": "'BLOCKHOUND-JUNIT-PLATFORM-VERSION'",
"cassandra": "'CASSANDRA-VERSION'",
"checkstyle": "'CHECKSTYLE-VERSION'",
"checksum-maven-plugin": "'CHECKSUM-MAVEN-PLUGIN-VERSION'",
"common-custom-user-data-gradle-plugin": "'COMMON-CUSTOM-USER-DATA-GRADLE-PLUGIN-VERSION'",
Expand All @@ -1629,10 +1628,10 @@ exports[`generator - app with microservice should match snapshot 1`] = `
"h2": "'H-2-VERSION'",
"hazelcast-hibernate53": "'HAZELCAST-HIBERNATE-53-VERSION'",
"hazelcast-spring": "'HAZELCAST-SPRING-VERSION'",
"hibernate": "'HIBERNATE-VERSION'",
"jackson-databind-nullable": "'JACKSON-DATABIND-NULLABLE-VERSION'",
"jacoco-maven-plugin": "'JACOCO-MAVEN-PLUGIN-VERSION'",
"jaxb-runtime": "'JAXB-RUNTIME-VERSION'",
"jhipster-dependabot": "'JHIPSTER-DEPENDABOT-VERSION'",
"jib-maven-plugin": "'JIB-MAVEN-PLUGIN-VERSION'",
"junit-platform-launcher": "'JUNIT-PLATFORM-LAUNCHER-VERSION'",
"lifecycle-mapping": "'LIFECYCLE-MAPPING-VERSION'",
Expand Down Expand Up @@ -1816,6 +1815,7 @@ exports[`generator - app with microservice should match snapshot 1`] = `
"skipJhipsterDependencies": undefined,
"skipServer": undefined,
"skipUserManagement": true,
"springBootDependencies": Any<Object>,
"srcMainDir": "src/main/",
"srcMainJava": "src/main/java/",
"srcMainResources": "src/main/resources/",
Expand Down
3 changes: 3 additions & 0 deletions generators/app/generator.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ describe(`generator - ${generator}`, () => {
authority: expect.any(Object),
userManagement: expect.any(Object),
jhipsterPackageJson: expect.any(Object),
springBootDependencies: expect.any(Object),
});
});
});
Expand All @@ -79,6 +80,7 @@ describe(`generator - ${generator}`, () => {
userManagement: expect.any(Object),
jhipsterPackageJson: expect.any(Object),
jwtSecretKey: expect.any(String),
springBootDependencies: expect.any(Object),
});
});
});
Expand All @@ -98,6 +100,7 @@ describe(`generator - ${generator}`, () => {
expect(runResult.generator.sharedData.getApplication()).toMatchSnapshot({
jhipsterPackageJson: expect.any(Object),
jwtSecretKey: expect.any(String),
springBootDependencies: expect.any(Object),
});
});
});
Expand Down
2 changes: 0 additions & 2 deletions generators/bootstrap-application-server/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import {
SERVER_TEST_SRC_DIR,
TEST_DIR,
dockerContainers,
javaDependencies,
} from '../generator-constants.js';
import { loadRequiredConfigIntoEntity, prepareEntityPrimaryKeyForTemplates } from '../base-application/support/index.js';
import {
Expand Down Expand Up @@ -86,7 +85,6 @@ export default class BoostrapApplicationServer extends BaseApplicationGenerator
application.packageInfoJavadocs = [];
application.javaDependencies = this.prepareDependencies(
{
...javaDependencies,
...getPomVersionProperties(pomFile!),
...getGradleLibsVersionsProperties(gradleLibsVersions!),
},
Expand Down
21 changes: 0 additions & 21 deletions generators/generator-constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,27 +29,6 @@ export const ADD_SPRING_MILESTONE_REPOSITORY = false;
export const NODE_VERSION = '18.19.1';
export const OPENAPI_GENERATOR_CLI_VERSION = '2.7.0';

/**
* @type {Record<string, string>}
*/
export const javaDependencies = {
/**
* spring-boot version should match the one managed by https://mvnrepository.com/artifact/tech.jhipster/jhipster-dependencies/JHIPSTER_DEPENDENCIES_VERSION
*/
'spring-boot': '3.2.3',
/*
* hibernate version should match the one managed by https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-dependencies/SPRING_BOOT_VERSION
* Required due to hibernate-jpamodelgen annotation processor.
*/
hibernate: '6.4.4.Final',
/*
* cassandra driver version should match the one managed by https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-dependencies/SPRING_BOOT_VERSION
* Required due to java-driver-mapper-processor annotation processor.
*/
cassandra: '4.17.0',
};
Object.freeze(javaDependencies);

// The version should be coherent with the one from spring-data-elasticsearch project
export const ELASTICSEARCH_TAG = '8.10.4';
export const ELASTICSEARCH_IMAGE = 'docker.elastic.co/elasticsearch/elasticsearch';
Expand Down
10 changes: 8 additions & 2 deletions generators/maven/support/dependabot-maven.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,15 @@ export function getPomProperties(pomContent: string): Record<string, string> {
* @param pomContent
*/
export function getPomVersionProperties(pomContent: string): Record<string, string> {
return Object.fromEntries(
Object.entries(getPomProperties(pomContent))
const { properties, version, artifactId }: { properties: Record<string, string>; version: string; artifactId: string } =
new XMLParser().parse(pomContent).project;
const versions = Object.fromEntries(
Object.entries(properties)
.filter(([property]) => property.endsWith('.version'))
.map(([property, value]) => [property.slice(0, -8), value]),
);
if (version && artifactId) {
versions[artifactId] = version;
}
return versions;
}
4 changes: 2 additions & 2 deletions generators/server/templates/gradle.properties.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ springBootVersion=<%- javaDependencies['spring-boot'] %>
<%_ if (databaseTypeSql && !reactive) { _%>
# The hibernate version should match the one managed by
# https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-dependencies/<%- javaDependencies['spring-boot'] %> -->
hibernateVersion=<%- javaDependencies.hibernate %>
hibernateVersion=<%- springBootDependencies.hibernate %>
<%_ } _%>
mapstructVersion=<%- javaDependencies.mapstruct %>
archunitJunit5Version=<%- javaDependencies['archunit-junit5'] %>
Expand All @@ -46,7 +46,7 @@ jaxbRuntimeVersion=<%- javaDependencies['jaxb-runtime'] %>
<%_ if (databaseTypeCassandra) { _%>
# The cassandra driver version should match the one managed by
# https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-dependencies/<%- javaDependencies['spring-boot'] %>
cassandraDriverVersion=<%- javaDependencies.cassandra %>
cassandraDriverVersion=<%- springBootDependencies['cassandra-driver'] %>
<%_ } _%>

# gradle plugin version
Expand Down
1 change: 1 addition & 0 deletions generators/server/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ export type SpringBootApplication = JavaApplication &
DatabaseTypeApplication &
MessageBrokerApplicationType & {
jhipsterDependenciesVersion: string;
springBootDependencies: Record<string, string>;
dockerContainers: Record<string, string>;

addSpringMilestoneRepository: boolean;
Expand Down
16 changes: 15 additions & 1 deletion generators/spring-boot/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/
import os from 'node:os';
import chalk from 'chalk';
import { sortedUniqBy } from 'lodash-es';
import { kebabCase, sortedUniqBy } from 'lodash-es';
import BaseApplicationGenerator from '../base-application/index.js';
import {
GENERATOR_SERVER,
Expand Down Expand Up @@ -56,6 +56,7 @@ import {
websocketTypes,
} from '../../jdl/index.js';
import { writeFiles as writeEntityFiles } from './entity-files.js';
import { getPomVersionProperties } from '../maven/support/index.js';

const { CAFFEINE, EHCACHE, HAZELCAST, INFINISPAN, MEMCACHED, REDIS, NO: NO_CACHE } = cacheTypes;
const { NO: NO_WEBSOCKET, SPRING_WEBSOCKET } = websocketTypes;
Expand Down Expand Up @@ -181,6 +182,19 @@ export default class SpringBootGenerator extends BaseApplicationGenerator {

get preparing() {
return this.asPreparingTaskGroup({
loadSpringBootBom({ application }) {
const pomFile = this.readTemplate(this.jhipsterTemplatePath('../resources/spring-boot-dependencies.pom'))?.toString();
if (this.useVersionPlaceholders) {
application.javaDependencies!['spring-boot'] = "'SPRING-BOOT-VERSION'";
application.springBootDependencies = {};
} else {
application.springBootDependencies = this.prepareDependencies(
getPomVersionProperties(pomFile!),
value => `'${kebabCase(value).toUpperCase()}-VERSION'`,
);
application.javaDependencies!['spring-boot'] = application.springBootDependencies['spring-boot-dependencies'];
}
},
prepareForTemplates({ application }) {
const SPRING_BOOT_VERSION = application.javaDependencies!['spring-boot'];
application.addSpringMilestoneRepository =
Expand Down
Loading

0 comments on commit ff6f51f

Please sign in to comment.