mvn liquibase:generateChangeLog not working with an URL problem - spring

I don't understand something with Liquibase and Spring Boot.
When I run my spring boot project with : mvn spring-boot:run
My changelog-v1.0.xml create a table and add two users inside my table user. So my liquibase is linked to my mySQL Database with success. But ... I don't know why, I can't used mvn liquibase command without failure.
Exemple, I want to save my database using :
mvn liquibase:generateChangeLog
But I have that log failure :
Failed to execute goal org.liquibase:liquibase-maven-plugin:4.9.0:generateChangeLog (default-cli) on project demo: The database URL has not been specified either as a parameter or in a properties file.
I think, when i'm using the command line, he don't use my configuration inside pox.xml but I don't know how to do that.
# pom.xml
<plugin>
<groupId>org.liquibase</groupId>
<artifactId>liquibase-maven-plugin</artifactId>
<version>4.9.0</version>
<configuration>
<propertyFileWillOverride>true</propertyFileWillOverride>
<promptOnNonLocalDatabase>false</promptOnNonLocalDatabase>
<ChangeLogFile>src/main/resources/db/changelog/changelog-master.xml</ChangeLogFile>
<driver>${spring.datasource.driverClassName}</driver>
<url>${spring.datasource.url}</url>
<username>${spring.datasource.username}</username>
<password>${spring.datasource.password}</password>
</configuration>
<dependencies>
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.3.0</version>
</dependency>
</dependencies>
</plugin>
My pom.xml is correctly setup because new changelog file inside liquibase directory create or update my data from my mysql database.

mvn liquibase:generateChangeLog does not depend on spring, so it is not going to read the spring file. You can either create a liquibase.properties file and reference it.
I changed the pom to reference a properties file
https://docs.liquibase.com/tools-integrations/maven/maven-pom-file.html
and then changed the changeLogFile configuration to use outputChangeLogFile like this:
<outputChangeLogFile>src/main/resources/db/changelog/changelog-master.xml</outputChangeLogFile>

Related

Athena latest JDBC driver jar AthenaJDBC42_2.0.14

https://docs.aws.amazon.com/athena/latest/ug/connect-with-jdbc.html
I've installed latest jdbc jar into my local mvn repo. While i'm trying to build my project I'm getting below error.
Failed to collect dependencies at Athena:AthenaJDBC42:jar:2.0.14.1000: Failed to read artifact descriptor for Athena:AthenaJDBC42:jar:2.0.14.1000: 1 problem was encountered while building the effective model for Athena:AthenaJDBC${env.JDBC_V}:${env.MAJOR_V}.${env.MINOR_V}.${env.REVISION_V}.${env.BUILD_V}
[ERROR] [ERROR] 'artifactId' with value 'AthenaJDBC${env.JDBC_V}' does not match a valid id pattern. #
Anyone have any idea, how to resolve this error.?
It is difficult to say with just the small Maven error snippet, but it looks like Maven doesn't recognize the property ${env.JDBC_V} or it contains some invalid value like a space.
I recommend to generate a Maven effective pom model (mvn help~effective-pom) and execute Maven in debug mode (mvn -X ...) to try to troubleshoot the cause.
I was facing the same error. It got resolved when I installed jar into repository using following command. (Ensure you deleted all existing instances of athena drivers jar files from .m2 before executing command)
mvn install:install-file -Dfile=/Users/chetanparekh/Downloads/AthenaJDBC42_2.0.14.jar -DgroupId=Athena -DartifactId=AthenaJDBC42 -Dversion=2.0.14.1000 -Dpackaging=jar
Snippet from my POM.
<build>
<plugins>
<plugin>
<groupId>org.mule.tools.maven</groupId>
<artifactId>mule-maven-plugin</artifactId>
<version>${mule.maven.plugin.version}</version>
<extensions>true</extensions>
<configuration>
<sharedLibraries>
<sharedLibrary>
<groupId>Athena</groupId>
<artifactId>AthenaJDBC42</artifactId>
</sharedLibrary>
</sharedLibraries>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>Athena</groupId>
<artifactId>AthenaJDBC42</artifactId>
<version>2.0.14.1000</version>
</dependency>
</dependencies>
Thank you for your answer.
I finally resolved it using
mvn install:install-file -Dfile=/Users/dk/Downloads/AthenaJDBC42_2.0.14.jar -DgroupId=Athena -DartifactId=AthenaJDBC42 -Dversion=2.0.14
Removed the build version(1000) and -Dpackaing=jar, it worked. I'm not sure what could be the problem with build version .1000 and -Dpacking=jar.
Thanks Again.!

What is the difference between Flyway Core and Flyway Maven Plugin?

I am using Flyway in my Spring-Boot project (in Eclipse with maven) with
<dependency>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-core</artifactId>
</dependency>
and I ran into some interesting issues.
The whole thing worked fine until I failed a migration (because of a typo in the schema syntax). I tried to run fly:repair and I got this error
Failed to execute goal org.flywaydb:flyway-maven-plugin:6.4.1:repair (default-cli) on project springboot: org.flywaydb.core.api.FlywayException: Unable to connect to the database. Configure the url, user and password!
Now, the curious thing I do not understand is that if I add all the information into pom.xml
<properties>
<flyway.user>databaseUser</flyway.user>
<flyway.password>databasePassword</flyway.password>
<flyway.url>urlAddress</flyway.url>
</properties>
it builds. But if I add the information to my application.properties file
spring.flyway.user=databaseUser
spring.flyway.password=databasePassword
spring.flyway.url=urlAddress
the same error message occurs.
According to Baedlung Database Migrations with Flyway (they are using Flyway Maven Plugin), it does not matter where you configure Flyway.
So I wonder if I should switch to flyway-maven-plugin? I would really like to have all configuration in the .properties file.
First thing: Flyway-core for database migration by Java programming code.
<dependency>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-core</artifactId>
<version>7.0.0</version>
</dependency>
import org.flywaydb.core.Flyway;
...
Flyway flyway = Flyway.configure().dataSource(url, user, password).load();
flyway.migrate();
// Start the rest of the application (incl. Hibernate)
...
Second thing: Flyway-plugin for Maven goal, run by command-line.
<plugin>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-maven-plugin</artifactId>
<version>4.0.3</version>
</plugin>
and
mvn clean flyway:migrate -Dflyway.configFile=myFlywayConfig.properties
You can choose first thing or second thing, depend on your preference (Database migration by Java code or by command)

flyway - why can't switch to a newly created schema?

I'm having a go with flyway and it looks promising. So, on the root project's pom.xml file, I have this:
<plugin>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-maven-plugin</artifactId>
<version>${flyway.version}</version>
<configuration>
<driver>com.microsoft.sqlserver.jdbc.SQLServerDriver</driver>
<url>jdbc:sqlserver://localhost</url>
<user>sa</user>
<password>dbPassword/</password>
<schemas>
<schema>schemaA</schema>
<schema>schemaB</schema>
</schemas>
</configuration>
<dependencies>
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>mssql-jdbc</artifactId>
<version>${mssql.version}</version>
</dependency>
</dependencies>
</plugin>
On projectA's and projectB's pom.xml, I have this:
<dependency>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-core</artifactId>
<version>${flyway.version}</version>
</dependency>
Also, on each project's application.properties there is the following:
#flyway
flyway.baseline-description= #
flyway.baseline-version=1 # version to start migration
flyway.baseline-on-migrate= #
flyway.check-location=false # Check that migration scripts location exists.
flyway.clean-on-validation-error= #
flyway.enabled=true # Enable flyway.
#flyway.encoding= #
#flyway.ignore-failed-future-migration= #
#flyway.init-sqls= # SQL statements to execute to initialize a connection immediately after obtaining it.
flyway.locations=classpath:db/migration
#flyway.out-of-order= #
#flyway.placeholder-prefix= #
#flyway.placeholder-replacement= #
#flyway.placeholder-suffix= #
#flyway.placeholders.*= #
flyway.schemas=schemaX
#flyway.sql-migration-prefix=V #
#flyway.sql-migration-separator= #
#flyway.sql-migration-suffix=.sql #
flyway.table= #
flyway.url=jdbc:sqlserver://localhost
flyway.user=sa
flyway.password=dbPassword
flyway.validate-on-migrate= #
So, in order to try make it work, here's what I do:
create schemaA and schemaB on the database using user sa and password dbPassword.
place at location [projectA]/src/main/resources/db/migration/m a file V1_0_Initialize.sql which is creates the structure of the tables and populates with standardized data.
try to run with the following command: mvn clean flyway:migrate -DskipTests
On step 3, I get the error message:
[INFO] Current version of schema [dbo.schemaA]: null
[INFO] Migrating schema [dbo.schemaA] to version 1.0 - Initialize
And after a few lines:
[ERROR] Message : The specified schema name "dbo.schemaA" either does not exist or you do not have permission to use it.
If I try to import the script using the DBMS, everything works perfectly.
What am I not seering?
Kind regards,

Add maven build time to jar name build with Spring Boot Maven Plugin

How can add maven build time to jar file name using Spring Boot Maven plugin?
I want to achieve something like: jar_name-build_time.jar
By default, Spring Boot Maven Plugin builds jar file with name ${project.build.finalName}.
This can be configured with non-required property finalName.
Maven build time can be used as ${maven.build.timestamp}
So, putting all things together, all you need to do is append build time to default jar name:
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>1.5.6.RELEASE</version>
<configuration>
<mainClass>com.marand.thinkmed.meds.config.boot.MedsConfigApplication</mainClass>
<finalName>${project.build.finalName}-${maven.build.timestamp}</finalName>
</configuration>
</plugin>
Also, make sure to change timestamp format so it doesn't violate file naming strategies:
<properties>
<maven.build.timestamp.format>yyyy-MM-dd-HH-mm</maven.build.timestamp.format>
</properties>

Turn off or configure java.util.Logging during Maven build

I want to clean up/unify the log output of a Maven build. Unfortunately, a dependency of a maven plugin uses java.util.Logging (JUL). Simply adding org.slf4j:jul-to-slf4j as an additional dependency to redirect the log output doesn't help. Exclusions also don't work of course, because it's JUL and therefore not a dependency.
Here's my configuration, containing the specific plugin and its dependency:
Configuration
<plugin>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-codegen-plugin</artifactId>
<version>2.7.11</version>
<executions>...</executions>
<configuration>
<defaultOptions>
<extraargs>
<extraarg>-xjc-Xbg</extraarg>
</extraargs>
</defaultOptions>
</configuration>
<dependencies>
<!-- This one uses JUL with logging level WARN -->
<dependency>
<groupId>org.apache.cxf.xjcplugins</groupId>
<artifactId>cxf-xjc-boolean</artifactId>
<version>2.7.0</version>
</dependency>
</dependencies>
</plugin>
Update
I've managed to turn off/configure JUL itself by adding a logging.properties file with the following content to the project's root folder:
# Turn off any java.util.Loggers (or use SEVERE to see problems)
.level=OFF
Additionally, I have to execute Maven with the following parameter (or set it into MAVEN_OPTS):
mvn clean install -Djava.util.logging.config.file=${basedir}/logging.properties
Remaining Question
Is there any way to achieve the same result without extra files and/or JVM parameters (pom.xml only)?
Following configuration for the plugin cxf-codegen-plugin prevented to show DEBUG log entries when building my project with maven:
<configuration>
<fork>once</fork>
<additionalJvmArgs>
-Dorg.apache.cxf.Logger=null
</additionalJvmArgs>
</configuration>
Instead of a properties file or completely disabling all logging as suggested in another answer, you can also set the desired log level like this:
<additionalJvmArgs>-Dorg.apache.cxf.level=OFF</additionalJvmArgs>
The level needs to be one of the java.util.logging.Level.
I was having similar behavior: was getting WARNING messages from CXF 2.6.3 generated webservices classes when running my Struts2 test cases, polluting my test log.
Since the log trace wasn't showing from what package was sended, I was trying to config the wrong package.
I've added this to my setUp() test case method from my test that extends XWorkTestCase (or whatever you need):
public void setUp() throws Exception{
super.setUp();
java.util.logging.Logger.getLogger("org.apache.cxf").setLevel(Level.OFF);
}
Then no more logging messages from CXF appears when I run my tests from maven.

Resources