为什么仍然存在不存在的ID

时间:2019-02-09 13:23:13

标签: java maven

在一个简单的maven项目(jar)中,我有一些我不了解的Maven和带有eclipse的执行ID

我将eclipse 2018-12与嵌入式Maven(3.5.3 / 1.10.020181127-2120)一起使用

当我在pom.xml中尝试此代码时

    <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>exec-maven-plugin</artifactId>
        <version>1.3.2</version>
        <executions>
          <execution>
            <id>first-cli</id>
            <configuration>
              <mainClass>com.zb.test.HelloFirst</mainClass>
            </configuration>
          </execution>
          <execution>
            <id>second-cli</id>
            <configuration>
              <mainClass>com.zb.test.HelloSecond</mainClass>
            </configuration>
          </execution>
        </executions>
      </plugin>

执行时

exec:java@first-cli

我得到类HelloFirst.java的结果

[INFO] Scanning for projects...
[INFO] 
[INFO] ----------------------< com.zb.membox:test >-----------------------
[INFO] Building test 0.0.1-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] 
[INFO] --- exec-maven-plugin:1.3.2:java (first-cli) @ test ---
[WARNING] Warning: killAfter is now deprecated. Do you need it ? Please comment on MEXEC-6.
hello world from first client
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.019 s
[INFO] Finished at: 2019-02-09T13:54:35+01:00
[INFO] ------------------------------------------------------------------------

执行时

exec:java@second-cli

我得到类HelloSecond.java的结果


[INFO] Scanning for projects...
[INFO] 
[INFO] ----------------------< com.zb.membox:test >-----------------------
[INFO] Building test 0.0.1-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] 
[INFO] --- exec-maven-plugin:1.3.2:java (second-cli) @ test ---
[WARNING] Warning: killAfter is now deprecated. Do you need it ? Please comment on MEXEC-6.
hello world from second client
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.019 s
[INFO] Finished at: 2019-02-09T13:54:35+01:00
[INFO] ------------------------------------------------------------------------

我得到类HelloSecond.java的结果

当我指定一个不存在的ID

exec:java@third-cli

它会产生我所期望的错误。


[INFO] Scanning for projects...
[INFO] 
[INFO] ----------------------< com.zb.membox:test >-----------------------
[INFO] Building test 0.0.1-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] 
[INFO] --- exec-maven-plugin:1.3.2:java (third-cli) @ test ---
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.014 s
[INFO] Finished at: 2019-02-09T13:55:17+01:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.3.2:java (third-cli) on project test: The parameters 'mainClass' for goal org.codehaus.mojo:exec-maven-plugin:1.3.2:java are missing or invalid -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginParameterException

但是当我尝试对编译器插件做同样的事情时,这里有些奇怪的地方是编译器插件的pom.xml部分


            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.2</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
                <executions>
                    <execution>
                        <id>compilefirst</id>
                      <phase>none</phase>
                      <goals>
                        <goal>compile</goal>
                      </goals>
                       <configuration>
                        <source>1.5</source>
                        <target>1.5</target>
                        </configuration>
                    </execution>
                    <execution>
                        <id>compilesecond</id>
                      <phase>none</phase>
                      <goals>
                        <goal>compile</goal>
                      </goals>
                       <configuration>
                        <source>1.6</source>
                        <target>1.6</target>
                        </configuration>
                    </execution>
                    <execution>
                        <id>default-compile</id>
                      <phase>compile</phase>
                      <goals>
                        <goal>compile</goal>
                      </goals>
                    </execution>
              </executions>
            </plugin>

我更改源目标以确保执行被执行 当我执行

clean compiler:compile@compilefirst

可以采用1.5 Java版本

clean compiler:compile@compilesecond

可以采用1.6 Java版本

但是,如果我尝试使用不存在的id……它可以正常工作!!!

clean compiler:compile@compilethird

结果

[INFO] Scanning for projects...
[INFO] 
[INFO] ----------------------< com.zb.membox:test >-----------------------
[INFO] Building test 0.0.1-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] 
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ test ---
[INFO] Deleting C:\Users\zb\Desktop\wspace-java\test\target
[INFO] 
[INFO] --- maven-compiler-plugin:3.2:compile (compilethird) @ test ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 30 source files to C:\Users\zb\Desktop\wspace-java\test\target\classes
[INFO] /C:/Users/zb/Desktop/wspace-java/test/src/main/java/com/zb/test/TestMbREG.java: C:\Users\zb\Desktop\wspace-java\test\src\main\java\com\zb\test\TestMbREG.java uses or overrides a deprecated API.
[INFO] /C:/Users/zb/Desktop/wspace-java/test/src/main/java/com/zb/test/TestMbREG.java: Recompile with -Xlint:deprecation for details.
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.279 s
[INFO] Finished at: 2019-02-09T14:00:24+01:00
[INFO] ------------------------------------------------------------------------

我的问题是为什么? Maven编译器是否具有默认执行ID?

非常感谢所有回复。

0 个答案:

没有答案