Maven:如何使用maven-compiler-plugin指定Javac插件参数? [英] Maven: How to specify Javac plugin argument with maven-compiler-plugin?

查看:907
本文介绍了Maven:如何使用maven-compiler-plugin指定Javac插件参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Javac提供了以下非标准选项(来自"javac -X"命令​​行帮助):

Javac provides the following nonstandard option (from "javac -X" command line help):

-Xplugin:"name args"       Name and optional arguments for a plug-in to be run

但是,Maven不处理该格式.例如,以下方法不起作用:

However, Maven does not handle that format. For example, the following does not work:

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-compiler-plugin</artifactId>
  <configuration>
    <compilerArgs>
      <arg>-Xplugin:"Manifold static"</arg>
    </compilerArgs>
  </configuration>
</plugin>

我尝试了几种不同的变体,并尝试用'='代替空格,但仍然没有bueno.有解决方法吗?

I've tried several different variations and tried replacing the space with '=', still no bueno. Is there a workaround?

请注意,我正在Java 8中使用 Manifold javac插件.对流形所有罐子的依赖:

Note I am using the Manifold javac plugin with Java 8. Reproducing is simple.. create a pom with a dependency on the manifold-all jar:

<dependency>
  <groupId>systems.manifold</groupId>
  <artifactId>manifold-all</artifactId>
  <version>0.9-alpha</version>
</dependency>

您实际上并不需要任何源,这只是为了证明Maven将不接受-Xplugin:"Manifold static" javac参数.

You don't really need any source, this is just to demonstrate that Maven will not accept the -Xplugin:"Manifold static" javac argument.

还请注意,Java 9似乎已将-Xplugin的格式更改为不再需要使用引号.请参见 Java 9文档.

Also note Java 9 appears to have changed the format of -Xplugin to no longer require quotes. See the Java 9 docs on this.

推荐答案

根据此讨论:拉请求 ,而且由于XML名称中似乎不允许使用空格,因此我怀疑您必须删除所有双引号,并保留所有空格.

In light of this discussion: MCOMPILER-178 and this patch: pull request, and since a space doesn't seem to be a character allowed in XML-names, I would suspect that you have to just drop all the double-quotes, and keep all the spaces.

这里:

myOption=foo"bar"baz

bash(或您正在使用的任何shell)中的字符串连接.它将字符串"foobarbaz"存储在变量myOption中.如果在bash中的选项中使用双引号,则它的简单含义是:"bash,请将引号之间的整个内容视为单个参数,请勿将其拆分为字符串参数数组".例如,如果运行以下命令 bash脚本:

is string concatenation in bash (or whatever shell your are using). It stores the string "foobarbaz" in variable myOption. If you use double quotes in an option in bash, then it simply means: "bash, please treat the entire thing between the quotes as a single argument, don't split it into an array of string arguments". For example, if you run the following bash script:

#!/bin/bash

echo $1
echo $2
echo $3

具有以下参数:

$ ./testArgs.sh hello -World:"blah blah blah" foobar

您将获得以下输出:

hello
-World:blah blah blah
foobar

-World:blah blah blah部分是单个字符串,引号不保留.

The -World:blah blah blah part is a single string, the quotes are not preserved.

Maven不是bash. POM是一个XML文件,它具有标签,某些标签中填充了文本. XML不在乎bash用于字符串连接或参数解析的语法.如果我正确理解了上面的讨论,它们将xml-tags的内容直接传递给编译器,而无需进行任何修改.

Maven is not bash. POM is an XML file, it has tags, some of the tags are filled with text. XML doesn't care about bash's syntax for string concatenation or argument-parsing. If I understood the above discussion correctly, they passed the content of the xml-tags directly to the compiler, without any modifications.

因此,我最好的猜测是删除双引号:

Therefore, my best guess would be to just drop the double quotes:

<arg>-Xplugin:MyPlugin myArg</arg>

如果这没有帮助,那么我会完全误解了上面链接的讨论,或者您使用的Maven版本的工作方式有所不同.

If this doesn't help, then I misunderstood the discussion linked above entirely, or maybe you are using a maven version that works differently.

这篇关于Maven:如何使用maven-compiler-plugin指定Javac插件参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆