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

查看:105
本文介绍了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 插件.复制很简单.对多方面的 jar 的依赖:

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.

推荐答案

鉴于此讨论:MCOMPILER-178 和这个补丁:拉取请求,并且由于空格似乎不是 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(或您正在使用的任何外壳程序)中的字符串连接.它将字符串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天全站免登陆