Support commercial repositories in effective BOM and Ivy

Update `BomExtension` to resolve '{spring.mavenRepositories}' and add
credentials to `ivysettings.xml` and `settings.xml`.

Closes gh-44050
This commit is contained in:
Phillip Webb 2025-02-03 16:55:32 -08:00
parent fd5180645e
commit 80e8ab8779
4 changed files with 22 additions and 14 deletions

View File

@ -59,6 +59,7 @@ import org.w3c.dom.Document;
import org.w3c.dom.NodeList;
import org.springframework.boot.build.DeployedPlugin;
import org.springframework.boot.build.RepositoryTransformersExtension;
import org.springframework.boot.build.bom.Library.Exclusion;
import org.springframework.boot.build.bom.Library.Group;
import org.springframework.boot.build.bom.Library.LibraryVersion;
@ -132,6 +133,8 @@ public class BomExtension {
public void effectiveBomArtifact() {
Configuration effectiveBomConfiguration = this.project.getConfigurations().create("effectiveBom");
RepositoryTransformersExtension repositoryTransformers = this.project.getExtensions()
.getByType(RepositoryTransformersExtension.class);
this.project.getTasks()
.matching((task) -> task.getName().equals(DeployedPlugin.GENERATE_POM_TASK_NAME))
.all((task) -> {
@ -144,8 +147,10 @@ public class BomExtension {
sync.dependsOn(task);
sync.setDestinationDir(generatedBomDir);
sync.from(((GenerateMavenPom) task).getDestination(), (pom) -> pom.rename((name) -> "pom.xml"));
sync.from(this.project.getResources().getText().fromString(loadSettingsXml()),
(settingsXml) -> settingsXml.rename((name) -> "settings.xml"));
sync.from(this.project.getResources().getText().fromString(loadSettingsXml()), (settingsXml) -> {
settingsXml.rename((name) -> "settings.xml");
settingsXml.filter(repositoryTransformers.mavenSettings());
});
});
File effectiveBom = this.project.getLayout()
.getBuildDirectory()

View File

@ -7,17 +7,7 @@
<activeByDefault>true</activeByDefault>
</activation>
<repositories>
<repository>
<id>spring-snapshot</id>
<url>https://repo.spring.io/snapshot</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
<repository>
<id>spring-milestone</id>
<url>https://repo.spring.io/milestone</url>
</repository>
<!-- {spring.mavenRepositories} -->
</repositories>
</profile>
</profiles>

View File

@ -11,5 +11,6 @@
<!-- {spring.mavenRepositories} -->
</chain>
</resolvers>
<credentials host="${env.COMMERCIAL_RELEASE_REPO_URL}" username="${env.COMMERCIAL_REPO_USERNAME}" passwd="${env.COMMERCIAL_REPO_PASSWORD}"/>
<credentials host="${env.COMMERCIAL_SNAPSHOT_REPO_URL}" username="${env.COMMERCIAL_REPO_USERNAME}" passwd="${env.COMMERCIAL_REPO_PASSWORD}"/>
</ivysettings>

View File

@ -1,6 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<settings>
<localRepository>@localRepositoryPath@</localRepository>
<servers>
<server>
<id>spring-commercial-release</id>
<username>${env.COMMERCIAL_REPO_USERNAME}</username>
<password>${env.COMMERCIAL_REPO_PASSWORD}</password>
</server>
<server>
<id>spring-commercial-snapshot</id>
<username>${env.COMMERCIAL_REPO_USERNAME}</username>
<password>${env.COMMERCIAL_REPO_PASSWORD}</password>
</server>
</servers>
<profiles>
<profile>
<id>it-repo</id>