4

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

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>

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

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>

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

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

5
  • Have you tried to escape the space? Commented Feb 10, 2018 at 7:45
  • @Andrey Haha, yes it's my project, it's in an alpha stage right now. I'm not sure where or how that test dependency is in play. Can you provide your pom file so I can reproduce that? Commented Feb 13, 2018 at 19:09
  • You should be able to use the plugin with the default -Xplugin:Manifold javac argument with the base jar file dependency: <dependency> <groupId>systems.manifold</groupId> <artifactId>manifold</artifactId> <version>0.9-alpha</version> </dependency> Commented Feb 13, 2018 at 19:12
  • Also, you don't really need to "use" the plugin in your project so much as simply try to compile it with Maven and see the error regarding the -Xplugin:"Manifold static" argument. Commented Feb 13, 2018 at 19:18
  • Let us continue this discussion in chat. Commented Feb 13, 2018 at 19:36

1 Answer 1

5

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.

This here:

myOption=foo"bar"baz

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

with these arguments:

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

you will get this output:

hello
-World:blah blah blah
foobar

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

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>

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

Sign up to request clarification or add additional context in comments.

8 Comments

I appreciate your suggestion, thanks, however I've tried that and many other variations without luck. The discussion you mention concerns <compilerArguments>, which is different from <compilerArgs>, but still fails in a similar way.
@ScottMcKinney The discussion was about <compilerArguments> (which turned out to be awkward), and this is why <compilerArgs> were introduced. If my proposal doesn't work, then I have to agree that it seems to be quite counter-intuitive. Is there a way to make your problem reproducible, i.e. specify maven version, the specific compiler plugin, and the exact content of <arg>? If it's your own plugin, maybe it could be somehow reduced into a trivial no-op compiler plugin? It's weird, because all text (including whitespace) should be passed to the javac unchanged...
Yeah, it is weird. I'm using the Manifold plugin. Reproducing is simple.. create a pom with a dependency on the manifold-all jar (and tools.jar if using Java 8). Then add the maven-compiler-plugin example above. I'm currently using Maven 3.5.0. The problem goes away with the standard Manifold plugin setting: -Xplugin:Manifold, but I'd like a way to use the static argument if possible.
@ScottMcKinney I won't be able to try it today, it's getting late in this part of the world... Could you please add this information to your original question (there is a little gray 'edit' button under it). The link to Manifold is particularly useful, because this makes the question reproducible, that's good! I'm playing with the thought that I could create javac-compiler-plugin tag extra for that, otherwise this question goes under in all the "maven-compiler-plugin"-hits. But, tomorrow... ;)
@ScottMcKinney It would also be very helpful if you could describe more precisely what "no bueno" means: does mvn complain, or does javac complain, or does the plugin itself complain? Or does the compiler plugin simply ignore the parameters? (I'll find out tomorrow, but it's probably helpful for those who will come here with a similar problem).
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.