Closed maybeec closed 3 years ago
I disagree and have a different PoV: There is no generic way to find out the location of the local maven repository without completly embedding maven, parsing settings.xml, etc. We so far have 3 ways to guess the local repo location:
M2_REPO
variableCodeSource
file path via relative lookupgetDefaultLocalRepository()
from ~/.m2/repository
I am OK to change the order/priorities but removing 1. is IMHO simply wrong.
Option 2. can point to something like ./target/classes
what will never lead us to the local maven repo.
And Option 3. is a default guess but may also be wrong.
After removing 1. that is no chance left for the user to take control if 2. does not work and 3. comes to the wrong result.
Further for 1. I see two options:
A. The variable is not set and then it will make no harm.
B. The variable is set and then I would strongly assume that the value is pointing to the correct local repo. Why would someone set M2_REPO=banana
?
Can you let me know what the value of M2_REPO
is in your github action and why this is wrong?
BTW: A real alternative would be to parse the settings.xml
via Maven library and get the local repository properly from the configuration and default fallbacks. However, this will be slower and therefore increase the time to "boostrap".
I finally implemented the save, but slower solution: https://github.com/devonfw/cobigen/blob/master/cobigen/cobigen-core-api/src/main/java/com/devonfw/cobigen/api/util/MavenUtil.java#L82 and ask maven directly to not need to reimplement the correct mvn repository path in all situations.
Github Actions runners come with a set of pre defined environment variables. https://www.theserverside.com/blog/Coffee-Talk-Java-News-Stories-and-Opinions/environment-variables-full-list-github-actions
See the values for windows machines, which in my case break the build as the repository used by mvn is different to what is specified in M2_REPO. I was searching for a specification of M2_REPO but it's not at all related to conventions of maven, only relates to eclipse. Therefore I think we definitely need to get it out of first priority in path determination.
@maybeec thanks for your analysis and feedback. I am still thinking to use maven-core in order to resolve settings so you would not need to run such quirks from outside. Shall we close this PR and I create a new issue for the improvement of reliable repository resolution? Or would you suggest something else to proceed?
Totally fine, we can close this. If there is a programmatic way of finding the current repository, this definitively would be preferable.
Currently, M2_REPO is taken as the primary source for determining the maven repository path. Nevertheless, this variable is eclipse specific and has not been standardized by Maven at all. In GitHub Actions this causes trouble determining the correct maven repository path.
I removed it as I don't see the benefit of having it in.