apache / maven-mvnd

Apache Maven Daemon
https://maven.apache.org/
Apache License 2.0
2.9k stars 207 forks source link

maven.multiModuleProjectDirectory is missing in DefaultSettingsBuildingRequest.getSystemProperties() #1031

Closed gzm55 closed 2 months ago

gzm55 commented 3 months ago

An EventSpy watching SettingsBuildingResult event, cannot get the multiModuleProjectDirectory from system properties.

cstamas commented 3 months ago

See related issues and discussions: https://issues.apache.org/jira/browse/MNG-6589

TL;DR: the mentioned property is NOT for public consumption. Moreover, as mvnd 1.0.0 (which version is affected?) is Maven 3.9.8 based, the issue https://issues.apache.org/jira/browse/MNG-7038 does NOT applies as it is Maven4.

gzm55 commented 3 months ago

See related issues and discussions: https://issues.apache.org/jira/browse/MNG-6589

TL;DR: the mentioned property is NOT for public consumption. Moreover, as mvnd 1.0.0 (which version is affected?) is Maven 3.9.8 based, the issue https://issues.apache.org/jira/browse/MNG-7038 does NOT applies as it is Maven4.

only affect mvnd 1.0.0.

Now mvnd 1.x is based on maven-3. How can we get or calculate the value of maven.multiModuleProjectDirectory for both mvnd 1.x and maven 3.x?

cstamas commented 3 months ago

You could pass it like this: https://github.com/cstamas/rrf-demo/blob/master/.mvn/maven.config#L2

Explanation: the used property is not a public property, should not be used (is an implementation detail). The new thing in Maven 3.9.x was ${session.rootDirectory} but alas, it is interpolated ONLY IN SETTINGS. Hence, if you just add foo=${session.rootDirectory} you will get the value as $foo among properties as well.

Maven4 makes this new property accessible in settings (like Maven 3.9.x) but also as properties (unlike Maven 3.9).

gzm55 commented 3 months ago

You could pass it like this: https://github.com/cstamas/rrf-demo/blob/master/.mvn/maven.config#L2

Explanation: the used property is not a public property, should not be used (is an implementation detail). The new thing in Maven 3.9.x was ${session.rootDirectory} but alas, it is interpolated ONLY IN SETTINGS. Hence, if you just add foo=${session.rootDirectory} you will get the value as $foo among properties as well.

Maven4 makes this new property accessible in settings (like Maven 3.9.x) but also as properties (unlike Maven 3.9).

thanks!

Tested on 3.9.8, rootDriectory depends on topDirectory. but session.topDirectory seems always be resolved to PWD when invoked with -f /path/to/pom.xml

korthout commented 3 months ago

I also run into the issue that maven.multiModuleProjectDirectory is no longer available.

I don't understand how to apply this proposed solution. Creating a .mvn/maven.config file with this -Daether.remoteRepositoryFilter.prefixes.basedir=${session.rootDirectory}/.mvn/rrf/ line does not add maven.multiModuleProjectDirectory back. Perhaps I'm missing something.

I was able to work around it by passing it directly:

mvnd package -Dmaven.multiModuleProjectDirectory=$(pwd)

This is not a nice experience though. Especially, since I generally work in a subfolder somwhere (mvnd package -Dmaven.multiModuleProjectDirectory=$(pwd)/../). Any other ideas how to resolve this?

gzm55 commented 3 months ago

I also run into the issue that maven.multiModuleProjectDirectory is no longer available.

I don't understand how to apply this proposed solution. Creating a .mvn/maven.config file with this -Daether.remoteRepositoryFilter.prefixes.basedir=${session.rootDirectory}/.mvn/rrf/ line does not add maven.multiModuleProjectDirectory back. Perhaps I'm missing something.

I was able to work around it by passing it directly:

mvnd package -Dmaven.multiModuleProjectDirectory=$(pwd)

This is not a nice experience though. Especially, since I generally work in a subfolder somwhere (mvnd package -Dmaven.multiModuleProjectDirectory=$(pwd)/../). Any other ideas how to resolve this?

@korthout from 3.9.2, when call with mvn -f /path/X/pom.xml maven replaces ${session.topDirectory} and ${session.rootDirectory} in command line flags (including from .mvn/maven.config with /path/X and the value of ${maven.multiModuleProjectDirectory}. So we should put -Dmaven.multiModuleProjectDirectory=${session.rootDirectory} to pull back the old property.

But now maven 3.9.8 included by mvnd 1.0.0 has a bug (https://github.com/apache/maven/pull/1589) of not correctly dealing with -f flag.