views:

96

answers:

2

I wonder what is the Maven way in my situation.

My application has a bunch of configuration files, let's call them profiles. Each profile configuration file is a *.properties file, that contains keys/values and some comments on these keys/values semantics. The idea is to generate these *.properties to have unified comments in all of them. My plan is to create a template.properties file that contains something like

#Comments for key1/value1
key1=${key1.value}

#Comments for key2/value2
key2=${key2.value}

and a bunch of files like

#profile_data_1.properties
key1.value=profile_1_key_1_value
key2.value=profile_1_key_2_value

#profile_data_2.properties
key1.value=profile_2_key_1_value
key2.value=profile_2_key_2_value

Then bind to generate-resources phase to create a copy of template.properties per profile_data_*, and filter that copy with profile_data_*.properties as a filter.

The easiest way is probably to create an ant build file and use antrun plugin. But that is not a Maven way, is it?

Other option is to create a Maven plugin for that tiny task. Somehow, I don't like that idea (plugin deployment is not what I want very much).

+1  A: 

Maven does offer filtering of resources that you can combine with Maven profiles (see for example this post) but I'm not sure this will help here. If I understand your needs correctly, you need to loop on a set of input files and to change the name of the output file. And while the first part would be maybe possible using several <execution>, I don't think the second part is doable with the resources plugin.

So if you want to do this in one build, the easiest way would be indeed to use the Maven AntRun plugin and to implement the loop and the processing logic with Ant tasks.

And unless you need to reuse this at several places, I wouldn't encapsulate this logic in a Maven plugin, this would give you much benefits if this is done in a single project, in a unique location.

Pascal Thivent
In fact, my problem has nothing to do with Maven profiles. The word "profile" is too ambiguous in maven discourse ).But thanks for the antrun approach approval, Pascal. It's hard for a Maven novice to tell if the chosen approach is not a cumbersome one.
zamza
@zamza You're welcome. And feel free to ask questions when in doubt, that's IMHO the right thing to do.
Pascal Thivent
+1  A: 

You can extend the way maven does it's filtering, as maven retrieves it's filtering strategy from the plexus container via dependency injection. So you would have to register a new default strategy. This is heavy stuff and badly documented, but I think it can be done.

Use these URLs as starting point:

http://maven.apache.org/shared/maven-filtering/usage.html

and

http://maven.apache.org/plugins/maven-resources-plugin/

Sean

seanizer