[ 
https://issues.apache.org/jira/browse/MNG-6000?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15245964#comment-15245964
 ] 

Fabrizio Lungo commented on MNG-6000:
-------------------------------------

Suppose I have a parent pom that is used for multiple projects (be it a 
corporate parent pom or a project parent pom) but not all of the projects using 
this parent generate executable jars (they may be a library), however when a 
project does build an executable jar I want these to be done the same way so I 
can define a profile. Here is the simplest profile I might define for this task:

{code}
<project>
    ...
    <profiles>
        <profile>
            <id>executable-jar</id>
            <activation>
                <activeByDefault>false</activeByDefault>
            </activation>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-jar-plugin</artifactId>
                        <configuration>
                            <archive>
                                <manifest>
                                    <addClasspath>true</addClasspath>
                                    
<mainClass>${maven.jar.manifest.mainClass}</mainClass>
                                </manifest>
                            </archive>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>
</project>
{code}

This profile can be included in the parent pom and activated manually at build 
time, but there is no way for the POM of the project to enable by default this 
profile, which makes the portability of this limited. If this feature were 
implemented I would add a {{<activeProfiles>}} section to the pom containing 
{{<profile>executable-jar</profile>}}.

In reality my profiles would probably be more complex than the simple one 
states above such as adding the {{maven-enforcer-plugin}} to check that the 
{{maven.jar.manifest.mainClass}} property is set and using the 
{{exec-maven-plugin}} to check that the jar can actually be executed (hence 
checking that the mainClass is correct and contains a main method).

I feel this could be expanded to many use cases. One that may have more 
configuration is (for example) a {{shaded-jar}} profile that can be configured 
with the appropriate includes and excludes others according to some corporate 
or project policy.

I feel this can also serve to provide some of the functionality seeked by 
MNG-5102 allowing profiles to be used as mixins.

At the moment, we use a separate parent for all our Java projects which 
inherits from our corporate parent. With this functionality, it may also be 
something we would consider to have {{java}} profile that contains all the java 
reporting and plugin configurations (e.g. javadoc).

> activeProfiles in pom.xml
> -------------------------
>
>                 Key: MNG-6000
>                 URL: https://issues.apache.org/jira/browse/MNG-6000
>             Project: Maven
>          Issue Type: Improvement
>          Components: POM, Profiles
>            Reporter: Fabrizio Lungo
>              Labels: features, maven
>             Fix For: waiting-for-feedback
>
>
> I would like to see the ability to define {{<activeProfiles>}} in a pom. I 
> think this would be extremely useful and provide a way for a parent pom to 
> provide a set of profiles that can be picked and chosen from as per the needs 
> of the project.
> A simple but specific example is where I would like to have a profile from 
> our corporate parent pom that is activated when a project should build an 
> executable jar. This profile provides the configuration for the 
> {{maven-jar-plugin}} (as well as adding some validations and checks) and we 
> would like to activate this on a per project level.
> Initially I tried using properties but activation conditions only look at 
> system properties (and not pom defined ones) and even using a property in the 
> {{<activateByDefault>}} tag. As described in MNG-5235 this is because 
> profiles need to be processed first and using properties from the pom would 
> create chicken-egg problems and inconsistencies because a profile can then 
> modify these properties.
> If {{<activeProfiles>}} were to be added to pom, this could be read first to 
> determine if any profiles need to be activated and allow a pom to define 
> which profiles will be active by default.
> Two optional features that could be implemented to supplement this would be:
> * Support for {{<activeProfiles>}} inside of a profile for profiles to be 
> able to recursively enable other profiles (that they may depend on). This 
> would allow reduction of duplication if two profiles require some shared 
> preconditions they can then just activate the profile with this shared 
> configuration and if one or both are activated, the shared configuration 
> profile will be activated too. This should be fairly easy to implement using 
> recursive checks and not revisiting any profiles already in an active list 
> (to avoid cycles - which should be warned about - and unnecessary 
> re-evaluations)
> * Support for disabling profiles (possibly by using 
> {{<profile>!profile-1</profile>}} syntax. This could have advantages where a 
> parent pom activates a profile by default and the child wants it disabled by 
> default although I can see this may cause problems.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to