6

We develop multiple branches of a project concurrently. Each developer has multiple working copies, each working copy uses its own DB schema. (There will typically be a working copy per branch, but sometimes even more than one working copy per branch.) We need to let Maven know the DB credentials (for the db-migration plugin, for unit tests, for the dev instance of the servlet).

We can't put the credentials in the pom.xml because each developer might use different DB schema names. We can't put the credentials in settings.xml because each developer uses more than one schema.

Where do we put the credentials?

For example, http://code.google.com/p/c5-db-migration/ describes that the DB credentials need to be present in pom.xml but I would like to externalize them out to a file that's not under revision control.

hibbelig
  • 510
  • 6
  • 15

2 Answers2

2

Read following answers:

or just:


<project>
  <build>
    <plugins>
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>properties-maven-plugin</artifactId>
        <version>1.0</version>
        <executions>
          <execution>
            <phase>initialize</phase>
            <goals>
              <goal>read-project-properties</goal>
            </goals>
          </execution>
          <configuration>
            <files>
              <file>dev.properties</file> <======== IT IS!!!!!
            </files>
          </configuration>
        </executions>
      </plugin>
    </plugins>
  </build>
</project>
Community
  • 1
  • 1
gavenkoa
  • 45,285
  • 19
  • 251
  • 303
2

You could put them into a properties file inside the project directory but which is excluded from source control.

With Maven it's possible to read properties from an external file by using a <build><filters><filter> element as instructed here.

Esko Luontola
  • 73,184
  • 17
  • 117
  • 128
  • That's what I want! But how to tell Maven to read the properties file? I searched and searched but couldn't find it. Thank you so much for the answer. – hibbelig Mar 07 '11 at 20:17
  • 1
    I don't know either that how to read properties files with Maven. Since it's Maven, probably there is a plugin for it. ;) With Maven 2 it was possible to use a per-project profiles.xml file, but Maven 3 has removed support for it. – Esko Luontola Mar 07 '11 at 22:38
  • I just found out how to read external properties files with Maven. I've updated the answer. – Esko Luontola Mar 07 '11 at 22:44
  • 1
    I've attempted to clarify the original question by adding an example. As I understand the `` documentation, it's not possible to use the properties read from an external file in a pom, it's only possible to put them into another external file. – hibbelig Mar 09 '11 at 22:25