Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Skip exec-maven-plugin from Command Line Argument in Maven

By default in my project POM, exec-maven-plugin, rpm-maven-plugin will be executed, which is not required in local compilation/build.

I want to skip these plugin execution by passing Command Line Arguments I tried below command to skip them like normal plugins, but didn't work though!

mvn install -Dmaven.test.skip=true -Dmaven.exec.skip=true -Dmaven.rpm.skip=true

like image 351
RaceBase Avatar asked Oct 29 '14 17:10

RaceBase


People also ask

What are the goals of the Exec Maven plugin?

The plugin provides 2 goals to help execute system and Java programs. General information about the goals. exec:exec execute programs and Java programs in a separate process. exec:java execute Java programs in the same VM. General instructions on how to use the Exec Maven Plugin can be found on the usage page.

How do I skip a test in Maven?

that is placed inside the plugins element of build tag in your project element of the pom. 2. DskipTests argument You can skip the test for any project while executing the maven command from command prompt for that particular project’s build lifecycle’s phase by specifying the argument -DskipTests.

How to execute the main method from the command line via Maven?

2. The exec-maven-plugin Let's suppose we have the following class: And we want to execute its main method from the command line via Maven. In order to do this, we can use the exec-maven-plugin. To be more specific, the exec:java goal from this plugin executes the supplied Java class with the enclosing project's dependencies as the classpath.

Is it possible to pass arguments from the command line in Maven?

However, this can be cumbersome when we're working with a pretty large classpath. On the contrary, when using this plugin, Maven automatically takes care of populating the classpath. 3. Passing Arguments It's also possible to pass arguments from the command line to the main method.


3 Answers

This page should tell you that the name of the argument to be passed by cmdline (i.e. the user property) is called skip, which is a poorly chosen name. To fix this do the following:

<properties>
  <maven.exec.skip>false</maven.exec.skip> <!-- default -->
</properties>
...
<plugin>
  <groupId>org.codehaus.mojo</groupId>
  <artifactId>exec-maven-plugin</artifactId>
  <version>1.3.2</version>
  <configuration>
    <skip>${maven.exec.skip}</skip>
  </configuration>
</plugin>
like image 170
Robert Scholte Avatar answered Oct 24 '22 16:10

Robert Scholte


Try -Dexec.skip from specification:

http://www.mojohaus.org/exec-maven-plugin/java-mojo.html#skip

like image 43
Grim Avatar answered Oct 24 '22 16:10

Grim


Using profiles (as little as possible) and execution phase you may achieve what you want for plugins that do not handle the skip property:

Plugin configuration:

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>rpm-maven-plugin</artifactId>
    <executions>
        <execution>
            <phase>${rpmPackagePhase}</phase>
            <id>generate-rpm</id>
            <goals>
                <goal>rpm</goal>
            </goals>
        </execution>
    </executions>
    <configuration>
    ...
    </configuration>
</plugin>

Profile configuration:

<profiles>
    <profile>
        <id>default</id>
        <activation>
            <activeByDefault>true</activeByDefault>
        </activation>
        <properties>
            <rpmPackagePhase>none</rpmPackagePhase>
        </properties>
    </profile>
    <profile>
        <id>rpmPackage</id>
        <activation>
            <property>
                <name>rpm.package</name>
                <value>true</value>
            </property>
        </activation>
        <properties>
            <rpmPackagePhase>package</rpmPackagePhase>
        </properties>
    </profile>
</profiles>

Invocation:

mvn package -Drpm.package=true [...]
like image 32
Ananda Avatar answered Oct 24 '22 15:10

Ananda