Arseniy Tashoyan created MNG-6885:
-------------------------------------

             Summary: Profile-scope properties
                 Key: MNG-6885
                 URL: https://issues.apache.org/jira/browse/MNG-6885
             Project: Maven
          Issue Type: Improvement
          Components: Profiles
    Affects Versions: 3.6.3
            Reporter: Arseniy Tashoyan


If a property is set in one profile, then another profile cannot change it. It 
would be good to have profile-scope properties.
 Usage scenario: cross-compilation for different Scala versions (2.11 and 2.12).
 POM file:
{code:xml}
<project xmlns="http://maven.apache.org/POM/4.0.0";
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
                      http://maven.apache.org/xsd/maven-4.0.0.xsd";>
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.example</groupId>
    <artifactId>scala-example</artifactId>
    <packaging>jar</packaging>
    <version>1.0-SNAPSHOT</version>

    <properties>
        <scala.version>UNDEFINED</scala.version>
    </properties>

    <profiles>

        <profile>
            <id>scala-common</id>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-antrun-plugin</artifactId>
                        <version>1.8</version>
                        <executions>
                            <execution>
                                <id>tasks-scala-${scala.version}</id>
                                <phase>generate-resources</phase>
                                <goals>
                                    <goal>run</goal>
                                </goals>
                                <configuration>
                                    <target>
                                        <exec executable="echo">
                                            <arg value="Scala version: 
${scala.version}"/>
                                        </exec>
                                    </target>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>

        <profile>
            <id>scala-2.11</id>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
            <properties>
                <scala.version>2.11</scala.version>
            </properties>

        </profile>

        <profile>
            <id>scala-2.12</id>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
            <properties>
                <scala.version>2.12</scala.version>
            </properties>
        </profile>

    </profiles>

</project>
{code}
In this POM file we have one common task declaration for both Scala versions: 
2.11 and 2.12. Two specific profiles define the 'scala.version' property. The 
execution id of the plugin includes the property: 
'tasks-scala-${scala.version}', hence unique. So theoretically we could build 
our project in one run for both Scala versions.
 However, in the output of 'mvn package' we see only one plugin execution:
{code:none}
[INFO] --- maven-antrun-plugin:1.8:run (tasks-scala-2.12) @ profile-example ---
[INFO] Executing tasks

main:
     [exec] Scala version: 2.12
{code}
This is because the property 'scala.version' is globally set to '2.12'. It does 
not take different values for two different profiles. Therefore we need to run 
separately:
{code:none}
mvn -P scala-2.11 goals...
mvn -P scala-2.12 goals...
{code}
This feature could give same user experience as with Sbt cross builds.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to