Skip to content

Commit

Permalink
Merge pull request #25504 from mshima/relational
Browse files Browse the repository at this point in the history
inject db gradle dependencies using api
  • Loading branch information
DanielFran committed Mar 17, 2024
2 parents a0662da + 968a9fd commit c039cb5
Show file tree
Hide file tree
Showing 17 changed files with 119 additions and 386 deletions.
41 changes: 18 additions & 23 deletions generators/java/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import { entityServerFiles, enumFiles } from './entity-files.js';
import { getEnumInfo } from '../base-application/support/index.js';
import { mutateData } from '../base/support/index.js';
import { javaBeanCase } from '../server/support/index.js';
import type { JavaArtifact } from './types.js';

export default class JavaGenerator extends BaseApplicationGenerator {
packageInfoFile!: boolean;
Expand Down Expand Up @@ -93,34 +94,28 @@ export default class JavaGenerator extends BaseApplicationGenerator {
prepareJavaApplication({ application, source }) {
source.addJavaDependencies = dependencies => {
if (application.buildToolMaven) {
const unversionedAnnotationProcessors = dependencies.filter(dep => !dep.version && dep.scope === 'annotationProcessor');
const versionedAnnotationProcessors = dependencies.filter(dep => dep.version && dep.scope === 'annotationProcessor');
const unversionedCommonDependencies = dependencies.filter(dep => !dep.version && dep.scope !== 'annotationProcessor');
const versionedCommonDependencies = dependencies.filter(dep => dep.version && dep.scope !== 'annotationProcessor');
const annotationProcessors = dependencies.filter(dep => dep.scope === 'annotationProcessor');
const importDependencies = dependencies.filter(dep => dep.scope === 'import');
const commonDependencies = dependencies.filter(dep => !['annotationProcessor', 'import'].includes(dep.scope!));
const convertVersionToProp = ({ version, artifactId, ...artifact }: JavaArtifact) => ({
...artifact,
artifactId,
version: version ? `\${${artifactId}.version}` : undefined,
});

source.addMavenDefinition?.({
properties: [
...versionedCommonDependencies.map(({ artifactId, version }) => ({ property: `${artifactId}.version`, value: version })),
...versionedAnnotationProcessors.map(({ artifactId, version }) => ({ property: `${artifactId}.version`, value: version })),
],
properties: dependencies
.filter(dep => dep.version)
.map(({ artifactId, version }) => ({ property: `${artifactId}.version`, value: version })),
dependencies: [
...unversionedCommonDependencies,
...versionedCommonDependencies.map(({ version: _version, artifactId, ...artifact }) => ({
...artifact,
artifactId,
version: `\${${artifactId}.version}`,
})),
...commonDependencies.map(convertVersionToProp),
// Add a provided scope for annotation processors so that version is not required in annotationProcessor dependencies
...unversionedAnnotationProcessors.map(({ scope: _scope, ...artifact }) => ({ ...artifact, scope: 'provided' })),
],
annotationProcessors: [
...unversionedAnnotationProcessors.map(({ scope: _scope, ...artifact }) => ({ ...artifact })),
...versionedAnnotationProcessors.map(({ version: _version, artifactId, ...artifact }) => ({
...artifact,
artifactId,
version: `\${${artifactId}.version}`,
})),
...annotationProcessors
.filter(dep => !dep.version)
.map(({ scope: _scope, ...artifact }) => ({ ...artifact, scope: 'provided' })),
],
dependencyManagement: importDependencies.map(convertVersionToProp),
annotationProcessors: annotationProcessors.map(convertVersionToProp).map(({ scope: _scope, ...artifact }) => artifact),
});
}

Expand Down
1 change: 0 additions & 1 deletion generators/liquibase/support/maven-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ export default function mavenPluginContent({
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
<version>\${spring-boot.version}</version>
</dependency>` : ''}${devDatabaseTypeH2Any? `
<dependency>
<groupId>com.h2database</groupId>
Expand Down
108 changes: 2 additions & 106 deletions generators/server/templates/build.gradle.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -164,25 +164,13 @@ repositories {

dependencies {
// Allows unversioned annotationProcessor
annotationProcessor platform("tech.jhipster:jhipster-dependencies:<%- jhipsterDependenciesVersion %>")
annotationProcessor platform(libs.jhipster.dependencies)

<%_ if (databaseTypeCouchbase) { _%>
implementation "com.couchbase.client:java-client"
<%_ } _%>
<%_ if (databaseTypeSql && !reactive) { _%>
implementation "com.fasterxml.jackson.datatype:jackson-datatype-hibernate6"
<%_ } _%>
implementation "com.fasterxml.jackson.datatype:jackson-datatype-hppc"
implementation "com.fasterxml.jackson.datatype:jackson-datatype-jsr310"
<%_ if (databaseTypeSql) { _%>
implementation "com.fasterxml.jackson.module:jackson-module-jaxb-annotations"
<%_ } _%>
<%_ if (authenticationTypeOauth2) { _%>
implementation "com.github.ben-manes.caffeine:caffeine"
<%_ } _%>
<%_ if (databaseTypeCouchbase) { _%>
implementation "com.github.differentway:couchmove"
<%_ } _%>
<%_ if ((applicationTypeMicroservice || applicationTypeGateway) && reactive) { _%>
implementation "com.playtika.reactivefeign:feign-reactor-cloud"
<%_ } _%>
Expand All @@ -198,54 +186,16 @@ dependencies {
testRuntimeOnly("com.tngtech.archunit:archunit-junit5-engine:${archunitJunit5Version}") {
exclude group: "org.slf4j", module: "slf4j-api"
}
<%_ if (databaseTypeSql) { _%>
implementation "com.zaxxer:HikariCP"
<%_ } _%>
<%_ if (databaseTypeSql && reactive) { _%>
implementation "commons-beanutils:commons-beanutils:${commonsBeanutilsVersion}"
<%_ } _%>
<%_ if (databaseTypeCouchbase) { _%>
implementation "commons-codec:commons-codec"
<%_ } _%>
<%_ if (databaseTypeNeo4j && !databaseMigrationLiquibase) { _%>
implementation "eu.michael-simons.neo4j:neo4j-migrations-spring-boot-starter"
<%_ } _%>
implementation "io.dropwizard.metrics:metrics-core"
implementation "io.micrometer:micrometer-registry-prometheus"
<%_ if (databaseTypeMongodb) { _%>
// Fix Mongock dependencies: https://github.com/mongock/mongock-jdk17/issues/6
implementation "io.mongock:mongock-springboot-v3", {
exclude group: "org.reflections", module: "reflections"
}
<%_ } _%>
<%_ if (databaseTypeMongodb && reactive) { _%>
implementation "io.mongock:mongodb-reactive-driver"
<%_ } _%>
<%_ if (databaseTypeMongodb) { _%>
// Fix Mongock dependencies: https://github.com/mongock/mongock-jdk17/issues/6
implementation "io.mongock:mongodb-springdata-v4-driver", {
exclude group: "org.reflections", module: "reflections"
}
<%_ } _%>
<%_ if (reactive) { _%>
runtimeOnly "io.netty:netty-tcnative-boringssl-static"
<%_ } _%>
<%_ if (reactive) { _%>
testImplementation "io.projectreactor.tools:blockhound-junit-platform:${blockhoundJunitPlatformVersion}"
<%_ } _%>
implementation "jakarta.annotation:jakarta.annotation-api"
<%_ if (searchEngineElasticsearch) { _%>
testImplementation "org.apache.commons:commons-collections4"
<%_ } _%>
implementation "org.apache.commons:commons-lang3"
<%_ if (searchEngineElasticsearch) { _%>
testImplementation "org.awaitility:awaitility"
<%_ } _%>
<%_ if (databaseTypeSql && !reactive) { _%>
implementation "org.hibernate.orm:hibernate-core"
annotationProcessor "org.hibernate.orm:hibernate-jpamodelgen:${hibernateVersion}"
implementation "org.hibernate.validator:hibernate-validator"
<%_ } _%>
<%_ if (reactive) { _%>
testRuntimeOnly 'org.junit.platform:junit-platform-launcher:${junitPlatformLauncherVersion}'
<%_ } _%>
Expand All @@ -254,37 +204,13 @@ dependencies {
<%_ if (enableSwaggerCodegen) { _%>
implementation "org.openapitools:jackson-databind-nullable:${jacksonDatabindNullableVersion}"
<%_ } _%>
<%_ if (databaseTypeMongodb) { _%>
implementation "org.reflections:reflections:0.10.1", {
exclude group: "org.javassist", module: "javassist"
}
<%_ } _%>
annotationProcessor "org.springframework.boot:spring-boot-configuration-processor:${springBootVersion}"
annotationProcessor "org.springframework.boot:spring-boot-configuration-processor"
implementation "org.springframework.boot:spring-boot-loader-tools"
<%_ /* This is useful for major Spring Boot migration */
if (addSpringMilestoneRepository) { _%>
runtimeOnly "org.springframework.boot:spring-boot-properties-migrator"
<%_ } _%>
implementation "org.springframework.boot:spring-boot-starter-actuator"
<%_ if (databaseTypeMongodb || databaseTypeCouchbase) { _%>
implementation "org.springframework.boot:spring-boot-starter-data-<%= databaseType %><% if (reactive) { %>-reactive<% } %>"
<%_ } _%>
<%_ if (searchEngineElasticsearch) { _%>
implementation "org.springframework.boot:spring-boot-starter-data-elasticsearch"
<%_ } _%>
<%_ if (databaseTypeSql && !reactive) { _%>
implementation "org.springframework.boot:spring-boot-starter-data-jpa"
<%_ } _%>
<%_ if (databaseTypeMongodb && reactive) { _%>
implementation "org.springframework.boot:spring-boot-starter-data-mongodb"
<%_ } _%>
<%_ if (databaseTypeNeo4j) { _%>
implementation "org.springframework.boot:spring-boot-starter-data-neo4j"
<%_ } _%>
<%_ if (databaseTypeSql && reactive) { _%>
implementation "org.springframework.boot:spring-boot-starter-data-r2dbc"
implementation "jakarta.persistence:jakarta.persistence-api"
<%_ } _%>
implementation "org.springframework.boot:spring-boot-starter-logging"
implementation "org.springframework.boot:spring-boot-starter-mail"
<%_ if (authenticationTypeOauth2) { _%>
Expand All @@ -305,9 +231,6 @@ if (addSpringMilestoneRepository) { _%>
implementation "org.springframework.boot:spring-boot-starter-validation"
<%_ } _%>
implementation "org.springframework.boot:spring-boot-starter-web<% if (reactive) { %>flux<% } %>"
<%_ if (communicationSpringWebsocket) { _%>
implementation "org.springframework.boot:spring-boot-starter-websocket"
<%_ } _%>
testImplementation "org.springframework.boot:spring-boot-test"
<%_ if (applicationTypeMicroservice || applicationTypeGateway) { _%>
implementation "org.springframework.cloud:spring-cloud-starter"
Expand Down Expand Up @@ -341,35 +264,8 @@ if (addSpringMilestoneRepository) { _%>
<%_ } _%>
<%_ if (applicationTypeMicroservice || applicationTypeGateway) { _%>
implementation "org.springframework.retry:spring-retry"
<%_ } _%>
<%_ if (!reactive && databaseTypeSql) { _%>
implementation "org.springframework.security:spring-security-data"
<%_ } _%>
<%_ if (communicationSpringWebsocket) { _%>
implementation "org.springframework.security:spring-security-messaging"
<%_ } _%>
testImplementation "org.springframework.security:spring-security-test"
<%_ if (databaseTypeCouchbase) { _%>
testImplementation "org.testcontainers:couchbase"
<%_ } _%>
<%_ if (searchEngineElasticsearch) { _%>
testImplementation "org.testcontainers:elasticsearch"
<%_ } _%>
<%_ if (databaseTypeSql) { _%>
testImplementation "org.testcontainers:jdbc"
<%_ } _%>
<%_ if (databaseTypeMongodb || databaseTypeCouchbase || databaseTypeNeo4j || searchEngineElasticsearch || databaseTypeSql) { _%>
testImplementation "org.testcontainers:junit-jupiter"
<%_ } _%>
<%_ if (databaseTypeMongodb) { _%>
testImplementation "org.testcontainers:mongodb"
<%_ } _%>
<%_ if (databaseTypeNeo4j) { _%>
testImplementation "org.testcontainers:neo4j"
<%_ } _%>
<%_ if (databaseTypeMongodb || databaseTypeCouchbase || databaseTypeNeo4j || searchEngineElasticsearch || databaseTypeSql) { _%>
testImplementation "org.testcontainers:testcontainers"
<%_ } _%>
<%_ if (reactive) { _%>
OperatingSystem os = org.gradle.nativeplatform.platform.internal.DefaultNativePlatform.getCurrentOperatingSystem();
Architecture arch = org.gradle.nativeplatform.platform.internal.DefaultNativePlatform.getCurrentArchitecture();
Expand Down
9 changes: 0 additions & 9 deletions generators/server/templates/gradle.properties.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,11 @@ rootProject.name=<%= dasherizedBaseName %>
profile=dev

# Dependency versions
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=<%- springBootDependencies.hibernate %>
<%_ } _%>
mapstructVersion=<%- javaDependencies.mapstruct %>
archunitJunit5Version=<%- javaDependencies['archunit-junit5'] %>
<%_ if (enableSwaggerCodegen) { _%>
jacksonDatabindNullableVersion=<%- javaDependencies['jackson-databind-nullable'] %>
<%_ } _%>
<%_ if (databaseTypeSql && reactive) { _%>
commonsBeanutilsVersion=<%- javaDependencies['commons-beanutils'] %>
<%_ } _%>
<%_ if (reactive) { _%>
blockhoundJunitPlatformVersion=<%- javaDependencies['blockhound-junit-platform'] %>
junitPlatformLauncherVersion=<%- javaDependencies['junit-platform-launcher'] %>
Expand Down
10 changes: 1 addition & 9 deletions generators/server/templates/gradle/profile_dev.gradle.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,6 @@ sourceSets {
configurations {
all {
resolutionStrategy {
<%_ if (!reactive) { _%>
// TODO drop forced version. Refer to https://github.com/jhipster/generator-jhipster/issues/22579
force "org.hibernate.orm:hibernate-core:${hibernateVersion}"
<%_ if (enableHibernateCache && (cacheProviderEhcache || cacheProviderCaffeine || cacheProviderRedis)) { _%>
// TODO drop forced version. Refer to https://github.com/jhipster/generator-jhipster/issues/22579
force "org.hibernate.orm:hibernate-jcache:${hibernateVersion}"
<%_ } _%>
<%_ } _%>
<%_ if (prodDatabaseDriver?.r2dbc?.version) { _%>
force "<%- prodDatabaseDriver.r2dbc.groupId %>:<%- prodDatabaseDriver.r2dbc.artifactId %>:<%- prodDatabaseDriver.r2dbc.version %>"
<%_ } _%>
Expand All @@ -49,7 +41,7 @@ configurations {
}
dependencies {
developmentOnly "org.springframework.boot:spring-boot-devtools:${springBootVersion}"
compileOnly "org.springframework.boot:spring-boot-devtools"
<%_ if (devDatabaseTypeH2Any && !reactive) { _%>
implementation "com.h2database:h2"
<%_ } _%>
Expand Down
8 changes: 0 additions & 8 deletions generators/server/templates/gradle/profile_prod.gradle.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,6 @@ sourceSets {
configurations {
all {
resolutionStrategy {
<%_ if (!reactive) { _%>
// TODO drop forced version. Refer to https://github.com/jhipster/generator-jhipster/issues/22579
force "org.hibernate.orm:hibernate-core:${hibernateVersion}"
<%_ if (enableHibernateCache && (cacheProviderEhcache || cacheProviderCaffeine || cacheProviderRedis)) { _%>
// TODO drop forced version. Refer to https://github.com/jhipster/generator-jhipster/issues/22579
force "org.hibernate.orm:hibernate-jcache:${hibernateVersion}"
<%_ } _%>
<%_ } _%>
<%_ if (prodDatabaseDriver?.r2dbc?.version) { _%>
force "<%- prodDatabaseDriver.r2dbc.groupId %>:<%- prodDatabaseDriver.r2dbc.artifactId %>:<%- prodDatabaseDriver.r2dbc.version %>"
<%_ } _%>
Expand Down
7 changes: 5 additions & 2 deletions generators/server/templates/pom.xml.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,11 @@
<artifactId>spring-security-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>

<build>
Expand Down Expand Up @@ -456,7 +461,6 @@
<path>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<version>${spring-boot.version}</version>
</path>
<path>
<groupId>org.mapstruct</groupId>
Expand Down Expand Up @@ -826,7 +830,6 @@
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>${spring-boot.version}</version>
<executions>
<execution>
<goals>
Expand Down
50 changes: 7 additions & 43 deletions generators/spring-boot/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -401,56 +401,20 @@ public void set${javaBeanCase(propertyName)}(${propertyType} ${propertyName}) {
get postWriting() {
return this.asPostWritingTaskGroup({
addJHipsterBomDependencies({ application, source }) {
if (application.buildToolMaven) {
source.addMavenProperty?.({
property: 'spring-boot.version',
value: application.javaDependencies!['spring-boot'],
});
source.addMavenDependencyManagement?.({
source.addJavaDependencies?.([
{
groupId: 'tech.jhipster',
artifactId: 'jhipster-dependencies',
// eslint-disable-next-line no-template-curly-in-string
version: '${jhipster-dependencies.version}',
version: application.jhipsterDependenciesVersion,
type: 'pom',
scope: 'import',
});
source.addMavenDefinition?.({
properties: [{ property: 'jhipster-dependencies.version', value: application.jhipsterDependenciesVersion }],
dependencies: [{ groupId: 'tech.jhipster', artifactId: 'jhipster-framework' }],
});
}

if (application.buildToolGradle) {
source.addGradleDependencyCatalogLibraries?.([
{
libraryName: 'jhipster-dependencies',
module: 'tech.jhipster:jhipster-dependencies',
version: application.jhipsterDependenciesVersion!,
scope: 'implementation platform',
},
]);
source.addGradleDependency?.({
groupId: 'tech.jhipster',
artifactId: 'jhipster-framework',
scope: 'implementation',
});
}
},
{ groupId: 'tech.jhipster', artifactId: 'jhipster-framework' },
]);
},
addSpringdoc({ application, source }) {
const springdocDependency = `springdoc-openapi-starter-${application.reactive ? 'webflux' : 'webmvc'}-api`;
if (application.buildToolMaven) {
source.addMavenDefinition?.({
dependencies: [{ groupId: 'org.springdoc', artifactId: springdocDependency }],
});
}

if (application.buildToolGradle) {
source.addGradleDependency?.({
groupId: 'org.springdoc',
artifactId: springdocDependency,
scope: 'implementation',
});
}
source.addJavaDependencies?.([{ groupId: 'org.springdoc', artifactId: springdocDependency }]);
},
addSpringSnapshotRepository({ application, source }) {
if (application.buildToolMaven) {
Expand Down
Loading

0 comments on commit c039cb5

Please sign in to comment.