I am trying to setup Liquibase in the already exsiting spring boot application. I am using embedded H2 database persisted in a file.
I am using liquibase maven pluging to generate the changelog file. Below is my section of pom.xml containing liquibase maven plugin details.
<plugin>
<groupId>org.liquibase</groupId>
<artifactId>liquibase-maven-plugin</artifactId>
<version>3.4.1</version>
<configuration>
<changeLogFile>
/src/main/resources/liquibase-outputChangeLog.xml
</changeLogFile>
<driver>org.h2.Driver</driver>
<url>jdbc:h2:file:~/taskapp</url>
<username>sa</username>
<password>password</password>
</configuration>
</plugin>
Liquibase dependency
<dependency>
<groupId>org.liquibase</groupId>
<artifactId>liquibase-core</artifactId>
<version>3.4.1</version>
</dependency>
Now i am trying to generate the changelog file by firing the maven command
mvn liquibase:generateChangeLog
But i get the following error in the console
Failed to execute goal org.liquibase:liquibase-maven-plugin:4.9.1:generateChangeLog (default-cli) on project tasklist: The database URL has not been specified either as a parameter or in a properties file.
Best Regards,
Saurav
Related
I'm trying to use JOOQ to generate code files from an existing database in a Spring Boot application. However, when I run the maven plugin, I'm getting the following error:
[ERROR] Failed to execute goal org.jooq:jooq-codegen-maven:3.13.3:generate (default-cli) on project english-learners: Error running jOOQ code generation tool: Your configured database type was not found. This can have several reasons:
[ERROR] - You want to use a commercial jOOQ Edition, but you pulled the Open Source Edition from Maven Central.
[ERROR] - You have mis-typed your class name. org.jooq.meta.sqlserver.SQLServerDatabase
I'm unclear what this error means - I copied the name from the documentation. I've tested, and can connect to the database. I assume there's something wrong with my configuration.
Here's my plugin configuration:
<plugin>
<groupId>org.jooq</groupId>
<artifactId>jooq-codegen-maven</artifactId>
<dependencies>
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>mssql-jdbc</artifactId>
<version>${mssql-jdbc.version}</version>
</dependency>
<dependency>
<groupId>org.jooq</groupId>
<artifactId>jooq-meta</artifactId>
<version>${jooq.version}</version>
</dependency>
</dependencies>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
<configuration>
<jdbc>
<driver>com.microsoft.sqlserver.jdbc.SQLServerDriver</driver>
<url>${datasource.url}</url>
<user>${datasource.username}</user>
<password>${datasource.password}</password>
</jdbc>
<generator>
<database>
<name>org.jooq.meta.sqlserver.SQLServerDatabase</name>
<includes>.*</includes>
<inputSchema>public</inputSchema>
</database>
<target>
<packageName>my.project</packageName>
</target>
</generator>
</configuration>
</plugin>
Versions:
Java 14
Spring Boot 2.3.2.RELEASE
JOOQ 3.13.3
mssql-jdbc 8.4.0.jre14
MS SQL 2012
Can anyone help me with my configuration or point out what I'm doing wrong?
jOOQ is not free for commercial databases.
Please check out: https://www.jooq.org/download/
I have a spring boot project using maven that I've included flyway in:
pom.xml:
<dependency>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-core</artifactId>
<version>6.5.0</version>
</dependency>
and application.properties:
#LOCAL
spring.datasource.url=jdbc:postgresql://localhost:5432/theDatabase
spring.datasource.username=theRightUser
spring.datasource.password=theRightPassword
and it works as expected when I run the application.
However, I'm trying to run mvn flyway:clean from the command line, and it doesn't seem to recognize the configuration correctly:
[ERROR] Failed to execute goal org.flywaydb:flyway-maven-plugin:6.4.4:clean (default-cli) on project my-service: org.flywaydb.core.api.FlywayException: Unable to connect to the database. Configure the url, user and password! -> [Help 1]
I tried adding spring.flyway properties (user/pass/url) in the application.properties file but it gave me the same error. What do I need to do to get flyway to read from the application.properies like it does when the application runs normally?
EDIT: I have made slight progress: I was able to reference my application.properties as a flyway config file by adding this to the pom.xml:
<plugin>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-maven-plugin</artifactId>
<version>6.5.0</version>
<configuration>
<configFiles>${project.basedir}/src/main/resources/application.properties</configFiles>
</configuration>
</plugin>
So now in that file, I have flyway.url, flyway.user and flyway.password. This allows me to run flyway goals from the command line, but is not totally the solution I want. I am looking into using this plugin to try and read the properties into the pom.xml file, and then using those values in the flyway-maven-plugin's <configuration> area.
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>properties-maven-plugin</artifactId>
<version>1.0.0</version>
<executions>
<execution>
<phase>initialize</phase>
<goals>
<goal>read-project-properties</goal>
</goals>
<configuration>
<files>
<file>${project.basedir}/src/main/resources/application.properties</file>
</files>
</configuration>
</execution>
</executions>
</plugin>
which would allow me to do this:
<plugin>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-maven-plugin</artifactId>
<version>6.5.0</version>
<configuration>
<url>${spring.datasource.url}</url>
<user>${spring.datasource.username}</user>
<password>${spring.datasource.password}</password>
</configuration>
</plugin>
When you run flyway as maven goal it will not pick up the properties from the application.properties, instead it will use the configuration provided by the flyway-maven-plugin, you can configure the flyway-maven-plugin in the following way -
Add the following plugin to pom.xml -
<plugin>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-maven-plugin</artifactId>
<version>6.5.0</version>
</plugin>
Then we will configure the flyway-maven-plugin, the Flyway Maven plugin can be configured in a wide variety of following ways (most convenient),
Configuration section of the plugin
The easiest way is to simply use the plugin’s configuration section in your pom.xml:
<plugin>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-maven-plugin</artifactId>
<version>6.5.0</version>
<configuration>
<driver>org.hsqldb.jdbcDriver</driver>
<url>jdbc:hsqldb:file:${project.build.directory}/db/flyway_sample;shutdown=true</url>
<user>SA</user>
<password>mySecretPwd</password>
<connectRetries>10</connectRetries>
<initSql>SET ROLE 'myuser'</initSql>
<schemas>
<schema>schema1</schema>
<schema>schema2</schema>
<schema>schema3</schema>
</schemas>
<callbacks>
<callback>com.mycompany.project.CustomCallback</callback>
<callback>com.mycompany.project.AnotherCallback</callback>
</callbacks>
<skipDefaultCallbacks>false</skipDefaultCallbacks>
<cleanDisabled>false</cleanDisabled>
<skip>false</skip>
<configFiles>
<configFile>myConfig.conf</configFile>
<configFile>other.conf</configFile>
</configFiles>
<workingDirectory>/my/working/dir</workingDirectory>
</configuration>
</plugin>
Maven properties
To make it easy to work with Maven profiles and to logically group configuration, the Flyway Maven plugin also supports Maven properties, update the properties section in pom.xml as follows:
<project>
...
<properties>
<!-- Properties are prefixed with flyway. -->
<flyway.user>myUser</flyway.user>
<flyway.password>mySecretPwd</flyway.password>
<!-- List are defined as comma-separated values -->
<flyway.schemas>schema1,schema2,schema3</flyway.schemas>
<!-- Individual placeholders are prefixed by flyway.placeholders. -->
<flyway.placeholders.keyABC>valueXYZ</flyway.placeholders.keyABC>
<flyway.placeholders.otherplaceholder>value123</flyway.placeholders.otherplaceholder>
</properties>
...
</project>
External Configuration File
Another way is to create a separate .properties file, the default configuration file name is flyway.properties and it should reside in the same directory as the pom.xml file. Encoding is specified by flyway.encoding (Default is UTF-8):
flyway.user=databaseUser
flyway.password=databasePassword
flyway.schemas=schemaName
...
If you are using any other name (e.g customConfig.properties) as the configuration file, then it should be specified explicitly when invoking the Maven command:
$ mvn <goals> -Dflyway.configFile=customConfig.properties
After configuring your flyway-maven-plugin, with the desired configuration, we will be able to execute flyway maven goals from command line.
You can do further reading here.
Hope this helps!
I am trying to use OpenDaylight to generate Pojos from Yang files according to this guide.
I cloned Yangtools from OpenDaylight github and built the project with mvn clean install
i've added the following to my pom:
<plugin>
<groupId>org.opendaylight.yangtools</groupId>
<artifactId>yang-maven-plugin</artifactId>
<version>2.0.8-SNAPSHOT</version>
<executions>
<execution>
<goals>
<goal>generate-sources</goal>
</goals>
<configuration>
<!-- directory containing yang files to parse and generate code -->
<yangFilesRootDir>src/main/yang</yangFilesRootDir>
<codeGenerators>
<generator>
<codeGeneratorClass>
org.opendaylight.yangtools.maven.sal.api.gen.plugin.CodeGeneratorImpl
</codeGeneratorClass>
<!-- directory into which generated files will be placed -->
<outputBaseDir>
target/generated-sources
</outputBaseDir>
</generator>
</codeGenerators>
<!-- if true, plugin will search for yang files also in dependent projects -->
<inspectDependencies>true</inspectDependencies>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.opendaylight.yangtools</groupId>
<artifactId>maven-sal-api-gen-plugin</artifactId>
<version>0.7.4-Lithium-SR4</version>
<type>jar</type>
</dependency>
</dependencies>
</plugin>
however i am unable to generate the sources. I am getting the following error:
[ERROR] Failed to execute goal org.opendaylight.yangtools:yang-maven-plugin:2.0.8-SNAPSHOT:generate-sources (default) on project odl-poc: Execution default of goal org.opendaylight.yangtools:yang-maven-plugin:2.0.8-SNAPSHOT:generate-sources failed: An API incompatibility was encountered while executing org.opendaylight.yangtools:yang-maven-plugin:2.0.8-SNAPSHOT:generate-sources: java.lang.AbstractMethodError: Method org/opendaylight/yangtools/maven/sal/api/gen/plugin/CodeGeneratorImpl.generateSources(Lorg/opendaylight/yangtools/yang/model/api/SchemaContext;Ljava/io/File;Ljava/util/Set;Ljava/util/function/Function;)Ljava/util/Collection; is abstract
what am i doing wrong?
Looks like a version incompatibility - you're referencing yang-maven-plugin version 2.0.8-SNAPSHOT, which is the current unreleased master branch, and dependency maven-sal-api-gen-plugin version 0.7.4-Lithium-SR4, which was like 5 major releases ago and long obsolete.
I have a maven project with a test class located at src/test/java/MyDevClass which is intended for development/testing purposes only. I would like to use it when I start spring-boot-maven-plugin with the command line mvn spring-boot:run.
So, my pom.xml contains:
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<!-- TODO: Will create a maven profile and have useTestClasspath only for development/testing -->
<useTestClasspath>true</useTestClasspath>
</configuration>
</plugin>
</plugins>
</build>
But, I get the following error:
org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [MyDevClass]
Caused by: java.lang.ClassNotFoundException: MyDevClass
Intriguing enough, I have another project using tomcat7-maven-plugin and it works fine:
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.0</version>
<configuration>
<useTestClasspath>true</useTestClasspath>
</configuration>
</plugin>
What I am missing?
Spring-boot maven plugin does not include current module's test sources (and resources) into classpath even if useTestClasspath is set to true.
I ran a forked execution with verbose logging (-X flag to Maven), and the plugin listed the forked JVM classpath. Test classes were not included.
If you look at the plugin sources (version 1.5.3 at time of writing), the flag useTestClasspath is only used in the addDependencies method.
I see two options as workarounds
Add the target/test-classes dir to the run classpath:
<directories>
<directory>${project.build.testOutputDirectory}</directory>
</directories>
For older plugin version use:
<folders>
<folder>${project.build.testOutputDirectory}</folder>
</folders>
The problem here is that the folder is added to the beginning of classpath, while test files are preferable at its end.
Create another Maven module with test classes and resources, and add it as a <scope>test</scope> dependency.
I'm trying to make the maven-checkstyle-plugin use the same config file for all our projects.
I've tried a couple of ways, but non of them was effective.
The only thing that seems to work is when i place the config file at the root of my maven-project and then use the name as configLocation configuration parameter in the pom.xml
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>2.10</version>
<configuration>
<configLocation>my-checkstyle-checker.xml</configLocation>
</configuration>
</plugin>
I've tried specifying an absolute disk-path, but that doesn't seem to work.
(Considering the endgoal is to have jenkins do the checkstyle this seemed a valid option if the file would be on the jenkins server at the specified location)
I've also tried making a seperate jar-file only containing the xml-file and then using this as a dependency. (This would also centralise the config in 1 location and prevent project specific deviations.) Unfortunately this also doesn't work.
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-checkstyle-plugin:2.10:checkstyle (default-cli) on project jenkins-sandbox-project: An error has occurred in Checkstyle report generation. Failed during checkstyle execution: Unable to find configuration file at location my-checkstyle-checker.xml: Could not find resource 'my-checkstyle-checker.xml'. -> [Help 1]
Is there anyone that can tell me what i'm doing wrong here?
It seems it only knows about the files in the same location as where the maven command was started.
maven-checkstyle-plugin version : 2.10
maven command : mvn checkstyle:checkstyle
Create a separate Maven project, that contains just the Checkstyle configuration. In my case I called this project checkstyle-config and it contains the following:
checkstyle-config/src/main/resources/checkstyle.config.xml
checkstyle-config/src/main/resources/checkstyle.suppressions.xml
checkstyle-config/pom.xml
The POM file for this project is trivial:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.totaalsoftware.incidentmanager</groupId>
<artifactId>checkstyle-config</artifactId>
<version>2.0.0-SNAPSHOT</version>
</project>
Build it, so that it gets installed. Then use it as a dependency for your Checkstyle execution, e.g.:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>com.totaalsoftware.incidentmanager</groupId>
<artifactId>checkstyle-config</artifactId>
<version>2.0.0-SNAPSHOT</version>
</dependency>
</dependencies>
<configuration>
<configLocation>checkstyle.config.xml</configLocation>
<suppressionsLocation>checkstyle.suppressions.xml</suppressionsLocation>
... other configuration ...
</configuration>
</plugin>
I had a similar problem. I solved it with the following configuration.
${project.basedir}/src/main/resources/checkstyle.xml
Note: my checkstyle file is located in "src/main/resources"
I also had some issues defining the location in my plugin configuration, but was able to get this working by overriding a Maven property that the plugin uses, checkstyle.config.location. See example below which works with a multi-module maven project and requires very little overhead.
<checkstyle.config.location>${project.parent.basedir}/my_checks.xml</checkstyle.config.location>
On my case the order of dependencies is the key , this is my pom
<dependency>
<groupId>org.geotools</groupId>
<artifactId>gt-epsg-wkt</artifactId>
<version>${geotools.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.geotools</groupId>
<artifactId>gt-geometry</artifactId>
<version>${geotools.version}</version>
</dependency>
<dependency>
<groupId>org.geotools</groupId>
<artifactId>gt-swing</artifactId>
<version>${geotools.version}</version>
</dependency>
<dependency>
<groupId>org.geotools</groupId>
<artifactId>gt-shapefile</artifactId>
<version>${geotools.version}</version>
</dependency>