Search code examples
javamavenplugins

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

  • 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.