Maven Compiler Plugin
  1. Maven Compiler Plugin
  2. MCOMPILER-135

Passing multiple parameters to Java 6 annotation processors with javac does not work

    Details

    • Type: Bug Bug
    • Status: Closed Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 2.3.1
    • Fix Version/s: 2.4
    • Labels:
      None
    • Environment:
      JDK 1.6, Maven 2.2.1, Maven-Compiler-Plugin 2.3.1, Windows
    • Number of attachments :
      3

      Description

      I have an annotation processor that supports multiple parameters and I have found that there is no way to set more than one of them at any given time from the Maven Compiler Plugin,

      Here's my setup.

       
      <plugin>
          <inherited>true</inherited>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-compiler-plugin</artifactId>
          <version>2.3.1</version>
          <configuration>
              <source>1.6</source>
              <target>1.6</target>
              <compilerArgument>-AaddResDir=src/main/webapp -Averbose=true</compilerArgument>
          </configuration>
      </plugin>
      

      Javac needs the parameters added as separate Strings

      [ ... , "-AaddResDir=src/main/webapp", "-Averbose=true"]

      but the Compiler Plugin generates this code:

      [ ... , "-AaddResDir=src/main/webapp -Averbose=true"]

      which Javac will parse as

      key:"addResDir" value="src/main/webapp -Averbose=true"

      The map version "<compilerArguments>" is of no help either, because this

      <Averbose>true</Averbose>
      <AaddResDir>src/main/webapp</AResDir>

      will generate the output

      [... , "-Averbose", "true", "-AaddResDir", "src/main/webapp"]

      while this

      <Averbose=true />
      <AaddResDir=src/main/webapp />

      is not well-formed XML.

      Stepping through the compiler argument generation with the debugger I have not found a way to post-process the arguments, so please add a way to support multiple APT parameters because this is a major show-stopper.

      1. AbstractCompilerMojo.java.2.patch
        2 kB
        Sean Patrick Floyd
      2. AbstractCompilerMojo.java.3.patch
        3 kB
        Sean Patrick Floyd
      3. AbstractCompilerMojo.java.patch
        1 kB
        Sean Patrick Floyd

        Issue Links

          Activity

          Hide
          Sean Patrick Floyd added a comment -

          OK now I see what you mean. What a mess. Maybe it would be best to introduce an array parameter, as an array is what's passed to the compiler anyway. That way we could catch all kinds of arguments. Something like this:

          <arguments>
              <argument>-Xmaxerrs</argument>
              <argument>100</argument>
              <argument>-Akey1=value1</argument>
              <argument>-Akey2=value2</argument>
          </arguments>
          

          (Inspired by exec:java)

          Show
          Sean Patrick Floyd added a comment - OK now I see what you mean. What a mess. Maybe it would be best to introduce an array parameter, as an array is what's passed to the compiler anyway. That way we could catch all kinds of arguments. Something like this: <arguments> <argument>-Xmaxerrs</argument> <argument>100</argument> <argument>-Akey1=value1</argument> <argument>-Akey2=value2</argument> </arguments> (Inspired by exec:java )
          Hide
          Sean Patrick Floyd added a comment -

          This third patch uses a Properties object.

          Usage:

          <additionalCompilerArguments>
              <property> <name>-Akey=value</name> </property>
              <property> <name>-verbose</name> </property>
              <property> <name>-Xmaxerrs</name> <value>1000</value> </property>
          </additionalCompilerArguments> 
          

          This is the most flexible approach and it should be able to support almost all kinds of parameters.

          Show
          Sean Patrick Floyd added a comment - This third patch uses a Properties object. Usage: <additionalCompilerArguments> <property> <name>-Akey=value</name> </property> <property> <name>-verbose</name> </property> <property> <name>-Xmaxerrs</name> <value>1000</value> </property> </additionalCompilerArguments> This is the most flexible approach and it should be able to support almost all kinds of parameters.
          Hide
          Per Hedman added a comment -

          This third patch seems flexible and interesting. I will run some basic scenarios through the patch and see if there is anything that we have missed...

          Show
          Per Hedman added a comment - This third patch seems flexible and interesting. I will run some basic scenarios through the patch and see if there is anything that we have missed...
          Hide
          Jesse Glick added a comment -

          By the way, -Akey=value notation is one of the standard options (not -X...) that all command-line Java compilers (as of JSR 269) are expected to interpret, not just javac, so it is quite appropriate for a mojo supporting multiple compilers to have dedicated knowledge of this syntax.

          Show
          Jesse Glick added a comment - By the way, -Akey=value notation is one of the standard options (not -X... ) that all command-line Java compilers (as of JSR 269) are expected to interpret, not just javac, so it is quite appropriate for a mojo supporting multiple compilers to have dedicated knowledge of this syntax.
          Hide
          Robert Scholte added a comment -

          Fixed in rev. 1162905 with an integration-test.
          After reading all comments I believe it is not necessary to add a new parameter. It is just another compilerArgument, where the key and value are separated by an '='-sign.

          Show
          Robert Scholte added a comment - Fixed in rev. 1162905 with an integration-test. After reading all comments I believe it is not necessary to add a new parameter. It is just another compilerArgument, where the key and value are separated by an '='-sign.

            People

            • Assignee:
              Robert Scholte
              Reporter:
              Sean Patrick Floyd
            • Votes:
              4 Vote for this issue
              Watchers:
              6 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: