Maven profile configuration with common plugins in different profiles

Viewed 200

I have a maven project which uses various plugins. One of those is the frontend maven plugin, which we use to run npm commands and build the output inside the war file.

When I am developing the backend part of the application I don't want that plugin to start, while in other situations (like when I'm developing web component which need to be built) I want to run this plugin.

As far as I know, Maven profiles could be used to address this issue. I want that the profiles are configured at project level because have to be used by many developers.

In this case, I would create:

  • a profile where I skip test (excluding frontend maven plugin)
  • a profile including tests (excluding frontend maven plugin)
  • a profile that includes frontend maven plugin for test locally some execution of the frontend maven plugin, while not others
  • 2 profiles (test and prod for test and production environment) that includes some extra frontend maven plugin's executions in the build process

I would like to know if I can configure it with profiles or if I have to manage it with command line arguments, excluding the steps that I don't want to run in a specific moment, but would not so much comfortable.

This is an idea of how I would configure those profiles:

<profiles>
    <profile>
        <id>local</id>
        <!-- skip tests -->
     </profile>
    <profile>
        <id>test</id>
        <plugins>
            <plugin>
                 <!-- frontend-maven-plugin -->
            </plugin>
        </plugins>
        <!-- other conf -->
     </profile>
     <profile>
         <id>prod</id>
           <plugins>
            <plugin>
                 <!-- frontend-maven-plugin -->
            </plugin>
        </plugins>
        <!-- other conf -->
     </profile>
</profiles>

Questions

  1. Is this pattern a good starting point or do I have to use profiles in a different way?
  2. How can I use the same plugin with same configuration (test and prod) without repeating the same code in both the profile sections?
  3. Do I have to use profiles for different reasons? Is there a better configuration to address this situation?
0 Answers
Related