diff --git a/initializr-docs/src/main/asciidoc/configuration-guide.adoc b/initializr-docs/src/main/asciidoc/configuration-guide.adoc index 80026c48..e15a1a32 100644 --- a/initializr-docs/src/main/asciidoc/configuration-guide.adoc +++ b/initializr-docs/src/main/asciidoc/configuration-guide.adoc @@ -445,6 +445,8 @@ initializr: artifactId: acme-foo-dependencies mappings: - versionRange: "[1.2.3.RELEASE,1.3.0.RELEASE)" + groupId: com.example.bar + artifactId: acme-foo-bom version: Arcturus.SR6 - versionRange: "[1.3.0.RELEASE,1.4.0.RELEASE)" version: Botein.SR7 @@ -461,7 +463,8 @@ initializr: The primary use case here is to map Spring Boot versions to the preferred or supported versions of the Foo project. You can also see that for the milestone and snapshot BOMs, additional repositories are declared because those artifacts are not in the default -repository. +repository. Initially the BOM was identified as `com.example.bar:acme-foo-bom` and renamed +as of `Botein` to `com.example.foo:acme-foo-dependencies`. TIP: We also use the `x` trick in version ranges to avoid updating the range every time a new Spring Boot 1.5 bug fix release is available diff --git a/initializr-generator/src/main/java/io/spring/initializr/metadata/BillOfMaterials.java b/initializr-generator/src/main/java/io/spring/initializr/metadata/BillOfMaterials.java index a125ec9f..89e094dd 100644 --- a/initializr-generator/src/main/java/io/spring/initializr/metadata/BillOfMaterials.java +++ b/initializr-generator/src/main/java/io/spring/initializr/metadata/BillOfMaterials.java @@ -190,8 +190,11 @@ public class BillOfMaterials { for (Mapping mapping : this.mappings) { if (mapping.range.match(bootVersion)) { - BillOfMaterials resolvedBom = new BillOfMaterials(this.groupId, - this.artifactId, mapping.version); + BillOfMaterials resolvedBom = new BillOfMaterials( + (mapping.groupId != null) ? mapping.groupId : this.groupId, + (mapping.artifactId != null) ? mapping.artifactId + : this.artifactId, + mapping.version); resolvedBom.setVersionProperty(this.versionProperty); resolvedBom.setOrder(this.order); resolvedBom.repositories.addAll(!mapping.repositories.isEmpty() @@ -233,10 +236,21 @@ public class BillOfMaterials { /** * Mapping information. */ + @JsonInclude(JsonInclude.Include.NON_EMPTY) public static class Mapping { private String versionRange; + /** + * The groupId to use for this mapping or {@code null} to use the default. + */ + private String groupId; + + /** + * The artifactId to use for this mapping or {@code null} to use the default. + */ + private String artifactId; + private String version; private List repositories = new ArrayList<>(); @@ -272,10 +286,34 @@ public class BillOfMaterials { return this.versionRange; } + public void setVersionRange(String versionRange) { + this.versionRange = versionRange; + } + + public String getGroupId() { + return this.groupId; + } + + public void setGroupId(String groupId) { + this.groupId = groupId; + } + + public String getArtifactId() { + return this.artifactId; + } + + public void setArtifactId(String artifactId) { + this.artifactId = artifactId; + } + public String getVersion() { return this.version; } + public void setVersion(String version) { + this.version = version; + } + public List getRepositories() { return this.repositories; } @@ -288,14 +326,6 @@ public class BillOfMaterials { return this.range; } - public void setVersionRange(String versionRange) { - this.versionRange = versionRange; - } - - public void setVersion(String version) { - this.version = version; - } - public void setRepositories(List repositories) { this.repositories = repositories; } @@ -313,6 +343,9 @@ public class BillOfMaterials { return "Mapping [" + ((this.versionRange != null) ? "versionRange=" + this.versionRange + ", " : "") + + ((this.groupId != null) ? "groupId=" + this.groupId + ", " : "") + + ((this.artifactId != null) ? "artifactId=" + this.artifactId + ", " + : "") + ((this.version != null) ? "version=" + this.version + ", " : "") + ((this.repositories != null) ? "repositories=" + this.repositories + ", " : "") diff --git a/initializr-generator/src/test/java/io/spring/initializr/metadata/BillOfMaterialsTests.java b/initializr-generator/src/test/java/io/spring/initializr/metadata/BillOfMaterialsTests.java index d4ecd6ad..35d9ff96 100755 --- a/initializr-generator/src/test/java/io/spring/initializr/metadata/BillOfMaterialsTests.java +++ b/initializr-generator/src/test/java/io/spring/initializr/metadata/BillOfMaterialsTests.java @@ -63,6 +63,29 @@ public class BillOfMaterialsTests { assertThat(resolved.getAdditionalBoms().get(0)).isEqualTo("bom-main"); } + @Test + public void resolveSimpleRangeWithGroupIdArtifactId() { + BillOfMaterials bom = BillOfMaterials.create("com.example", "bom", "1.0.0"); + bom.setVersionProperty("bom.version"); + bom.getRepositories().add("repo-main"); + bom.getAdditionalBoms().add("bom-main"); + Mapping mapping = Mapping.create("[1.2.0.RELEASE,1.3.0.M1)", "1.1.0"); + mapping.setGroupId("com.example.override"); + mapping.setArtifactId("bom-override"); + bom.getMappings().add(mapping); + bom.validate(); + BillOfMaterials resolved = bom.resolve(Version.parse("1.2.3.RELEASE")); + assertThat(resolved.getGroupId()).isEqualTo("com.example.override"); + assertThat(resolved.getArtifactId()).isEqualTo("bom-override"); + assertThat(resolved.getVersion()).isEqualTo("1.1.0"); + assertThat(resolved.getVersionProperty().toStandardFormat()) + .isEqualTo("bom.version"); + assertThat(resolved.getRepositories()).hasSize(1); + assertThat(resolved.getRepositories().get(0)).isEqualTo("repo-main"); + assertThat(resolved.getAdditionalBoms()).hasSize(1); + assertThat(resolved.getAdditionalBoms().get(0)).isEqualTo("bom-main"); + } + @Test public void resolveRangeOverride() { BillOfMaterials bom = BillOfMaterials.create("com.example", "bom", "1.0.0"); diff --git a/initializr-web/src/test/resources/metadata/config/test-default.json b/initializr-web/src/test/resources/metadata/config/test-default.json index 5bfa0daa..ed62a702 100644 --- a/initializr-web/src/test/resources/metadata/config/test-default.json +++ b/initializr-web/src/test/resources/metadata/config/test-default.json @@ -106,7 +106,6 @@ "repositories": [ "my-api-repo-1" ], - "additionalBoms": [], "version": "1.0.0.RELEASE" }, { @@ -114,7 +113,6 @@ "repositories": [ "my-api-repo-2" ], - "additionalBoms": [], "version": "2.0.0.RELEASE" } ]