简体   繁体   English

Maven中的用户和项目特定设置

[英]User and project specific settings in Maven

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). (每个分支通常会有一个工作副本,但有时甚至每个分支都有一个工作副本。)我们需要让Maven知道数据库凭据(对于db-migration插件,对于单元测试,对于dev实例)小服务程序)。

We can't put the credentials in the pom.xml because each developer might use different DB schema names. 我们无法将凭据放在pom.xml因为每个开发人员可能使用不同的数据库模式名称。 We can't put the credentials in settings.xml because each developer uses more than one schema. 我们无法将凭据放在settings.xml因为每个开发人员都使用多个架构。

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. 例如, http://code.google.com/p/c5-db-migration/描述了数据库凭据需要存在于pom.xml但我想将它们外部pom.xml不受版本控制的文件。

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>

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 . 使用Maven,可以按照此处的说明使用<build><filters><filter>元素从外部文件中读取属性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM