Skip to content

Commit

Permalink
Merge pull request #22667 from hide212131/fix-gradle-liquibase-execution
Browse files Browse the repository at this point in the history
Fix gradle liquibase execution
  • Loading branch information
DanielFran authored Jun 29, 2023
2 parents a55f15d + f282637 commit 6b35bdf
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 4 deletions.
6 changes: 6 additions & 0 deletions generators/app/__snapshots__/generator.spec.mts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,7 @@ exports[`generator - app with default config should match snapshot 1`] = `
"node-gradle": "'NODE-GRADLE-VERSION'",
"nohttp-checkstyle": "'NOHTTP-CHECKSTYLE-VERSION'",
"openapi-generator-maven-plugin": "'OPENAPI-GENERATOR-MAVEN-PLUGIN-VERSION'",
"picocli": "'PICOCLI-VERSION'",
"properties-maven-plugin": "'PROPERTIES-MAVEN-PLUGIN-VERSION'",
"sonar-maven-plugin": "'SONAR-MAVEN-PLUGIN-VERSION'",
"spring-boot": "'SPRING-BOOT-VERSION'",
Expand Down Expand Up @@ -410,6 +411,7 @@ exports[`generator - app with default config should match snapshot 1`] = `
"rtl": false,
},
],
"liquibaseDefaultSchemaName": "",
"lowercaseBaseName": "jhipster",
"mainClass": "JhipsterApp",
"mainJavaDir": "src/main/java/",
Expand Down Expand Up @@ -903,6 +905,7 @@ exports[`generator - app with gateway should match snapshot 1`] = `
"node-gradle": "'NODE-GRADLE-VERSION'",
"nohttp-checkstyle": "'NOHTTP-CHECKSTYLE-VERSION'",
"openapi-generator-maven-plugin": "'OPENAPI-GENERATOR-MAVEN-PLUGIN-VERSION'",
"picocli": "'PICOCLI-VERSION'",
"properties-maven-plugin": "'PROPERTIES-MAVEN-PLUGIN-VERSION'",
"sonar-maven-plugin": "'SONAR-MAVEN-PLUGIN-VERSION'",
"spring-boot": "'SPRING-BOOT-VERSION'",
Expand Down Expand Up @@ -946,6 +949,7 @@ exports[`generator - app with gateway should match snapshot 1`] = `
"rtl": false,
},
],
"liquibaseDefaultSchemaName": "",
"lowercaseBaseName": "jhipster",
"mainClass": "JhipsterApp",
"mainJavaDir": "src/main/java/",
Expand Down Expand Up @@ -1438,6 +1442,7 @@ exports[`generator - app with microservice should match snapshot 1`] = `
"node-gradle": "'NODE-GRADLE-VERSION'",
"nohttp-checkstyle": "'NOHTTP-CHECKSTYLE-VERSION'",
"openapi-generator-maven-plugin": "'OPENAPI-GENERATOR-MAVEN-PLUGIN-VERSION'",
"picocli": "'PICOCLI-VERSION'",
"properties-maven-plugin": "'PROPERTIES-MAVEN-PLUGIN-VERSION'",
"sonar-maven-plugin": "'SONAR-MAVEN-PLUGIN-VERSION'",
"spring-boot": "'SPRING-BOOT-VERSION'",
Expand Down Expand Up @@ -1481,6 +1486,7 @@ exports[`generator - app with microservice should match snapshot 1`] = `
"rtl": false,
},
],
"liquibaseDefaultSchemaName": "",
"lowercaseBaseName": "jhipster",
"mainClass": "JhipsterApp",
"mainJavaDir": "src/main/java/",
Expand Down
4 changes: 4 additions & 0 deletions generators/liquibase/generator.mts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ export default class LiquibaseGenerator extends BaseApplicationGenerator {

get preparing() {
return this.asPreparingTaskGroup({
preparing({ application }) {
application.liquibaseDefaultSchemaName =
application.databaseTypeSql && application.devDatabaseTypeMysql && application.baseName ? application.baseName : '';
},
checkDatabaseCompatibility({ application }) {
if (!application.databaseTypeSql && !application.databaseTypeNeo4j) {
throw new Error(`Database type ${application.databaseType} is not supported`);
Expand Down
18 changes: 14 additions & 4 deletions generators/liquibase/templates/gradle/liquibase.gradle.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ configurations {
dependencies {
implementation "org.liquibase:liquibase-core"
liquibaseRuntime "org.liquibase:liquibase-core"
// Dependency required to parse options. Refer to https://github.com/liquibase/liquibase-gradle-plugin/tree/Release_2.2.0#news.
liquibaseRuntime "info.picocli:picocli:<%- javaDependencies.picocli %>"
<%_ if (databaseTypeSql && !reactive) { _%>
liquibaseRuntime "org.liquibase.ext:liquibase-hibernate6:${liquibaseHibernate6Version}"
Expand Down Expand Up @@ -49,22 +51,30 @@ liquibase {
driver "<%= devJdbcDriver %>"
url "<%- devLiquibaseUrl %>"
username "<%- devDatabaseUsername %>"
<%_ if (devDatabasePassword) { _%>
password "<%- devDatabasePassword %>"
changeLogFile "<%= SERVER_MAIN_RES_DIR %>config/liquibase/master.xml"
defaultSchemaName "<% if (devDatabaseTypeMysql) { %><%= baseName %><% } else if (devDatabaseTypePostgres) { %><% } %>"
<%_ } _%>
changelogFile "<%= SERVER_MAIN_RES_DIR %>config/liquibase/master.xml"
<%_ if (liquibaseDefaultSchemaName) { _%>
defaultSchemaName "<%- liquibaseDefaultSchemaName %>"
<%_ } _%>
logLevel "debug"
classpath "<%= SERVER_MAIN_RES_DIR %>"
}
diffLog {
driver "<%= devJdbcDriver %>"
url "<%- devLiquibaseUrl %>"
username "<%- devDatabaseUsername %>"
<%_ if (devDatabasePassword) { _%>
password "<%- devDatabasePassword %>"
changeLogFile project.ext.diffChangelogFile
<%_ } _%>
changelogFile project.ext.diffChangelogFile
<%_ if (!reactive) { _%>
referenceUrl "hibernate:spring:<%= packageName %>.domain?dialect=<%= devHibernateDialect %>&hibernate.physical_naming_strategy=org.hibernate.boot.model.naming.CamelCaseToUnderscoresNamingStrategy&hibernate.implicit_naming_strategy=org.springframework.boot.orm.jpa.hibernate.SpringImplicitNamingStrategy"
<%_ } _%>
defaultSchemaName "<% if (devDatabaseTypeMysql) { %><%= baseName %><% } else if (devDatabaseTypePostgres) { %><% } %>"
<%_ if (liquibaseDefaultSchemaName) { _%>
defaultSchemaName "<%- liquibaseDefaultSchemaName %>"
<%_ } _%>
logLevel "debug"
classpath "$buildDir/classes/java/main"
<%_ if (authenticationTypeOauth2) { _%>
Expand Down
6 changes: 6 additions & 0 deletions generators/server/resources/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
<liquibase.version>4.20.0</liquibase.version>
<mapstruct.version>1.5.5.Final</mapstruct.version>
<micrometer-context-propagation.version>1.0.3</micrometer-context-propagation.version>
<picocli.version>4.6.1</picocli.version>
<spring-pulsar.version>0.2.0</spring-pulsar.version>
<typesafe.version>1.4.2</typesafe.version>
<validation-api.version>3.0.2.Final</validation-api.version>
Expand Down Expand Up @@ -127,6 +128,11 @@
<artifactId>mapstruct</artifactId>
<version>${mapstruct.version}</version>
</dependency>
<dependency>
<groupId>info.picocli</groupId>
<artifactId>picocli</artifactId>
<version>${picocli.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.pulsar</groupId>
<artifactId>spring-pulsar-spring-cloud-stream-binder</artifactId>
Expand Down
2 changes: 2 additions & 0 deletions generators/server/types.d.mts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ type ReactiveApplication = {

export type LiquibaseApplication = {
incrementalChangelog: boolean;
liquibaseDefaultSchemaName: string;
};

type DatabaseTypeSqlApplication = (
Expand All @@ -41,6 +42,7 @@ type DatabaseTypeSqlApplication = (
) & {
devDatabaseType: string;
prodDatabaseType: string;
devDatabaseTypeMysql: boolean;
} & LiquibaseApplication;

type DatabaseTypeApplication = DeterministicOptionWithDerivedProperties<
Expand Down

0 comments on commit 6b35bdf

Please sign in to comment.