Skip to content

Commit 2e98acd

Browse files
committed
Tolerate incomplete models
This commit improves the resolution of plugins to ignore a non fatal resolution of the model. See gh-1227
1 parent e91f3f3 commit 2e98acd

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-0
lines changed

Diff for: initializr-version-resolver/pom.xml

+4
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@
2121
</scm>
2222

2323
<dependencies>
24+
<dependency>
25+
<groupId>org.springframework</groupId>
26+
<artifactId>spring-jcl</artifactId>
27+
</dependency>
2428
<dependency>
2529
<groupId>org.apache.maven</groupId>
2630
<artifactId>maven-core</artifactId>

Diff for: initializr-version-resolver/src/main/java/io/spring/initializr/versionresolver/DefaultMavenVersionResolver.java

+10
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
import java.util.List;
2323
import java.util.Map;
2424

25+
import org.apache.commons.logging.Log;
26+
import org.apache.commons.logging.LogFactory;
2527
import org.apache.maven.model.Model;
2628
import org.apache.maven.model.building.DefaultModelBuilder;
2729
import org.apache.maven.model.building.DefaultModelBuilderFactory;
@@ -68,6 +70,8 @@
6870
@SuppressWarnings("removal")
6971
class DefaultMavenVersionResolver implements MavenVersionResolver, DependencyManagementVersionResolver {
7072

73+
private static final Log logger = LogFactory.getLog(DefaultMavenVersionResolver.class);
74+
7175
private static final RemoteRepository mavenCentral = new RemoteRepository.Builder("central", "default",
7276
"https://repo1.maven.org/maven2")
7377
.build();
@@ -163,6 +167,12 @@ private Model buildEffectiveModel(String groupId, String artifactId, String vers
163167
return modelBuilder.build(modelBuildingRequest).getEffectiveModel();
164168
}
165169
catch (ModelBuildingException ex) {
170+
Model model = ex.getModel();
171+
if (model != null) {
172+
logger.warn("Model for '" + groupId + ":" + artifactId + ":" + version + "' is incomplete: "
173+
+ ex.getProblems());
174+
return model;
175+
}
166176
throw new IllegalStateException(
167177
"Model for '" + groupId + ":" + artifactId + ":" + version + "' could not be built", ex);
168178
}

Diff for: initializr-version-resolver/src/test/java/io/spring/initializr/versionresolver/DefaultMavenVersionResolverTests.java

+7
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,13 @@ void resolvePluginsUsingMilestones() {
9090
assertThat(versions).containsEntry("org.springframework.boot:spring-boot-maven-plugin", "2.2.0.M3");
9191
}
9292

93+
@Test
94+
void resolvePluginsUsingMilestoneThatHasResolutionProblem() {
95+
Map<String, String> versions = this.resolver.resolvePlugins("org.springframework.boot",
96+
"spring-boot-dependencies", "3.0.0-M1");
97+
assertThat(versions).containsEntry("org.springframework.boot:spring-boot-maven-plugin", "3.0.0-M1");
98+
}
99+
93100
@Test
94101
void resolvePluginsUsingSnapshots() {
95102
Map<String, String> versions = this.resolver.resolvePlugins("org.springframework.boot",

0 commit comments

Comments
 (0)