Demo Maven Plugin
Provide configuration values during build-time
Introduction
The Maven Plugin can be used to provide configuration values during a maven execution, so normally during build time or at any other time you run maven.
To be able to follow this demo, the following prerequisites must be met:
- ConfigSeeder is up and running
- Connectivity from the machine running the Maven Plugin to the ConfigSeeder
Prepare configuration groups in ConfigSeeder
- Create a configuration group
maven-demo
(the name of the configuration group can be chosen as desired). When creating the configuration group, just enable the filter columns Environment and Version and leave the security options on their default values. - Create the two environments
TEST
andPROD
(the name of the Environments can be chosen as desired) - Create an API Keys with permission to access the configuration group maven-demo. The API Key should have permissions to access the Test-and Prod-environment.
Prepare configuration Values
Add the following configuration values to the configuration group maven-demo
:
Setup and Run Maven
Maven Configuration
You can find your Maven Plugin Demo at https://gitlab.com/configseeder/java-demo.
You need to add the ConfigSeeder Maven Repository to your pom.xml or master pom:
<repositories>
...
<repository>
<id>configseeder-release-repository-read</id>
<name>ConfigSeeder Release Repository</name>
<url>https://maven.configseeder.com/</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>configseeder-release-repository-read</id>
<name>ConfigSeeder Release Repository</name>
<url>https://maven.configseeder.com/</url>
</pluginRepository>
</pluginRepositories>
Then you can add a configuration goal like:
<profiles>
<profile>
<id>demo</id>
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>filtered.properties</include> (1)
</includes>
<filtering>true</filtering>
</resource>
</resources>
<plugins>
<plugin>
<groupId>com.configseeder.client.maven</groupId>
<artifactId>configseeder-client-maven-plugin</artifactId>
<version>${dependency.configseeder-client.version}</version>
<goals>
<goal>fetch</goal>
</goals>
<executions>
<execution>
<phase>initialize</phase>
<goals>
<goal>fetch</goal>
</goals>
</execution>
</executions>
<configuration>
<serverUrl>https://demo.configseeder.com</serverUrl>
<apiKey>eyJr...</apiKey>
<tenant>demo</tenant> (2)
<environment>PROD</environment> (3)
<configurationGroups>
<configurationGroup>
<key>maven-demo</key> (4)
</configurationGroup>
</configurationGroups>
<version>1.0</version> (5)
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
- Configuration Files, in which templating will be done
- tenant, defaults to default
- Environment, for which the configuration values should be loaded
- Configuration Group, which should be loaded. There can be multiple configuration groups, the values of the last configuration group have the highest priority.
- Optional version, for which the configuration values should be loaded. It is also possible to specify dateTime to load the configuration values which were valid at a specific time.
Templating in Configuration Files
If you run the shown maven plugin configuration, there will be templating done in the configured file filtered.properties. This file should look like the following example:
project.version=@project.version@ <- Property replaced by maven
mail.host=@mail.host@ <- Property replaced by ConfigSeeder Plugin
mail.port=@mail.port@ <- Property replaced by ConfigSeeder Plugin
Run Maven
If you run mvn install with activated demo-Profile, the ConfigSeeder Maven Plugin will use the given API Key to connect to the ConfigSeeder and retrieve the required configuration values. The resulting filtered.properties should look like this:
project.version=2.2.0-SNAPSHOT
mail.host=smtp.company.com
mail.port=25