<plugin>
<groupId>com.googlecode.flyway</groupId>
<artifactId>flyway-maven-plugin</artifactId>
<version>1.7</version>
<configuration>
<driver>com.mysql.jdbc.Driver</driver>
<url>jdbc:mysql://127.0.0.1:3306/db_abc</url>
<user>db_user</user>
<sqlMigrationPrefix>V</sqlMigrationPrefix>
</configuration>
</plugin>
I don't want to mention driver, url and user here. I already have a abc.property
on src/main/resources
. How can use that file here?
in version 3.0 you have to use configFile like :
Garry,
there is one more way not to place database connection parameters to your pom-file. In particular, one can add them to settings.xml file in .m2 sub-folder of the user's folder [1]. The benefit is that the db paraneters do not live in the project folder and are not transmitted to the repository, so each developer may use her own settings.
The example of the settings file could look like the example below.
After that your can modify your pom-file according to the following snippet.
In the example above Oracle's driver is used, but you can replace it with the required one.
To print current settings execute the following.
Have a look at the
properties-maven-plugin
. It allows you to read properties from a file to then use them in your pom.Add the following plugin defintion:
If
abc.properties
contains:You can then use the properties as follows:
In version 3.x you have configFile option
You can add external property file in configuration section of pom or can be pass when running maven goal example- command line-
Pom file-
In my opinion, the best and the most flexible approach is to:
a) use profiles and filtering - keep all configuration properties for specific profile (development, test, etc.), e.g. in development.properties:
Then, in your pom file (possibly in root pom) define a profile, e.g:
here you can see that development profile is activated by default. If you want to use another profile set it with
b) set flyway.properties with filtered values - your flyway.properties should sit e.g. in src/main/resources and the values should be used from the parameters defined in the profile properties file:
c) reference flyway.properties from build directory - use simple plugin configuration (I really like clean poms):
Don't forget to enable filtering in resources as shown in many examples here. My flyway-maven-plugin version is 3.2.1 and it is managed in pluginManagement in parent pom, therefore version is not visible here. I also use explicit sql scripts with locations configuration.
There are several ways to deal with this. One approach is to do it the other way around.
That means that the properties to use are saved as properties inside the
pom.xml
and that the fileabc.properties
only has placeholders that will be filled in at build time.I will show you how it can be configured.
This is what the
pom.xml
will look like:And this will be your
src/main/resources/abc.properties
(use the key names of your choice):After the build the
target/classes/abc.properties
will look like this:As stated this is only one of several ways to do it. It might not suit your exact needs but it could.