Disable maven plugins when using a specific profile

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.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)