2

I think I've a fairly generic problem that I expecting Maven to solve, but I can't find the appropriate plug-in...

Background

Like most reasonably sized projects I've got a requirement to deploy my application in several different environments. Let's say they are called "development", "qa" and "production". In each of these environments my application will talk to a different back end server and save it's data to a different data base. Rather then hard code all the setting in my application I'm going to create a Java properties file for each environment and just deploy the right one with the application. In my source code will look something like:

<root>
   |-- conf
   |     |--develop
   |     |    \-- application.properties
   |     |--qa
   |     |    \-- application.properties
   |     \--production
   |         \-- application.properties
   \-- pom.xml 

The problem

If the developer is adding a new setting to the project it's too easy to update conf\development\application.properties file but forget to update the other files. If the setting is missing this typically causes errors a run time, which on a production server could be disastrous.

The Question

Is there a Maven plug-in that could be used to ensure that all three versions of application.properties contain the exactly same set of keys. If one (or more) key is missing from any of the files the build should be failed.

Stormcloud
  • 2,065
  • 2
  • 21
  • 41
  • To recap, you want to validate that all 3 `application.properties` have the same keys. Do you also want to validate that they have some specific key? – Tunaki Apr 19 '16 at 15:41
  • 1
    The simplest solution would be to write a unit test which handles this... – khmarbaise Apr 19 '16 at 18:04
  • @Tunaki I've updated the question to be a bit clearer, but yes - I want to validate that each of the properties files contains exactly the same set of keys. The build should fail if any of the keys are missing as they are all important. – Stormcloud Apr 20 '16 at 08:22

1 Answers1

1

I'd develop a Maven plugin:

  • with an appropriate parameter, e.g. files.

    See this answer for examples how to implement multiple values parameters.

  • that reads the three .properties files and fills a Map<String, Integer> (where: String key, Integer count).

  • If any of the Integer is not equal to the number of files given in the end throw an org.apache.maven.plugin.MojoFailureException. The same applies if one of the values is invalid, e.g. empty or otherwise syntactically wrong.

I'd bind the plugin's goal to the generate-resources phase.

Community
  • 1
  • 1
Gerold Broser
  • 14,080
  • 5
  • 48
  • 107
  • Sadly, I think this might be the best solution. I had imagined that this would be a frequent enough requirement, but I'm guessing I'm wrong. Thanks – Stormcloud May 10 '16 at 08:11