Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to achieve reverse of maven profile activation by property?

Tags:

maven

I want to have a profile that triggers a certain plugin(say PMD) but I want to explicitly disable that plugin execution sometimes.
So I want to have a profile that is always active except when a property is defined.
Something like mvn -Dnopmd clean install, and the profile gets de-activated. Other than that the profile should always be active.

like image 574
Ravi Sanwal Avatar asked Feb 07 '12 20:02

Ravi Sanwal


People also ask

Which element activates a profile by default in Maven?

Profiles can be activated in the Maven settings, via the <activeProfiles> section. This section takes a list of <activeProfile> elements, each containing a profile-id inside. Profiles listed in the <activeProfiles> tag would be activated by default every time a project use it.


1 Answers

You can activate a profile when a property is not specfied like so:

<profile>
       <id>someprofile</id>
       <activation>
           <property>
               <name>!property.name</name>
           </property>
       </activation>
</profile>

This is also explained in the Maven documentation, Introduction to Build Profiles.

like image 140
smp7d Avatar answered Oct 09 '22 08:10

smp7d