3

I'm using Maven 3.3.9. Is it possible to have the same goal for the same plugin with different configurations? I mean something like this

<build>
    ...
    <pluginManagement>
    <plugins>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>exec-maven-plugin</artifactId>
            <version>1.6.0</version>
            <executions>
              <execution>
                <id>test1</id>
                <goals>
                  <goal>exec</goal>
                </goals>
              </execution>
            </executions>
            <configuration>
                <executable>dir</executable>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>exec-maven-plugin</artifactId>
            <version>1.6.0</version>
            <executions>
              <execution>
                <id>test2</id>
                <goals>
                  <goal>exec</goal>
                </goals>
              </execution>
            </executions>
            <configuration>
                <executable>cd</executable>
            </configuration>
        </plugin>
    </plugins>
    </pluginManagement>
</build>

If i put the <configuration> tag inside the <execution> it just get ignored.

Plus the tag <goalPrefix> is not working so i don't know how to alias the goals to differentiate them...

EDIT

I need to execute two different scripts i made, but only as a cli goal... the scripts run some tests on the code, but the test are optional, they have to be executed only when the programmer wants explicitly to run them.

The reason i want to embed those scripts in maven is because i want to use the ${project.build.directory} variable

Schizoping
  • 137
  • 10

1 Answers1

4

Yes, it is. However you would normally include them all in the same plugin definition. We do this to do the tree shaking, ahead of time compile and minification of our angular2 UIs in our projects. Our config looks like this:

            <plugins>
                <plugin>
                    <groupId>com.github.eirslett</groupId>
                    <artifactId>frontend-maven-plugin</artifactId>
                    <version>1.0</version>
                    <executions>
                        <execution>
                            <id>npm run typescript compiler</id>
                            <phase>compile</phase>
                            <goals>
                                <goal>npm</goal>
                            </goals>
                            <configuration>
                                <arguments>run compile_ts_ngc</arguments>
                            </configuration>
                        </execution>

                        <execution>
                            <id>rollup</id>
                            <phase>compile</phase>
                            <goals>
                                <goal>npm</goal>
                            </goals>
                            <configuration>
                                <arguments>run rollup</arguments>
                            </configuration>
                        </execution>

                        <execution>
                            <id>gulp build</id>
                            <phase>compile</phase>
                            <goals>
                                <goal>gulp</goal>
                            </goals>
                            <configuration>
                                <arguments>aot</arguments>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>
            </plugins>

As you can see we run two different npm commands during the compile phase. They run in the order specified from top to bottom.

I am not entirely certain what you are trying to do with them to differentiate them? Is that for ordering purposes or some conditional execution? Normally we would put separate tasks that need to run under specific conditions into a profile so you could easily specify when to run them.

tokkov
  • 2,959
  • 1
  • 13
  • 9