I'm looking to find a way of disabling a plugin execution if running with a particular profile.
This is the opposite of running a plugin if a profile is selected.
My use case: My Maven build has a whole load of plugins, but when running on my dev machine, I want to skip some of them. Instead of commenting those plugins out locally, I want to be able just run the build with a "dev" profile. The plugins would continue to run on my continuous build.
Ideas?
Open Maven settings. m2 directory where %USER_HOME% represents the user home directory. If settings. xml file is not there, then create a new one. Add test profile as an active profile using active Profiles node as shown below in example.
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.
There is a neat way to disable plugin execution when specific profile is active.
Firstly you need to add an identifier to plugin execution like:
<build> <plugins> <!-- (...) --> <plugin> <groupId>nl.geodienstencentrum.maven</groupId> <artifactId>sass-maven-plugin</artifactId> <version>2.1</version> <executions> <execution> <id>styles-compilation</id> <!-- plugin execution identifier --> <phase>generate-resources</phase> <goals> <goal>update-stylesheets</goal> </goals> </execution> </executions> </plugin>
Then you need to define a profile in which this plugin will NOT be executed:
<profiles> <profile> <id>no-sass</id> <build> <plugins> <plugin> <groupId>nl.geodienstencentrum.maven</groupId> <artifactId>sass-maven-plugin</artifactId> <version>2.1</version> <executions> <execution> <id>styles-compilation</id> <!-- here there must be the same identifier as defined in <build><plugins> section --> <phase>none</phase> <!-- this disables plugin --> </execution> </executions> </plugin> </plugins> </build> </profile> </profiles>
Now if you run standard maven build:
mvn clean package
the sass-maven-plugin will be executed, yet when running:
mvn clean package -P no-sass
the sass-maven-plugin will not be executed.
example pom:
<profiles> <profile> <id>production</id> <activation> <activeByDefault>true</activeByDefault> </activation> <build> <plugins> <!-- <plugin> ... </plugin> --> </plugins> </build> </profile> <profile> <id>dev</id> <!-- Some other logic here, if necessary. Otherwise, there's no need for another profile. --> </profile> </profiles>
To run in Dev Mode you can call the following:
mvn -Pdev compile
To run in Production Mode just use the normal steps:
mvn compile
In case you don't want/need to define anything special in your dev profile, you can omit its declaration and call your Dev Mode like this (!
disables a profile):
mvn -P!production compile
Be aware: you may need to escape the exclamation mark since it is a special character in bash:
mvn -P\!production compile
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With