Re: Why does POM have precedence over -D property expressions?

2020-09-16 Thread Bernd Eckenfels
Hello,

While I do agree that it is not very intuitive, I don’t think there is any 
chance to change this in a compatible way.

 Also it’s pretty easy to understand: just remember this simplification: you 
can only define properties, and if the configuration should be affected by them 
you need to have a property explicitly in the POMs or as implicated default 
value. With this info in mind Mojo Docs are much easier to read ;)

Gruß
Bernd
--
https://Bernd.eckenfels.net


Von: Andreas Sewe 
Gesendet: Mittwoch, September 16, 2020 10:02 AM
An: users@maven.apache.org
Betreff: Re: Why does POM  have precedence over -D property 
expressions?

Andy Feldman wrote:
>> My situation is unfortunately a bit more complex than that, as I have
>> *two* s of the maven-enforcer-plugin, only one of which
>> should be affected by -DskipChecks. The other simply uses the
>>  rule, which IMHO shouldn't easily be disabled (but
>> should still respect -Denforcer.skip)
>> [...]
>> What I want is this:
>> [...]
>
> -Denforcer.skip, being the more direct option, should
>> take precedence over -DskipChecks.
>
> Just an idea:
>
> 
>   false
>   ${enforcer.skip}
> 
>
> This way if you set -DskipChecks=true, then only checks would be
> skipped, but if you set -Denforcer.skip=true, it would also cause
> skipChecks to be true, so both executions would be skipped. I haven't
> actually tested it though.

Thanks, Andy. The above does have the desired behavior *if* the
maven-enforcer-plugin were the only plugin which should be governed by
-DskipChecks.

But as I said in my initial mail, that property should also control the
maven-checkstyle-plugin, maven-tidy-plugin, and others (kine of like
-DskipTests does for maven-surefire-plugin and maven-failsafe-plugin).
And that's just not doable with

  ${enforcer.skip}

I experimented quite a bit yesterday and have become convinced that the
desired behavior is not possible, at least without profiles (ugh!) --
and even then I am not sure, as the profile would need to affect only
some executions.

But maybe I am missing something.

Best wishes,

Andreas



Re: Why does POM have precedence over -D property expressions?

2020-09-16 Thread Andreas Sewe
Andy Feldman wrote:
>> My situation is unfortunately a bit more complex than that, as I have
>> *two* s of the maven-enforcer-plugin, only one of which
>> should be affected by -DskipChecks. The other simply uses the
>>  rule, which IMHO shouldn't easily be disabled (but
>> should still respect -Denforcer.skip)
>> [...]
>> What I want is this:
>> [...]
> 
> -Denforcer.skip, being the more direct option, should
>> take precedence over -DskipChecks.
> 
> Just an idea:
> 
> 
>   false
>   ${enforcer.skip}
> 
> 
> This way if you set -DskipChecks=true, then only checks would be
> skipped, but if you set -Denforcer.skip=true, it would also cause
> skipChecks to be true, so both executions would be skipped. I haven't
> actually tested it though.

Thanks, Andy. The above does have the desired behavior *if* the
maven-enforcer-plugin were the only plugin which should be governed by
-DskipChecks.

But as I said in my initial mail, that property should also control the
maven-checkstyle-plugin, maven-tidy-plugin, and others (kine of like
-DskipTests does for maven-surefire-plugin and maven-failsafe-plugin).
And that's just not doable with

  ${enforcer.skip}

I experimented quite a bit yesterday and have become convinced that the
desired behavior is not possible, at least without profiles (ugh!) --
and even then I am not sure, as the profile would need to affect only
some executions.

But maybe I am missing something.

Best wishes,

Andreas



signature.asc
Description: OpenPGP digital signature


Re: Why does POM have precedence over -D property expressions?

2020-09-15 Thread Andy Feldman
On Tue, Sep 15, 2020 at 1:12 PM Andreas Sewe 
wrote:

> My situation is unfortunately a bit more complex than that, as I have
> *two* s of the maven-enforcer-plugin, only one of which
> should be affected by -DskipChecks. The other simply uses the
>  rule, which IMHO shouldn't easily be disabled (but
> should still respect -Denforcer.skip)
> [...]
> What I want is this:
> [...]

-Denforcer.skip, being the more direct option, should
> take precedence over -DskipChecks.
>

Just an idea:


  false
  ${enforcer.skip}


This way if you set -DskipChecks=true, then only checks would be
skipped, but if you set -Denforcer.skip=true, it would also cause
skipChecks to be true, so both executions would be skipped. I haven't
actually tested it though.

--
Andy Feldman


Re: Why does POM have precedence over -D property expressions?

2020-09-15 Thread Andreas Sewe
Andy Feldman wrote:
> I guess you don't even need a custom property since each plugin tends to
> have one already. So a simpler property-based approach would just be:
> 
> 
>   ${skipChecks}
> 
> 
> And maybe you'd also need false in your properties
> to provide a default for when skipChecks isn't specified on the command
> line. But like I said, I haven't tried this approach so you'd have to
> experiment and see if it works for you.

Thank you, Andy, for the suggestions.

My situation is unfortunately a bit more complex than that, as I have
*two* s of the maven-enforcer-plugin, only one of which
should be affected by -DskipChecks. The other simply uses the
 rule, which IMHO shouldn't easily be disabled (but
should still respect -Denforcer.skip)

  
org.apache.maven.plugins
maven-enforcer-plugin

  
enforce-maven-version/id>

  enforce


  

  [3.6,4)

  
   
 
 
checks

  enforce


  $[skipChecks}
  

  

  

  

I can't think of a way to use  to get the desired behavior
in this case, at least not without resorting to profiles -- which I am
trying to avoid, as they seem to be frowned upon for this kind of stuff.

What I want is this:

  no property -> enforce-maven-version, checks

  -DskipChecks=false -> enforce-maven-version, checks

  -DskipChecks=true -> enforce-maven-version

  -Denforcer.skip=true -> no executions

  -Denforcer.skip=false, -DskipChecks=true -> enforce-maven-version,
checks (but possibly other checks predicated on skipChecks)

  etc.

In other words, -Denforcer.skip, being the more direct option, should
take precedence over -DskipChecks.

Any ideas?

Best wishes,

Andreas Sewe



signature.asc
Description: OpenPGP digital signature


Re: Why does POM have precedence over -D property expressions?

2020-09-15 Thread Andreas Sewe
Oliver B. Fischer wrote:
> I had the same question some days back
> (https://mail-archives.apache.org/mod_mbox/maven-users/202009.mbox/%3C922b4efc-3296-d35d-0675-d6c0090cc4b1%40swe-blog.net%3E)
> and Stuart McCulloch sent me a link to this JIRA issue:
> https://issues.apache.org/jira/browse/MNG-4979

Thanks for the pointer, Oliver. I also thought this behavior was a bug
and even tested with different Maven versions, assuming that this was a
regression.

> So, this seems to be a recurring issue that irritates a lot of people.

Yes, it is very irritating and I don't really buy Robert Scholte's
argument [1] that this is a feature rather than a bug.

Yes, it allows you to lock-in critical configuration options and make
them read-only, but to be on the safe side, you would need to do this
for *every* option of your plug-ins, which is obviously undesirable.

Also, if you break something with a manual override via the
command-line, the cause is normally crystal-clear, as you just added the
-D to the invocation; it's not something that snuck in using some
configuration file the user didn't even know about.

I hence really wish MNG-4979 would be reconsidered, maybe for Maven 4.

Best wishes,

Andreas

[1] 



signature.asc
Description: OpenPGP digital signature


Re: Why does POM have precedence over -D property expressions?

2020-09-14 Thread Oliver B. Fischer


-BEGIN PGP SIGNED MESSAGE-
Hash: SHA256


I had the same question some days back
(https://mail-archives.apache.org/mod_mbox/maven-users/202009.mbox/%3C922b4efc-3296-d35d-0675-d6c0090cc4b1%40swe-blog.net%3E)
and Stuart McCulloch sent me a link to this JIRA issue:
https://issues.apache.org/jira/browse/MNG-4979

So, this seems to be a recurring issue that irritates a lot of people.

Oliver

Am 14.09.20 um 18:11 schrieb Andreas Sewe:
> Hi,
>
> I am currently sprinkling  child elements like the
> following through my (parent) POMs for enforcer:enforce, tidy:check and
> checkstyle:check :
>
>   ${skipChecks}
>
> This allows me to skip all kinds of checks with a simple
> -DskipChecks=true (or even -DskipChecks), just like I am used to for
> tests with -DskipTests.
>
> Unfortunately, I cannot selectively override this, as the following
> doesn't work:
>
>   mvn install -DskipChecks -Denforcer.skip=false
>
> The above command still uses the ${skipChecks} (with
> skipChecks=true).
>
> Further experimentation led me to believe that *any* explicit pom.xml
>  cannot be overridden by a property expression given on
> the command line.
>
> This was very surprising, as I would have expected Maven to follow a
> "command line takes precedence over configuration file" approach like
> other tools -- but apparently it doesn't (at least in Maven 3.3.9 and
> 3.6.3) and thus violates the Principle of Least Astonishment (for one of
> its users anyway).
>
> In particular, Maven's handling of property expressions means that
> having no  element and making the default explicit behave
> differently; a  element like this can never be overridden
> on the command-line:
>
>   false
>
> I wonder why it was designed that way?
>
> Or should this be considered a bug?
>
> Best wishes,
>
> Andreas
>
- -- 
N Oliver B. Fischer
A Schönhauser Allee 64, 10437 Berlin, Deutschland/Germany
P +49 30 44793251
M +49 178 7903538
E o.b.fisc...@swe-blog.net
S oliver.b.fischer
J oliver.b.fisc...@jabber.org
X http://xing.to/obf
-BEGIN PGP SIGNATURE-

iQIzBAEBCAAdFiEEU7j685HGR9cAsMGwB88X6wLziPwFAl9fzxAACgkQB88X6wLz
iPzd/w/9FFSjkXtHrspdg9z8sV5tXEEXIGJdw1XRcDL8SDl412GmCIoCN5+HuYSa
MIMyGrmlsMgdeHUkx/0wvUXLBjmV7oEiAIhiLhA4l25F3Qc+y5zoUxZIUjNbZiZu
4oR04RZcrIdBA67sdxkvhQfM8rnv4/P97L70CVZpA8/nFNDjYWrG2troCTLMn6MI
NmjiYMpmG9xHDxy3KkqJqXwfEZDmEqphYV2K4T18EOcw5dP7ZJBK3sHXczK93Wkz
eTrDDgVcBHexSR2aqGX6xlNdtR4UScsCJjsXpnCZq/09qS9pOduBCIPX8Cswsi7B
d1nFKmNR41TpZtQFv8LCrbNkK5FBSupsxrOGgKjGza70y3JPki13I15tKZjnMZFY
CvaSK36VzEQOMVaZL5TB1ybXvF9OWXJgwqGT1dYCoCm3WDFCdGka3igVKKJWEE/P
xriYNkmzhKuKY5mAJa7wpXa1DQLnraFLcIPTEHNKLYocct58yRGtsgCvx7FIXflY
rtfou8+b5Q6FGHJcGpTiL7Zh191nV1gUJJA3ZXJwGzdvs+tvwLYPj34+5LNvwj0z
Ax1MKZLllCfq2wLm8NAnVqHYh55K5YN5O/jG+Fk9Mw87ynj+Tn9qIQ9jQ7nGIVyv
nvF87+KgBTQE5OFSpmLvDJEkN+zPqnp81VDkjNdMUSj16kcgAw8=
=oPqj
-END PGP SIGNATURE-


-
To unsubscribe, e-mail: users-unsubscr...@maven.apache.org
For additional commands, e-mail: users-h...@maven.apache.org



Re: Why does POM have precedence over -D property expressions?

2020-09-14 Thread Tomo Suzuki
> *any* explicit pom.xml  cannot be overridden by a property
expression given on
> the command line.

I also encountered the problem when my Maven project has multiple main
classes and I wanted to run them by switching "mvn exec:java
-Dexec.mainClass=...' while keeping the default one in pom.xml. I don't
know why Maven is designed in that way.

Good to know the use of properties to control it. Thank you.

-- 
Regards,
Tomo


Re: Why does POM have precedence over -D property expressions?

2020-09-14 Thread Andy Feldman
I guess you don't even need a custom property since each plugin tends to
have one already. So a simpler property-based approach would just be:


  ${skipChecks}


And maybe you'd also need false in your properties
to provide a default for when skipChecks isn't specified on the command
line. But like I said, I haven't tried this approach so you'd have to
experiment and see if it works for you.


On Mon, Sep 14, 2020 at 10:38 AM Andy Feldman  wrote:

> I agree this behavior is unexpected. But it's different for properties! So
> a workaround here is to have a unique property for each check you want to
> skip, so that you can override the property by command line rather than
> overriding the  configuration directly. Then you can have a single
> way to set all these properties. In my company's parent pom we have a
> profile that can be activated like `mvn install -P quick` to skip tests and
> checks:
>
> 
>   quick
>   
> true
> true
> true
> true
> true
>   
> 
>
> So if I want to still run the enforcer plugin, I can do this: `mvn install
> -P quick -Denforcer.skip=false`.
>
> If you want to keep using a property rather than a profile, I assume you
> could have the specific property for each check reference your main
> property by default, like:
>
> 
>   ${skipChecks}
> 
> [...]
> ${skip.our.enforcer}
>
> But I haven't tested it.
>
>
> On Mon, Sep 14, 2020 at 9:11 AM Andreas Sewe <
> andreas_s...@buildingblobs.com> wrote:
>
>> Hi,
>>
>> I am currently sprinkling  child elements like the
>> following through my (parent) POMs for enforcer:enforce, tidy:check and
>> checkstyle:check :
>>
>>   ${skipChecks}
>>
>> This allows me to skip all kinds of checks with a simple
>> -DskipChecks=true (or even -DskipChecks), just like I am used to for
>> tests with -DskipTests.
>>
>> Unfortunately, I cannot selectively override this, as the following
>> doesn't work:
>>
>>   mvn install -DskipChecks -Denforcer.skip=false
>>
>> The above command still uses the ${skipChecks} (with
>> skipChecks=true).
>>
>> Further experimentation led me to believe that *any* explicit pom.xml
>>  cannot be overridden by a property expression given on
>> the command line.
>>
>> This was very surprising, as I would have expected Maven to follow a
>> "command line takes precedence over configuration file" approach like
>> other tools -- but apparently it doesn't (at least in Maven 3.3.9 and
>> 3.6.3) and thus violates the Principle of Least Astonishment (for one of
>> its users anyway).
>>
>> In particular, Maven's handling of property expressions means that
>> having no  element and making the default explicit behave
>> differently; a  element like this can never be overridden
>> on the command-line:
>>
>>   false
>>
>> I wonder why it was designed that way?
>>
>> Or should this be considered a bug?
>>
>> Best wishes,
>>
>> Andreas
>>
>>


Re: Why does POM have precedence over -D property expressions?

2020-09-14 Thread Andy Feldman
I agree this behavior is unexpected. But it's different for properties! So
a workaround here is to have a unique property for each check you want to
skip, so that you can override the property by command line rather than
overriding the  configuration directly. Then you can have a single
way to set all these properties. In my company's parent pom we have a
profile that can be activated like `mvn install -P quick` to skip tests and
checks:


  quick
  
true
true
true
true
true
  


So if I want to still run the enforcer plugin, I can do this: `mvn install
-P quick -Denforcer.skip=false`.

If you want to keep using a property rather than a profile, I assume you
could have the specific property for each check reference your main
property by default, like:


  ${skipChecks}

[...]
${skip.our.enforcer}

But I haven't tested it.


On Mon, Sep 14, 2020 at 9:11 AM Andreas Sewe 
wrote:

> Hi,
>
> I am currently sprinkling  child elements like the
> following through my (parent) POMs for enforcer:enforce, tidy:check and
> checkstyle:check :
>
>   ${skipChecks}
>
> This allows me to skip all kinds of checks with a simple
> -DskipChecks=true (or even -DskipChecks), just like I am used to for
> tests with -DskipTests.
>
> Unfortunately, I cannot selectively override this, as the following
> doesn't work:
>
>   mvn install -DskipChecks -Denforcer.skip=false
>
> The above command still uses the ${skipChecks} (with
> skipChecks=true).
>
> Further experimentation led me to believe that *any* explicit pom.xml
>  cannot be overridden by a property expression given on
> the command line.
>
> This was very surprising, as I would have expected Maven to follow a
> "command line takes precedence over configuration file" approach like
> other tools -- but apparently it doesn't (at least in Maven 3.3.9 and
> 3.6.3) and thus violates the Principle of Least Astonishment (for one of
> its users anyway).
>
> In particular, Maven's handling of property expressions means that
> having no  element and making the default explicit behave
> differently; a  element like this can never be overridden
> on the command-line:
>
>   false
>
> I wonder why it was designed that way?
>
> Or should this be considered a bug?
>
> Best wishes,
>
> Andreas
>
>


Why does POM have precedence over -D property expressions?

2020-09-14 Thread Andreas Sewe
Hi,

I am currently sprinkling  child elements like the
following through my (parent) POMs for enforcer:enforce, tidy:check and
checkstyle:check :

  ${skipChecks}

This allows me to skip all kinds of checks with a simple
-DskipChecks=true (or even -DskipChecks), just like I am used to for
tests with -DskipTests.

Unfortunately, I cannot selectively override this, as the following
doesn't work:

  mvn install -DskipChecks -Denforcer.skip=false

The above command still uses the ${skipChecks} (with
skipChecks=true).

Further experimentation led me to believe that *any* explicit pom.xml
 cannot be overridden by a property expression given on
the command line.

This was very surprising, as I would have expected Maven to follow a
"command line takes precedence over configuration file" approach like
other tools -- but apparently it doesn't (at least in Maven 3.3.9 and
3.6.3) and thus violates the Principle of Least Astonishment (for one of
its users anyway).

In particular, Maven's handling of property expressions means that
having no  element and making the default explicit behave
differently; a  element like this can never be overridden
on the command-line:

  false

I wonder why it was designed that way?

Or should this be considered a bug?

Best wishes,

Andreas



signature.asc
Description: OpenPGP digital signature