0

I use maven to build my java based program. It is work fine. But now I meet an issue which request me to build a revision for other users which is based on the same source code with a little different(e.g. different software name, and different resource file).

Does anyone have any idea about how to do it?

Mat
  • 202,337
  • 40
  • 393
  • 406
Peica
  • 31
  • 7

3 Answers3

6

You need to use profiles. It's a little complicated to explain in an answer like this, but essentially, you will create different profiles within your POM for the different builds you want to do. You will choose the profile at build time, using, e.g., a variable definition in the mvn command line, and within the profile, you change any of the variables or settings that you need to change. Lots more info is available here.

jwismar
  • 12,164
  • 3
  • 32
  • 44
  • Thanks, i will find out some info about the maven profile at first. – Peica May 19 '11 at 04:37
  • Fine, after reading the profile section in Maven, I think it is not necessary for me. I need to use the pom to build all revision at the same time. My big problem is how to do some different setting for two revision at the same pom file. – Peica May 19 '11 at 07:42
  • I see a similar question here [1]. Based on that answer, it doesn't sound like this is supported. [1] http://stackoverflow.com/questions/4932944/maven-build-multiple-profiles-in-one-go – jwismar May 19 '11 at 20:34
  • I have fill all resources into my program and detect which need to use by myself. I think to depend on something which i was not familiar is a bad idea. – Peica May 20 '11 at 08:56
0

You can create different profiles within your POM for the different builds you want to do.

Here are some of the example part of POM.xml

<!-- Define profiles here and make DEV as default profile -->
<profiles>

    <!-- dev Profile -->
    <profile>
        <id>dev</id>
        <activation>
            <activeByDefault>true</activeByDefault>
        </activation>
    </profile>

    <!-- qa Profile -->
    <profile>
        <id>qa</id>
        <properties>
            <env>qa</env>
        </properties>
    </profile>

    <!-- prod Profile -->
    <profile>
        <id>prod</id>
        <properties>
            <env>prod</env>
        </properties>
    </profile>

</profiles>
...


<plugin>
    <artifactId>maven-resources-plugin</artifactId>
    <version>2.4.3</version>

    <executions>
        <execution>
aryan
  • 29
  • 9
0

Depending on the type of project, the most "maven" way to do this would be to split up the project into a parent with multiple children. Your main project is put into one module and each of user specific configurations goes into a different module, which can then depend on the common code.

Each of the user specific modules can have their own resources and unique configuration, which would make producing different named configurations easier. It would also make any user specific coding tweaks easier.

deterb
  • 3,994
  • 1
  • 28
  • 33