'Unable to pass java compiler parameters using maven

As the title says I am unable to pass command line parameters to the java compiler using maven, I am using the maven-compiler-plugin to do it, and accordingly to this (specifically for the compilerArgs option of the pluging) I am using the "latest way" to speficy the arguments passed to the compiler. Well enough talk, more code, this is my maven configuration for the plug-in and I am not sure what am I doing wrong:

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.3</version>
            <configuration>
                <source>1.8</source>
                <target>1.8</target>
                <fork>true</fork>
                <compilerArgs>
                    <arg>-parameters</arg>
                </compilerArgs>
            </configuration>
        </plugin>
    </plugins>
</build>

I am following the instructions for the usage of the tool which says that <fork> have to be set to true, and I do not know what am I missing... a little bit of help please?

May or may not be helpful to mention that: I need the parameters argument as specified here because I want to get the name of the arguments in my methods in runtime using reflection; I use the -X argument when calling maven to see the debug and I shows me the "fork" call that it does and I cannot se ANYWHERE the arguments I am passing (maybe I need to enable the plug-in; but I think In this case is automatically enabled since it is not part of any profile, I am not a maven expert so please correct me if I am wrong).

EDIT: I have tried in several ways with and without the dash I have even tried the "old way" to do it:

<compilerArguments>
  <parameters />
</compilerArguments>

And:

<compilerArgument>-parameters</compilerArgument>


Solution 1:[1]

My mistake: I created the code before modifying my pom file, and ran it using maven to check that is was actually working. After that, I modified my pom to include the -parameters flag. The code had already been compiled without that flag and was not modified after. Therefore, maven saw no changes in the code and did not recompile the file.

SOLUTION execute a mvn clean, delete the compiled classes, delete the target folder, or whatever is necessary to ensure that the files are recompiled.

Solution 2:[2]

Please mention, that you always have to write a '-' letter before the parameters.

Below you can see a configuration for your plugin with some sample compiler arguments.

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.3</version>
            <configuration>
                <source>1.8</source>
                <target>1.8</target>
                <fork>true</fork>
                <compilerArgs>
                    <arg>-verbose</arg>
                    <arg>-Xlint:all,-options,-path</arg>
                </compilerArgs>
            </configuration>
        </plugin>
    </plugins>
</build>

Solution 3:[3]

From the maven compile plugin main page:

The Compiler Plugin is used to compile the sources of your project. Since 3.0, the default compiler is javax.tools.JavaCompiler (if you are using java 1.6) and is used to compile Java sources. If you want to force the plugin using javac, you must configure the plugin option forceJavacCompilerUse.

I'm guessing the javax.tools.JavaCompiler doesn't works the same way javac does with the -parameters option.

Try forcing the javac use

<build>
<plugins>
    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.3</version>
        <configuration>
            <source>1.8</source>
            <target>1.8</target>
            <forceJavacCompilerUse>true</forceJavacCompilerUse>
            <fork>true</fork>
            <compilerArgs>
                <arg>-parameters</arg>
            </compilerArgs>
        </configuration>
    </plugin>
</plugins>
</build>

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 cb4
Solution 2 Coder55
Solution 3 Sekkuar