configurations {
    liquibaseRuntime.extendsFrom sourceSets.main.compileClasspath
}

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) { _%>
  <%_ if (prodDatabaseType !== devDatabaseType) { _%>
  if (project.hasProperty("prod") || project.hasProperty("gae")) {
  <%_ } _%>
  <%_ if (prodDatabaseTypeMysql) { _%>
  liquibaseRuntime "com.mysql:mysql-connector-j"
  <%_ } _%>
  <%_ if (prodDatabaseTypePostgresql) { _%>
  liquibaseRuntime "org.postgresql:postgresql"
  <%_ } _%>
  <%_ if (prodDatabaseTypeMariadb) { _%>
  liquibaseRuntime "org.mariadb.jdbc:mariadb-java-client"
  <%_ } _%>
  <%_ if (prodDatabaseTypeMssql) { _%>
  liquibaseRuntime "com.microsoft.sqlserver:mssql-jdbc"
  liquibaseRuntime "org.liquibase.ext:liquibase-mssql:${dependencyManagement.importedProperties['liquibase.version']}"
  <%_ } _%>
  <%_ if (prodDatabaseTypeOracle) { _%>
  liquibaseRuntime "com.oracle.database.jdbc:ojdbc8"
  <%_ } _%>
  <%_ if (prodDatabaseType !== devDatabaseType) { _%>
  }
  <%_ } _%>
<%_ } else if (databaseTypeNeo4j) { _%>
  // Exclude current neo4j driver and use the one provided by spring-data
  // See: https://github.com/jhipster/generator-jhipster/pull/24241
  implementation (<%- javaDependencies['liquibase-neo4j'] ? 'libs.liquibase.neo4j' : '"org.liquibase.ext:liquibase-neo4j:${dependencyManagement.importedProperties[\'liquibase.version\']}"' %>) {
    exclude group: "org.neo4j.driver", module: "neo4j-java-driver"
    exclude group: "org.slf4j", module: "*"
  }
  implementation "org.springframework:spring-jdbc"
<%_ } _%>
  // jhipster-needle-gradle-dependency - JHipster will add additional dependencies here
}

project.ext.diffChangelogFile = "<%= srcMainResources %>config/liquibase/changelog/" + new Date().format("yyyyMMddHHmmss") + "_changelog.xml"
if (!project.hasProperty("runList")) {
 project.ext.runList = "main"
}

liquibase {
  activities {
    main {
      driver "<%= devJdbcDriver %>"
      url "<%- devLiquibaseUrl %>"
      username "<%- devDatabaseUsername %>"
<%_ if (devDatabasePassword) { _%>
      password "<%- devDatabasePassword %>"
<%_ } _%>
      changelogFile "<%= srcMainResources %>config/liquibase/master.xml"
<%_ if (liquibaseDefaultSchemaName) { _%>
      defaultSchemaName "<%- liquibaseDefaultSchemaName %>"
<%_ } _%>
      logLevel "debug"
      classpath "<%= srcMainResources %>"
    }
    diffLog {
      driver "<%= devJdbcDriver %>"
      url "<%- devLiquibaseUrl %>"
      username "<%- devDatabaseUsername %>"
<%_ if (devDatabasePassword) { _%>
      password "<%- devDatabasePassword %>"
<%_ } _%>
      changelogFile project.ext.diffChangelogFile
<%_ if (!reactive && backendTypeSpringBoot) { _%>
      referenceUrl "hibernate:spring:<%= packageName %>.domain?dialect=<%= devHibernateDialect %>&hibernate.physical_naming_strategy=<%= locals.hibernateNamingPhysicalStrategy %>&hibernate.implicit_naming_strategy=<%= locals.hibernateNamingImplicitStrategy %>"
<%_ } _%>
<%_ if (liquibaseDefaultSchemaName) { _%>
      defaultSchemaName "<%- liquibaseDefaultSchemaName %>"
<%_ } _%>
      logLevel "debug"
      classpath "$buildDir/classes/java/main"
<%_ if (authenticationTypeOauth2) { _%>
      excludeObjects "oauth_access_token, oauth_approvals, oauth_client_details, oauth_client_token, oauth_code, oauth_refresh_token"
<%_ } _%>
    }
  }

  runList = project.ext.runList
}

liquibaseDiff.dependsOn(compileJava)
liquibaseDiffChangelog.dependsOn(compileJava)
<%_ if (backendTypeSpringBoot) { _%>

ext {
  if (project.hasProperty("no-liquibase")) {
    springProfiles += ",no-liquibase"
  }
}
<%_ } _%>
