Handle both snapshots and releases enabled flags in Maven Pom

This commit improves the handling of repositories with Maven.
Previously, the writer wrongly assumed that the default for releases
and snapshots are true and false respectively. However, both defaults
are true which means that snapshots repository are considered for
releases, and releases repositories are considered for snapshots.

MavenRepository has now separate flags for those and the writer makes
sure to only update the `enabled` flag if the chosen value is not
true. This doesn't increase the content for repository definitions
while offering better performance for dependencies resolution.

Closes gh-1226
This commit is contained in:
Stephane Nicoll
2021-04-20 20:20:41 +02:00
parent 88d6e79fca
commit 17df3b9b5d
23 changed files with 303 additions and 84 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2020 the original author or authors.
* Copyright 2012-2021 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -83,7 +83,7 @@ class DefaultDependencyMetadataProviderTests {
Dependency third = Dependency.withId("third", "org.foo", "third");
third.setRepository("repo-foo");
InitializrMetadata metadata = InitializrMetadataTestBuilder.withDefaults()
.addRepository("repo-foo", "my-repo", "http://localhost", false)
.addReleasesRepository("repo-foo", "my-repo", "http://localhost")
.addDependencyGroup("test", first, second, third).build();
DependencyMetadata dependencyMetadata = this.provider.get(metadata, Version.parse("1.1.5.RELEASE"));
assertThat(dependencyMetadata.getDependencies()).hasSize(3);
@@ -155,9 +155,9 @@ class DefaultDependencyMetadataProviderTests {
"repo-foo", "repo-bar"));
bom.getMappings().add(BillOfMaterials.Mapping.create("1.1.0.RELEASE", "3.0.0.RELEASE", "repo-biz"));
InitializrMetadata metadata = InitializrMetadataTestBuilder.withDefaults().addBom("bom-foo", bom)
.addRepository("repo-foo", "foo", "http://localhost", false)
.addRepository("repo-bar", "bar", "http://localhost", false)
.addRepository("repo-biz", "biz", "http://localhost", false)
.addReleasesRepository("repo-foo", "foo", "http://localhost")
.addReleasesRepository("repo-bar", "bar", "http://localhost")
.addReleasesRepository("repo-biz", "biz", "http://localhost")
.addDependencyGroup("test", first, second, third).build();
return this.provider.get(metadata, Version.parse(bootVersion));
}

View File

@@ -74,27 +74,32 @@
"my-api-repo-1": {
"name": "repo1",
"url": "https://example.com/repo1",
"releasesEnabled": true,
"snapshotsEnabled": false
},
"my-api-repo-2": {
"name": "repo2",
"url": "https://example.com/repo2",
"releasesEnabled": true,
"snapshotsEnabled": false
},
"my-api-repo-3": {
"name": "repo3",
"url": "https://example.com/repo3",
"releasesEnabled": true,
"snapshotsEnabled": false
},
"spring-milestones": {
"name": "Spring Milestones",
"snapshotsEnabled": false,
"url": "https://repo.spring.io/milestone"
"url": "https://repo.spring.io/milestone",
"releasesEnabled": true,
"snapshotsEnabled": false
},
"spring-snapshots": {
"name": "Spring Snapshots",
"snapshotsEnabled": true,
"url": "https://repo.spring.io/snapshot"
"url": "https://repo.spring.io/snapshot",
"releasesEnabled": false,
"snapshotsEnabled": true
}
},
"boms": {