How do I pass javac multiple command-line arguments, some of which include colon, without breaking Maven release plugin?

自闭症网瘾萝莉.ら 提交于 2019-12-01 06:36:32

See http://maven.apache.org/plugins/maven-compiler-plugin/compile-mojo.html#compilerArgs

and http://maven.apache.org/plugins/maven-compiler-plugin/examples/pass-compiler-arguments.html

Maven 3.1 or later

                        <source>1.6</source>
                        <target>1.6</target>
                        <showDeprecation>true</showDeprecation>
                        <showWarnings>true</showWarnings>
                        </processors>
                        <compilerArgs>
                          <arg>-verbose</arg>
                          <arg>-Aeclipselink.persistencexml=src/main/resources/META-INF/persistence.xml</arg>
                        </compilerArgs>

or Maven 3.0 or older

      <compilerArguments>
        <verbose />
      </compilerArguments>
      <compilerArgument>-Aeclipselink.persistencexml=src/main/resources/META-INF/persistence.xml</compilerArgument>

It seems that while spaces are escaped in compilerArgument, the same isn't true for quotes. So, if you surround the spaces in the argument with quotes, you get two arguments:

<compilerArgument>-Xlint:serial" "-Werror</compilerArgument>

This invokes javac "-Xlint:serial" "-Werror" rather than javac "-Xlint:serial -Werror".

There's nothing in the docs about this that I can find.

I think it's a bug in maven-compiler-plugin, I submitted an issue to developers: MCOMPILER-178

dominik

In relation to Kalpesh Soni's answer:

Note for Maven 3.1 or later according to the example from http://maven.apache.org/plugins/maven-compiler-plugin/examples/pass-compiler-arguments.html:

<compilerArgs>
    <arg>-verbose</arg>
    <arg>-Xlint:all,-options,-path</arg>
</compilerArgs>

The above is great unless you want to pass an additional param that requires space character. In my case it was -bootclasspath /path/to/custom/rt.jar. In such a case you have to split this string on every space and pass every part as a new <arg /> in order not to get Fatal error compiling: invalid flag: ... So the working example is:

<compilerArgs>
    <arg>-verbose</arg>
    <arg>-Xlint:all,-options,-path</arg>
    <arg>-bootclasspath</arg><arg>/path/to/custom/rt.jar</arg>
</compilerArgs>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!