Profile not being activated by default

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Profile not being activated by default

Adam Retter
I have a build plugin configured like so:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-assembly-plugin</artifactId>
    <executions>
        <execution>
            <id>assemble-archives</id>
            <phase>package</phase>
            <goals>
                <goal>single</goal>
            </goals>
        </execution>
    </executions>
    <configuration>
        <skipAssembly>true</skipAssembly>  <!-- Overridden by profile
build-dist-archives -->
    </configuration>
</plugin>


I am trying to override its configuration in a profile that I would
like enabled by default:

<profiles>
    <profile>
        <id>build-dist-archives</id>
        <activation>
            <activeByDefault>true</activeByDefault>
        </activation>
        <build>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-assembly-plugin</artifactId>
                    <configuration>
                        <skipAssembly>false</skipAssembly>  <!--
Override setting in default profile build/plugins for this module -->
                        <attach>false</attach>
                        <tarLongFileMode>gnu</tarLongFileMode>
                        <descriptors>

<descriptor>src/assembly/dist-assembly-unix.xml</descriptor>

<descriptor>src/assembly/dist-assembly-win.xml</descriptor>
                        </descriptors>
                    </configuration>
                </plugin>
            </plugins>
        </build>
    </profile>


I would expect that when I run `mvn package`, the
`build-dist-archives` profile is active and therefore the
maven-assembly-plugin SHOULD have skipAssembly=false. In the output
from Maven I see:

[INFO] --- maven-assembly-plugin:3.3.0:single (assemble-archives) @
exist-distribution ---
[INFO] Assemblies have been skipped per configuration of the
skipAssembly parameter.

This implies that skipAssembly was true.


However... if I manually enable the profile by running `mvn package -P
build-dist-archives`, then the maven-assembly-plugin does indeed have
skipAssembly=false, and the assembly is correctly built.

Can anyone tell me why the ` <activeByDefault>true</activeByDefault>`
on the profile is being ignored?


--
Adam Retter

skype: adam.retter
tweet: adamretter
http://www.adamretter.org.uk

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Profile not being activated by default

John Patrick
Running `mvn help:active-profiles` does it list your
build-dist-archives profile in the output?
Also `mvn help:all-profiles' is it listed their and does it show the
correct source? so pom or settings

If you add duplicate the executions section into your plugin defined
in the profiles, do you see the plugin executed twice?

Also what version of maven are you using? 3.6.3? or something older?

Sorry not an answer, just things i would do to try and work out if the
config is being seen, seen but ignored, or ignored.

On Wed, 13 May 2020 at 10:37, Adam Retter
<[hidden email]> wrote:

>
> I have a build plugin configured like so:
>
> <plugin>
>     <groupId>org.apache.maven.plugins</groupId>
>     <artifactId>maven-assembly-plugin</artifactId>
>     <executions>
>         <execution>
>             <id>assemble-archives</id>
>             <phase>package</phase>
>             <goals>
>                 <goal>single</goal>
>             </goals>
>         </execution>
>     </executions>
>     <configuration>
>         <skipAssembly>true</skipAssembly>  <!-- Overridden by profile
> build-dist-archives -->
>     </configuration>
> </plugin>
>
>
> I am trying to override its configuration in a profile that I would
> like enabled by default:
>
> <profiles>
>     <profile>
>         <id>build-dist-archives</id>
>         <activation>
>             <activeByDefault>true</activeByDefault>
>         </activation>
>         <build>
>             <plugins>
>                 <plugin>
>                     <groupId>org.apache.maven.plugins</groupId>
>                     <artifactId>maven-assembly-plugin</artifactId>
>                     <configuration>
>                         <skipAssembly>false</skipAssembly>  <!--
> Override setting in default profile build/plugins for this module -->
>                         <attach>false</attach>
>                         <tarLongFileMode>gnu</tarLongFileMode>
>                         <descriptors>
>
> <descriptor>src/assembly/dist-assembly-unix.xml</descriptor>
>
> <descriptor>src/assembly/dist-assembly-win.xml</descriptor>
>                         </descriptors>
>                     </configuration>
>                 </plugin>
>             </plugins>
>         </build>
>     </profile>
>
>
> I would expect that when I run `mvn package`, the
> `build-dist-archives` profile is active and therefore the
> maven-assembly-plugin SHOULD have skipAssembly=false. In the output
> from Maven I see:
>
> [INFO] --- maven-assembly-plugin:3.3.0:single (assemble-archives) @
> exist-distribution ---
> [INFO] Assemblies have been skipped per configuration of the
> skipAssembly parameter.
>
> This implies that skipAssembly was true.
>
>
> However... if I manually enable the profile by running `mvn package -P
> build-dist-archives`, then the maven-assembly-plugin does indeed have
> skipAssembly=false, and the assembly is correctly built.
>
> Can anyone tell me why the ` <activeByDefault>true</activeByDefault>`
> on the profile is being ignored?
>
>
> --
> Adam Retter
>
> skype: adam.retter
> tweet: adamretter
> http://www.adamretter.org.uk
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Profile not being activated by default

Anders Hammar
In reply to this post by Adam Retter
activeByDefault  is a bit tricky as it doesn't really when that it is
active by default all the time. It is only active if there is no other
profile ativated [1]. So I believe this is the behavior that you're seeing.

So, 'activeByDefault' is typically not good to use as you can get
unexpected behavior. E.g. when you enable some other profile.

On a general note I don't really understand the use case. In general you
shouldn't use profiles, especially to change the build behavior as you seem
to be wanting here.

[1]
https://maven.apache.org/guides/introduction/introduction-to-profiles.html

/Anders

On Wed, May 13, 2020 at 11:37 AM Adam Retter
<[hidden email]> wrote:

> I have a build plugin configured like so:
>
> <plugin>
>     <groupId>org.apache.maven.plugins</groupId>
>     <artifactId>maven-assembly-plugin</artifactId>
>     <executions>
>         <execution>
>             <id>assemble-archives</id>
>             <phase>package</phase>
>             <goals>
>                 <goal>single</goal>
>             </goals>
>         </execution>
>     </executions>
>     <configuration>
>         <skipAssembly>true</skipAssembly>  <!-- Overridden by profile
> build-dist-archives -->
>     </configuration>
> </plugin>
>
>
> I am trying to override its configuration in a profile that I would
> like enabled by default:
>
> <profiles>
>     <profile>
>         <id>build-dist-archives</id>
>         <activation>
>             <activeByDefault>true</activeByDefault>
>         </activation>
>         <build>
>             <plugins>
>                 <plugin>
>                     <groupId>org.apache.maven.plugins</groupId>
>                     <artifactId>maven-assembly-plugin</artifactId>
>                     <configuration>
>                         <skipAssembly>false</skipAssembly>  <!--
> Override setting in default profile build/plugins for this module -->
>                         <attach>false</attach>
>                         <tarLongFileMode>gnu</tarLongFileMode>
>                         <descriptors>
>
> <descriptor>src/assembly/dist-assembly-unix.xml</descriptor>
>
> <descriptor>src/assembly/dist-assembly-win.xml</descriptor>
>                         </descriptors>
>                     </configuration>
>                 </plugin>
>             </plugins>
>         </build>
>     </profile>
>
>
> I would expect that when I run `mvn package`, the
> `build-dist-archives` profile is active and therefore the
> maven-assembly-plugin SHOULD have skipAssembly=false. In the output
> from Maven I see:
>
> [INFO] --- maven-assembly-plugin:3.3.0:single (assemble-archives) @
> exist-distribution ---
> [INFO] Assemblies have been skipped per configuration of the
> skipAssembly parameter.
>
> This implies that skipAssembly was true.
>
>
> However... if I manually enable the profile by running `mvn package -P
> build-dist-archives`, then the maven-assembly-plugin does indeed have
> skipAssembly=false, and the assembly is correctly built.
>
> Can anyone tell me why the ` <activeByDefault>true</activeByDefault>`
> on the profile is being ignored?
>
>
> --
> Adam Retter
>
> skype: adam.retter
> tweet: adamretter
> http://www.adamretter.org.uk
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>
Reply | Threaded
Open this post in threaded view
|

Re: Profile not being activated by default

Adam Retter
In reply to this post by John Patrick
> Running `mvn help:active-profiles` does it list your
> build-dist-archives profile in the output?

Nope. It is not shown as an active profile:

Active Profiles for Project
'org.exist-db:exist-distribution:pom:5.3.0-SNAPSHOT':

The following profiles are active:

 - evolvedbinary-release (source: external)
 - mac-dmg-on-mac (source: org.exist-db:exist-distribution:5.3.0-SNAPSHOT)



> Also `mvn help:all-profiles' is it listed their and does it show the
> correct source? so pom or settings

Listing Profiles for Project: org.exist-db:exist-distribution:pom:5.3.0-SNAPSHOT
  Profile Id: evolvedbinary-release (Active: true , Source: settings.xml)
  Profile Id: mac-dmg-on-mac (Active: true , Source: pom)
  Profile Id: java8-runtime-compatibility (Active: false , Source: pom)
  Profile Id: mac-dmg-on-unix (Active: false , Source: pom)
  Profile Id: codesign-mac-dmg (Active: false , Source: pom)
  Profile Id: codesign-mac-app (Active: false , Source: pom)
  Profile Id: exist-release (Active: false , Source: pom)
  Profile Id: build-dist-archives (Active: false , Source: pom)


build-dist-archives is shown above as "pom" but active=false.

So it seems that the default activation is not taking place??? i.e.:
    <activation>
        <activeByDefault>true</activeByDefault>
    </activation>



> If you add duplicate the executions section into your plugin defined
> in the profiles, do you see the plugin executed twice?

I did this and saw no change to the output from either `mvn
help:active-profiles` or `mvn help:all-profiles`.
That plugin is only executed once (presumably because the profile is
not enabled correctly).


> Also what version of maven are you using? 3.6.3? or something older?

I am using 3.6.3.


> Sorry not an answer, just things i would do to try and work out if the
> config is being seen, seen but ignored, or ignored.

No problem. Thanks for taking the time to try and help me :-)


--
Adam Retter

skype: adam.retter
tweet: adamretter
http://www.adamretter.org.uk

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Profile not being activated by default

Adam Retter
In reply to this post by Anders Hammar
On Wed, 13 May 2020 at 11:50, Anders Hammar <[hidden email]> wrote:
>
> activeByDefault  is a bit tricky as it doesn't really when that it is
> active by default all the time. It is only active if there is no other
> profile ativated [1]. So I believe this is the behavior that you're seeing.
>
> So, 'activeByDefault' is typically not good to use as you can get
> unexpected behavior. E.g. when you enable some other profile.

That's very interesting... and completely un-intuitive behaviour IMHO

I just read in [1]:

"This profile will automatically be active for all builds unless
another profile in the same POM is activated using one of the
previously described methods"

So, in this case there is another profile which is activated in that
POM when it detects that it is running on MacOS. I guess this would
explain what is causing the <activeByDefault> to be ignored?



> On a general note I don't really understand the use case. In general you
> shouldn't use profiles, especially to change the build behavior as you seem
> to be wanting here.

We have a module that has many steps in it. It builds a distribution
of our software (lots of different types of package: DMG for Mac, Zip
and Bz2 files, etc), by default I want all of those packages to build.
Building all those packages takes a lot of time. For developers to
speed up their build-test lifecycle I want to offer flags to disable
building some of those packages.

I thought I could do that in this way. I might be better to do the
inverse though where the build plugin is set to
<skipAssembly>false</skipAssembly>, and I could instead enable a
profile which sets <skipAssembly>true</skipAssembly>. It's not enough
to use a command line property to control the assembly-plugin as we
make lots of different uses of it within that module.

I do realise that ultimately we should likely refactor this large
module into a parent with lots of smaller modules, but that is a large
amount of work as there are lots of file dependencies between the
plugin steps.


--
Adam Retter

skype: adam.retter
tweet: adamretter
http://www.adamretter.org.uk

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]