在exec之前编译Mvn

Ler*_*erp 12 compilation exec phase maven

我正在尝试设置我的POM,这样当我这样做mvn exec:exec或者mvn exec:java它将首先编译源并且iff成功时,执行它.

我有以下内容,并试图移动<execution>部分,但无法让它工作:

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.1</version>
            <configuration>
                <source>1.7</source>
                <target>1.7</target>
            </configuration>
            <executions>
                <execution>
                    <phase>exec</phase>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>exec-maven-plugin</artifactId>
            <version>1.2.1</version>
            <configuration>
                <mainClass>my.main.class</mainClass>
            </configuration>
        </plugin>
    </plugins>
</build>
Run Code Online (Sandbox Code Playgroud)

当我做任何一个mvn exec:exec ...mvn exec:java它没有先编译.我已经尝试将该<execution>部分放入exec插件部分,但这也不起作用?

Lin*_*abo 2

您可以将 exec 插件绑定到构建生命周期compile中的后续阶段(在下面的示例中):verify

<profile>
    <id>proxy</id>
    <build>
        <plugins>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>exec-maven-plugin</artifactId>
                <version>1.2.1</version>
                <executions>
                    <execution>
                        <phase>verify</phase>
                        <goals>
                            <goal>exec</goal>
                        </goals>
                        <configuration>
                           <mainClass>my.main.class</mainClass>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</profile> 
Run Code Online (Sandbox Code Playgroud)

并比跑mvn verify

我看到答案已经很晚了,您可能已经找到了解决方案。我只是留下来作为其他可能有需要的人的参考。

  • 谢谢你,但是,如果我理解正确的话,OP 正在尝试在“mvn exec:[exec|java]”的[直接]执行期间进行编译,而**不是**作为“正常”的一部分Maven 构建周期。为了澄清,他们和我一样,希望在我们运行“mvn exec”时首先构建代码,但**不**希望在正常的 Maven 构建周期/阶段运行“exec”。 (9认同)