Skip to content

[MNG-5913] Allow defining aliases for existing server configurations in settings.xml#2333

Open
slawekjaranowski wants to merge 7 commits intoapache:masterfrom
slawekjaranowski:MNG-5913
Open

[MNG-5913] Allow defining aliases for existing server configurations in settings.xml#2333
slawekjaranowski wants to merge 7 commits intoapache:masterfrom
slawekjaranowski:MNG-5913

Conversation

@slawekjaranowski
Copy link
Copy Markdown
Member

Add the next tag ids to the server in settings.xml

Additional server will be created in memory by SettingsBuilder, so the generated configuration should be transparent to other as Settings#getServers() will return complete list.


https://issues.apache.org/jira/browse/MNG-5913

@slawekjaranowski slawekjaranowski added the enhancement New feature or request label May 13, 2025
@slawekjaranowski slawekjaranowski self-assigned this May 13, 2025
@cstamas
Copy link
Copy Markdown
Member

cstamas commented May 13, 2025

This needs to be made sure will not break Maven 3, as same settings is shared by both currently.

@slawekjaranowski
Copy link
Copy Markdown
Member Author

This needs to be made sure will not break Maven 3, as same settings is shared by both currently.

unit test, looks ok for me.

I tested with: mvn help:effective-settings

@slawekjaranowski
Copy link
Copy Markdown
Member Author

ok, who is willing to work on it with me?
If proposition will be generally accepted I will do similar in 3.9.x

I hope such feature will be valuable.

@cstamas
Copy link
Copy Markdown
Member

cstamas commented May 14, 2025

Well, settings with current 3.9.9 are NOT read:

[WARNING] 
[WARNING] Some problems were encountered while building the effective settings
[WARNING] Unrecognised tag: 'aliases' (position: START_TAG seen ...</id>\n     <aliases>... @61:15)  @ /home/cstamas/.m2/settings.xml, line 61, column 15
[WARNING] 

Or this is "ok"? Is settings loaded partially or discaded?

@cstamas
Copy link
Copy Markdown
Member

cstamas commented May 14, 2025

I am willing to jump in as Njord does something similar, but my concern is that Maven 3.x is not "forgiving" while readint settings.xml AFAIK. And if we modify XML then things like ./mvnw will work ONLY (for user) if 3.9.10 used?

@slawekjaranowski
Copy link
Copy Markdown
Member Author

Well, settings with current 3.9.9 are NOT read:

[WARNING] 
[WARNING] Some problems were encountered while building the effective settings
[WARNING] Unrecognised tag: 'aliases' (position: START_TAG seen ...</id>\n     <aliases>... @61:15)  @ /home/cstamas/.m2/settings.xml, line 61, column 15
[WARNING] 

Or this is "ok"? Is settings loaded partially or discaded?

it is correct because 3.9.x does not have it yet

@slawekjaranowski
Copy link
Copy Markdown
Member Author

I am willing to jump in as Njord does something similar, but my concern is that Maven 3.x is not "forgiving" while readint settings.xml AFAIK. And if we modify XML then things like ./mvnw will work ONLY (for user) if 3.9.10 used?

I hope we can have next version of settings schema for 3.9.x ... so if someone update own settings alos will use newer version of Maven

Copy link
Copy Markdown
Contributor

@Pankraz76 Pankraz76 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

already very nice.
please give last dedication, to reach infinitive higher-order function.

Copy link
Copy Markdown
Contributor

@Pankraz76 Pankraz76 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

polish

@slawekjaranowski
Copy link
Copy Markdown
Member Author

@gnodet @Pankraz76 last suggestions applied

Copy link
Copy Markdown
Contributor

@Pankraz76 Pankraz76 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

init by default

@Pankraz76
Copy link
Copy Markdown
Contributor

Pankraz76 commented May 15, 2025

why we need to change deprecated stuff?

PMD or rewrite, might even do both.
Spot seems ending up being short:

@slawekjaranowski
Copy link
Copy Markdown
Member Author

why we need to change deprecated stuff?

Found this one related:

deprecated staff can be used by Maven 3 plugins - we need support backward compatibility for Maven 3.x

@slawekjaranowski
Copy link
Copy Markdown
Member Author

@gnodet @cstamas any more comments for it?

I will cleanups from comments and will be ready.

@cstamas
Copy link
Copy Markdown
Member

cstamas commented May 17, 2025

I am still unconvinced that this change is backward compatible. Or the idea is that whoever uses this feature must use Maven 4 or latest (upcoming) Maven 3.9.10? What happens if by mistake (or project mvnw) is 3.9.9 or 3.8.8?

@slawekjaranowski
Copy link
Copy Markdown
Member Author

I am still unconvinced that this change is backward compatible. Or the idea is that whoever uses this feature must use Maven 4 or latest (upcoming) Maven 3.9.10? What happens if by mistake (or project mvnw) is 3.9.9 or 3.8.8?

Confirm - for new future Maven 4.x (rc-4+) and 3.9.10+ will be needed.

Such futures will be needed for deployments or for special environments where users use more private repositories.
So if user want to use it simply needs the latest version of Maven.

For older Maven warning will be printed.

@cstamas
Copy link
Copy Markdown
Member

cstamas commented May 17, 2025

For older Maven warning will be printed.

I am aware of warning, but am unaware what exactly happens when that warning is printed: is whole settings ignored, is only the server (with unknown element) ignored... Given we talk about same file that all Maven 3+ would use, I think we need to be careful here. Maven is already printing a LOT to screen, is very easy to miss one line warning and then tinker why build/deploy/whatever failed...

@slawekjaranowski
Copy link
Copy Markdown
Member Author

As I see from my testing only unparsable settings.xml break a Maven build at all
settings.xml with correct xml syntax, but with unkown tags are processed, all recognized settings are correctly read

I can add IT for such case - what happens with unrecognized tag in settings.xml - in separate PR if can help you

@slawekjaranowski
Copy link
Copy Markdown
Member Author

Kindly reminder - Any more comments here? Anything what I can do more ...?

If there are no more requests, I would like to merge it

Copy link
Copy Markdown
Member

@michael-o michael-o left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I consider it as confusing having <id/> and <ids/> as subelements. I think this needs to be in Maven 4 first, RC and then in 3.9.x. I think that one server element should have a unique ID and then <aliases/>.

There is also a JIRA issue which requests to completely decouple credentials from server elements. Which makes creds reusable throughout.

@michael-o
Copy link
Copy Markdown
Member

Looking at this I am still convinced that is should not be delivered with 3.9.10.

@michael-o
Copy link
Copy Markdown
Member

@michael-o
Copy link
Copy Markdown
Member

Yet another problem is that we are abusing one server structure for multiple ones, e.g., you are settings headers or other transport-related config. It will be applied to mulitple servers, but you need to split them up actually except credentials.

@jira-importer
Copy link
Copy Markdown

Resolve #7757

…in settings.xml

Add the next tag ids to the server in settings.xml

Additional server will be created in memory by SettingsBuilder,
so the generated configuration should be transparent to other
as Settings#getServers() will return complete list.
@slawekjaranowski
Copy link
Copy Markdown
Member Author

@michael-o @cstamas I refreshed a PR 😄 with last suggestions

to build pass I need fixes in modello - in progress

@michael-o
Copy link
Copy Markdown
Member

Will check next week...

<version>1.3.0+</version>
<description>
List of additional server aliases. For each alias, an additional server will be generated by copying the entire configuration, but using a different ID.
This is useful when the same credentials should be used for multiple servers. </description>
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trailing whitespace

.id(id)
.aliases(List.of())
.build());
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks very ugly. It is the clien't responsibility to traverse the Settings object, no?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is the core of change.

Based on additional tag - aliases we create a next server instance in memory on server list.
So all others plugins tools will see destination list of servers original declared in settings and created based on aliases tag.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do remember that Modello allows to add Java code to Settings. Why can't we inject/improve the code in the model directly?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so you propose to override a getServers method directly in modelo?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, correct.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, I will check if it will be easier?

Copy link
Copy Markdown
Member Author

@slawekjaranowski slawekjaranowski Apr 14, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@michael-o
It will be impossible (in easy way) to implement in code settings.mdo, we use velocity templates to generate code for 4.x and for 3.x.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Share the spot where this is done. Modello made it possible :-(

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Share the spot where this is done. Modello made it possible :-(

There is two templates for generating output from modello files:
https://github.com/apache/maven/blob/master/src/mdo/model.vm
https://github.com/apache/maven/blob/master/src/mdo/model-v3.vm

I see some of code in settings.mdo so will look again

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see a way to provide such code in settings.mdo

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants