I'm using JHipster and when I run sudo mvn liquibase:diff
I get the below error
[INFO] Settings
----------------------------
[INFO] driver: org.postgresql.Driver
[INFO] url: jdbc:postgresql://localhost/gastos8
[INFO] username: gastos8
[INFO] password: *****
[INFO] use empty password: false
[INFO] properties file: null
[INFO] properties file will override? false
[INFO] prompt on non-local database? true
[INFO] clear checksums? false
[INFO] changeLogFile: src/main/resources/config/liquibase/master.xml
[INFO] context(s): null
[INFO] label(s): null
[INFO] referenceDriver: null
[INFO] referenceUrl: hibernate:spring:com.cboujon.domain?dialect=org.hibernate.dialect.PostgreSQL82Dialect
[INFO] referenceUsername: null
[INFO] referencePassword: null
[INFO] referenceDefaultSchema: null
[INFO] diffChangeLogFile: src/main/resources/config/liquibase/changelog/20150807132702_changelog.xml
[INFO] ------------------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 9.554s
[INFO] Finished at: Fri Aug 07 13:27:12 ART 2015
[INFO] Final Memory: 18M/179M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.liquibase:liquibase-maven-plugin:3.3.2:diff (default-cli) on project gastos8: Error setting up or running Liquibase: liquibase.exception.DatabaseException: org.postgresql.util.PSQLException: FATAL: password authentication failed for user "gastos8" -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
I don't know why the [INFO] username: gastos8
.
That is my config file:
application-dev.yml
spring:
profiles:
active: dev
datasource:
dataSourceClassName: org.postgresql.ds.PGSimpleDataSource
url:
databaseName: gastos8
serverName: localhost
username: postgres
password: ---
jpa:
database-platform: org.hibernate.dialect.PostgreSQL9Dialect
database: POSTGRESQL
openInView: false
show_sql: true
generate-ddl: false
hibernate:
ddl-auto: none
naming-strategy: org.hibernate.cfg.EJB3NamingStrategy
properties:
hibernate.cache.use_second_level_cache: true
hibernate.cache.use_query_cache: false
hibernate.generate_statistics: true
hibernate.cache.region.factory_class: org.hibernate.cache.ehcache.SingletonEhCacheRegionFactory
What am I doing wrong?
Liquibase maven plugin does not read application.yml to know how to connect to your database, it has its own configuration in your pom.xml. So you have to put it there.
Why are you executing maven with sudo? Now, you probably have project files owned by root, it's usually a bad idea.
As said in the accepted answer, maven doesn't read application.yml.
But if you're uncomfortable with having database configuration in your maven liquibase plugin definition, you can use maven properties and a liquibase configuration file.
1 - In your liquibase-maven-plugin
configuration, add a propertyFile
:
<plugin>
<groupId>org.liquibase</groupId>
<artifactId>liquibase-maven-plugin</artifactId>
<version>${liquibase.version}</version>
<configuration>
<propertyFileWillOverride>true</propertyFileWillOverride>
<propertyFile>src/main/resources/liquibase.properties</propertyFile>
</configuration>
(...)
</plugin>
2 - Create the liquibase properties files anywhere under src/main/resources. For instance, src/main/resources/config/liquibase :
contexts:${liquibase.contexts}
changeLogFile:src/main/resources/config/liquibase/master.xml
driver:${dataSource.project.driverClass}
url:${dataSource.project.jdbcURL}
username:${dataSource.project.user}
password:${dataSource.project.password}
verbose:true
dropFirst:false
3 - Tell maven to filter your liquibase properties files to replace values by maven properties. In <build>
, ask maven to filter your liquibase configuration file :
<build>
<resources>
<resource>
<directory>src/main/resources/config/liquibase</directory>
<filtering>true</filtering>
</resource>
</resources>
(...)
</build>
4 - Add maven properties for each profile allowed to launch liquibase goals :
<profile>
<id>dev</id>
(...)
<properties>
<liquibase.contexts></liquibase.contexts>
<dataSource.project.driverClass>org.mariadb.jdbc.Driver</dataSource.project.driverClass>
<dataSource.project.jdbcURL>jdbc:mariadb://localhost:3306/yourDatabaseName</dataSource.project.jdbcURL>
<dataSource.project.user>${datasource.username}</dataSource.project.user>
<dataSource.project.password>${datasource.password}</dataSource.project.password>
</properties>
</profile>
5 - Launch liquibase goals with maven and set credentials in the command line :
mvn resources:resources liquibase:update -Pdev -Ddatasource.username=root -Ddatasource.password=root
Source : Liquibase Maven Documentation
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With