Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Passing an options/arguments file to Maven compiler plugin

Tags:

java

maven

The javac command can be configured with a file by specifying that file on the command line with @:

javac @compileargs

I want to use that syntax in Maven so I can collect parts of the command line arguments in such a file instead of Maven's pom.xml.

The Maven compiler plugin does not seem to have a specific tag for that, so I tried compilerArgs:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>3.6.1</version>
    <configuration>
        <compilerArgs>
            <arg>@compile-args</arg>
        </compilerArgs>
        <fork>true</fork>
    </configuration>
</plugin>

But then javac complains:

javac: invalid flag: @compile-args
Usage: javac <options> <source files>
use --help for a list of possible options

If I get the actual command Maven is executing (with -X) and call that myself it works, though.

I recently had a similar problem with spaces in compiler options so I assume a similar process is screwing with me here.

like image 444
Nicolai Parlog Avatar asked Apr 12 '17 05:04

Nicolai Parlog


1 Answers

Background info: The maven-compiler depends on the plexus compiler.

If the build process gets forked it will take all specified arguments and create a temporary config file on its own (see the code). The argument file will also include the user defined argument file, but the documentation points out that:

Use of the at sign (@) to recursively interpret files is not supported.

This means referencing an options file from Maven is not possible.

like image 79
meistermeier Avatar answered Sep 27 '22 02:09

meistermeier