Undertaker
Undertaker

Reputation: 131

Manage maven project version by profiles not by parent

I have a parent tag in pom.xml like this:

<parent>
    <groupId>com.de</groupId>
    <artifactId>MyApplication</artifactId>
    <version>2.5.7-SNAPSHOT</version>
    <relativePath>../pom.xml</relativePath>
</parent>

Also I have different profiles:

        <profiles>
            <profile>
                <id>default-environment-settings</id>
                <properties>
                    <app.env>dev</app.env>
                </properties>
                <activation>
                    <activeByDefault>true</activeByDefault>
                </activation>
            </profile>
                <profile>
                <id>xyz</id>
                <properties>
                    <app.env>profile2</app.env>
                </properties>
                <activation>
                    <activeByDefault>false</activeByDefault>
                </activation>
            </profile>
        <profiles>

Now I want that my application's version is managed by profiles not as a global parent so that each profile can have it's private version number.

Upvotes: 1

Views: 1387

Answers (2)

eclideria
eclideria

Reputation: 141

Did you try this ?

            <profiles>
                <profile>
                    <id>default-environment-settings</id>
                    <properties>
                        <app.env>dev</app.env>
                        <projectVersion>1.0-SNAPSHOT</projectVersion>
                    </properties>
                    <activation>
                        <activeByDefault>true</activeByDefault>
                    </activation>
                </profile>
                    <profile>
                    <id>xyz</id>
                    <properties>
                        <app.env>profile2</app.env>
                        <projectVersion>1.0</projectVersion>
                    </properties>
                    <activation>
                        <activeByDefault>false</activeByDefault>
                    </activation>
                </profile>
            <profiles>

And don't forget to put on your artifact

<version>${projectVersion}</version>

Upvotes: 2

Gerold Broser
Gerold Broser

Reputation: 14762

Profiles are not intended to declare POM's versions. If you define profiles as mentioned in eclideria's answer and your parent's POM with:

  <groupId>com.de</groupId>
  <artifactId>MyApplication</artifactId>
  <version>${projectVersion}</version>

it will result in:

[WARNING]
[WARNING] Some problems were encountered while building the effective model for com.de:MyApplication:jar:1.0-SNAPSHOT
[WARNING] 'version' contains an expression but should be a constant. @ com.de:MyApplication:${projectVersion}, ...MyApplication directory.../pom.xml, line ..., column ...
[WARNING]
[WARNING] It is highly recommended to fix these problems because they threaten the stability of your build.
[WARNING]
[WARNING] For this reason, future Maven versions might no longer support building such malformed projects.
[WARNING]

Upvotes: 0

Related Questions