> For certain git branches, I want to use a different .m2 folder.
Even if possible maybe revisit why you need this?

In any case, Maven supports (since 3.3 or something) that you can have
a local ".mvn" folder in your project.
See this:  https://maven.apache.org/configure.html
This makes it easy to use a per-project localRepository. NetBeans IDE
will respect this.
You can add the ".mvn" folder to git, or not, depending on your needs.

But the hard part is that your Maven config will be dynamic, it will
depend on your branch name. You can of course check in the ".mvn"
folder to Git and let it have different values in different branches.
Ta da. Problem solved. It is not dynamic, though.
(I don't personally like it, but YMMV)

Throwing out (other) ideas:

Dynamic solution: You obviously need something that picks up your
current git branch (executes a git command to get that info) and then
uses that to configure the actual mvn execution. So, imagine that
you've done that and the branch name is now in a variable called
GIT_BRANCH and that the branch name is suitable as a folder name. Then
your "mvn" execution becomes (example):

mvn -Dmaven.repo.local=.m2/$GIT_BRANCH clean install

(when doing it on the command line like this it will override the
localRepository setting in the settings.xml file)


Another thought: Maven command execution shell still supports a
"$HOME/.mavenrc" file which is executed (sourced) by Maven before it
does anything else. It will be fired each and every time you execute
the "mvn" command. I don't know if it will be respected by the
NetBeans IDE? (I would think not since NetBeans IDE executes Maven
from the Java level, not via the OS shell).
I believe the ",mavenrc" feature is a bit deprecated by the Maven
project, but don't know for sure. In that file you could have shell
command to determine the current GIT branch name and then set the
MAVEN_OPTS env var accordingly.


But overall:

I got a feeling that your are trying to do something locally (catering
to builds from multiple branches which should not "interfere" with
each other) which is normally a concern handled by your CI pipeline.
Locally you would work on one branch/feature at a time.


Best of luck.

Lars

On Fri, Jan 26, 2024 at 6:20 PM Pieter van den Hombergh
<pieter.van.den.hombe...@gmail.com> wrote:
>
> maybe you want to use profiles for this, which can be added in the pom.xml 
> proper.
> that would at least shorten the commandline, but is also an artefact of the 
> project and would be the better option imho.
>
> met vriendelijke groet
> Pieter van den Hombergh
>
> Op vr 26 jan 2024 17:01 schreef Nelligan, Steven M <snell...@illinois.edu>:
>>
>>
>> In the maven Tools\Options\Java\Maven, there is a prompt for Global 
>> Execution Options:
>> Currently I use -U -SkipTests -gs C:\Users\XXXX\m2_for_project\.m2\settings 
>> -s C: \Users\XXXX\m2_for_project \.m2\settings.xml
>> The settings.xml file contain a localRepository tag which points to 
>> different .m2 folders.
>>
>> For certain git branches, I want to use a different .m2 folder.
>>
>> Currently I edit the above setting when I change the git branch.
>>
>> I was wondering if it would work, if I store the setting.xml file in git and 
>> then reference it in the above settings file.
>> i.e. c:\dev\gitFolder\mavenFolder\settings.xml
>>
>> Any options or comments on the above?
>>
>>
>> Thanks in advance,
>>
>> STEVEN M NELLIGAN
>> SENIOR SOFTWARE DEVELOPER
>>
>> Facilities and Services
>> Information Technology Services
>> University of Illinois at Urbana-Champaign
>> Facilities and Services
>> 1501 S. Oak Street | M/C 800
>> Champaign, IL 61820
>>
>> Under the Illinois Freedom of Information Act any written communication to 
>> or from university employees regarding university business is a public 
>> record and may be subject to public disclosure.
>>
>>
>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscr...@netbeans.apache.org
>> For additional commands, e-mail: users-h...@netbeans.apache.org
>>
>> For further information about the NetBeans mailing lists, visit:
>> https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists
>>

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

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists

Reply via email to