You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by Delany <de...@gmail.com> on 2023/09/24 13:45:49 UTC
passing compiler args via a properties file
Hi,
Passing a few arguments to the compiler is done easily enough through the
pom,
but when there are many arguments it starts to gets hairy,
especially when I'm configuring a plugin in multiple levels of inheritance.
For example, there are many bugpatterns in errorprone
https://errorprone.info/docs/flags
I want my build pom to set the basic settings for the compiler
<compilerArgs combine.children="append">
<arg>-Xlint:all,-serial,-processing</arg>
<arg>-XDcompilePolicy=byfile</arg>
<arg>-Xplugin:ErrorProne -XepExcludedPaths:.*/target/.* ${ep}</arg>
</compilerArgs>
And then my project can decide whether it want to override errorprone
default levels for specific rules
https://maven.apache.org/configure.html
I can add this one line to maven.config
-Dep=-Xep:ArgumentSelectionDefectChecker:WARN -Xep:AssertFalse:WARN
-Xep:EqualsHashCode:WARN -Xep:AvoidObjectArrays:WARN
-Xep:BareDotMetacharacter:WARN -Xep:CatchAndPrintStackTrace:WARN
-Xep:OperatorPrecedence:WARN -Xep:StatementSwitchToExpressionSwitch:WARN
-Xep:SuppressWarningsWithoutExplanation:WARN
And that does the job. I can also quickly run a build to catch on issue
that I'm trying to eradicate by adding
-Dep="-XepDisableAllChecks -Xep:ReferenceEquality:ERROR"
But having all those rules on one line makes reviewing changes a pain.
I don't really want to config the whole build with the compiler arguments.
Is there a way to specify these in a properties file and have each argument
on its own line?
Kind regards,
Delany
Re: passing compiler args via a properties file
Posted by Stanimir Stamenkov <s7...@netscape.net.INVALID>.
Sun, 24 Sep 2023 20:01:14 +0200, /Thomas Broyer/:
> ErrorProne itself doesn't support @file arguments, so I think the question
> remains unanswered: can Maven load a property's value from a file?
> (possibly through a plugin; I have looked at build-helper-maven-plugin and
> apparently it doesn't support it)
There's also a "Properties Maven Plugin":
https://www.mojohaus.org/properties-maven-plugin/
--
Stanimir
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org
Re: passing compiler args via a properties file
Posted by Thomas Broyer <t....@gmail.com>.
On Sun, Sep 24, 2023 at 7:49 PM Stanimir Stamenkov
<s7...@netscape.net.invalid> wrote:
> I've just noticed you're providing multiple arguments in a single <arg>
> element – I'm not sure if this is supposed to work like that.
It is; this is how -Xplugin: works; those are arguments to the ErrorProne
plugins, not to javac itself:
https://docs.oracle.com/en/java/javase/21/docs/specs/man/javac.html#option-Xplugin
This also means that using @file wouldn't really solve the problem, as the
whole -Xplugin:ErrorProne and its arguments would still have to be on a
single line.
ErrorProne itself doesn't support @file arguments, so I think the question
remains unanswered: can Maven load a property's value from a file?
(possibly through a plugin; I have looked at build-helper-maven-plugin and
apparently it doesn't support it)
--
Thomas Broyer
/tɔ.ma.bʁwa.je/ <http://xn--nna.ma.xn--bwa-xxb.je/>
Re: passing compiler args via a properties file
Posted by Stanimir Stamenkov <s7...@netscape.net.INVALID>.
Sun, 24 Sep 2023 18:04:51 +0200, /Delany/:
> Thank you. Its not happening though. I also tried it from the pom, so
> <arg>-Xplugin:ErrorProne
> -XepExcludedPaths:.*/target/.* @${build.root}/ep.config</arg>
@files are Java 9+ feature for tools other than javadoc – just making
sure you're not using Java 8 here.
If @file is specified it must exist, although it could be empty. If the
file doesn't exist the tool would fail.
I've just noticed you're providing multiple arguments in a single <arg>
element – I'm not sure if this is supposed to work like that. Maybe try:
<arg>-Xplugin:ErrorProne</arg>
<arg>-XepExcludedPaths:.*target.*</arg>
<arg>@${build.root}/ep.config</arg>
> Made more difficult by lack of visibility what's going on with the javac
> processors.
mvn -X (--debug) could be overwhelming but could possibly provide
insight of what's happening.
--
Stanimir
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org
Re: passing compiler args via a properties file
Posted by Delany <de...@gmail.com>.
Thank you. Its not happening though. I also tried it from the pom, so
<arg>-Xplugin:ErrorProne
-XepExcludedPaths:.*/target/.* @${build.root}/ep.config</arg>
Made more difficult by lack of visibility what's going on with the javac
processors.
On Sun, 24 Sept 2023 at 16:23, Stanimir Stamenkov
<s7...@netscape.net.invalid> wrote:
> [With some more context from the original message.]
>
> Sun, 24 Sep 2023 15:45:49 +0200, /Stanimir Stamenkov/:
> > Sun, 24 Sep 2023 15:45:49 +0200, /Delany/:
> >
> >> I can also quickly run a build to catch on issue
> >> that I'm trying to eradicate by adding
> >> -Dep="-XepDisableAllChecks -Xep:ReferenceEquality:ERROR"
> >>
> >> But having all those rules on one line makes reviewing changes a pain.
> >> I don't really want to config the whole build with the compiler
> arguments.
> >>
> >> Is there a way to specify these in a properties file and have each
> >> argument on its own line?
> >
> > Have you tried using @file (a-la javadoc options):
> >
> >
> https://docs.oracle.com/en/java/javase/17/docs/specs/man/javac.html#command-line-argument-files
>
> Maybe:
>
> -Dep=@myoptions
>
> And in "myoptions" file:
>
> -XepDisableAllChecks
> -Xep:ReferenceEquality:ERROR
>
> --
> Stanimir
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
>
>
Re: passing compiler args via a properties file
Posted by Stanimir Stamenkov <s7...@netscape.net.INVALID>.
[With some more context from the original message.]
Sun, 24 Sep 2023 15:45:49 +0200, /Stanimir Stamenkov/:
> Sun, 24 Sep 2023 15:45:49 +0200, /Delany/:
>
>> I can also quickly run a build to catch on issue
>> that I'm trying to eradicate by adding
>> -Dep="-XepDisableAllChecks -Xep:ReferenceEquality:ERROR"
>>
>> But having all those rules on one line makes reviewing changes a pain.
>> I don't really want to config the whole build with the compiler arguments.
>>
>> Is there a way to specify these in a properties file and have each
>> argument on its own line?
>
> Have you tried using @file (a-la javadoc options):
>
> https://docs.oracle.com/en/java/javase/17/docs/specs/man/javac.html#command-line-argument-files
Maybe:
-Dep=@myoptions
And in "myoptions" file:
-XepDisableAllChecks
-Xep:ReferenceEquality:ERROR
--
Stanimir
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org
Re: passing compiler args via a properties file
Posted by Stanimir Stamenkov <s7...@netscape.net.INVALID>.
Sun, 24 Sep 2023 15:45:49 +0200, /Delany/:
> [...]
> Is there a way to specify these in a properties file and have each argument
> on its own line?
Have you tried using @file (a-la javadoc options):
https://docs.oracle.com/en/java/javase/17/docs/specs/man/javac.html#command-line-argument-files
--
Stanimir
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org