tags:

views:

24

answers:

2

Hello there.

We are attempting to re-factor our modularized maven building. We've introduced a property DEPLOYMENT_ENV which might be "prod", "dev", "staging", or what not. The mentality we had going in was that we could then define, say:

dev.jdbc.username = yoyodyne
dev.jdbc.password = 0verthruster
staging.jdb.username = cavaliers
staging.jdbc.password = 8thdim

Where this seems to break down is feeding maven plugin's configurations. For example, DBUnit needs a username. Semantically, the solution we had in mind looked like the below, however maven does not allow for recursive property definitions in this fashion:

<configuration>
    <username>${${DEPLOYMENT_ENV}.jdbc.username}</username>
</configuration>

Any ideas for parameterizing maven builds, such that we can keep our big huge central list of property definitions?

+1  A: 

Instead of different property names you can simply use same properties, but declare them in different profiles, either in pom.xml or in settings.xml

Eugene Kuleshov
we'd been doing that previously. our profile based approach was getting out of hand, with different profiles defining very different plugins. agreed completely that we can fix the problem of spaghetti build profiles independently having different profiles declare different variables. we're attempting to do away with as much profile independent configuration as possible, but this may well be a good or even necessary place for it.
rektide
I am suggesting to create multiple profiles just with properties. Note that you can activate multiple profiles at the same time, e.g. properties + additional plugins/gials, or just properties with default plugins.
Eugene Kuleshov
A: 

Could you be a little more specific about the issue you encounter? Do you have any error?

I already used this recursive property definition in one of my pom.xml, in a antrun plugin <configuration> and it works well:

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-antrun-plugin</artifactId>
            <version>1.2</version>
            <executions>
                <execution>
                    <phase>package</phase>
                    <goals>
                        <goal>run</goal>
                    </goals>
                    <configuration>
                        <tasks>
                            ...
                            <ftp server="${my-ftp-url}" userid="${ftp-${appli}-${env}-username}" password="${ftp-${appli}-${env}-password}"
                                remotedir="${remoteDir}/sources" passive="yes">
                                <fileset dir="../target/">
                                    <include name="*.tar.gz"/>
                                </fileset>
                            </ftp>
                            ...

As you can see in this code snippet, I use the ${ftp-${appli}-${env}-username} property, where ${appli}, ${env} and ${ftp-xxx-yyy-username} are properties that come from command line or settings.xml.

Anyway, as suggested by Eugene Kuleshov, I would go for a set of <profiles> that only define some properties, using <properties> tags, or an external property file:

<build>
    <plugins>
        <!-- Properties loader -->
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>properties-maven-plugin</artifactId>
            <version>1.0-alpha-1</version>
            <executions>
                <execution>
                    <phase>initialize</phase>
                    <goals>
                        <goal>read-project-properties</goal>
                    </goals>
                    <configuration>
                        <files>
                            <file>${basedir}/${env-properties-file}</file>
                        </files>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>
...
<profiles>
    <!-- Development -->
    <profile>
        <id>dev</id>
        <activation>
            <activeByDefault>true</activeByDefault>
            <property>
                <name>env</name>
                <value>dev</value>
            </property>
        </activation>
        <properties>
            <env-properties-file>dev-environment.properties</env-properties-file>
        </properties>
    </profile>

    <!-- Homologation -->
    <profile>
        <id>hom</id>
        <activation>
            <activeByDefault>false</activeByDefault>
            <property>
                <name>env</name>
                <value>hom</value>
            </property>
        </activation>
        <properties>
            <env-properties-file>homologation-environment.properties</env-properties-file>
        </properties>
    </profile>
    ...
romaintaz