Skip to content

Commit

Permalink
Fix multiple versions potentially accepted (#717)
Browse files Browse the repository at this point in the history
This commit fixes an issue with version updates: when a custom implementation
accepts a version, we should interrupt the loop otherwise it becomes possible
for a lower version to be selected.
  • Loading branch information
melix authored Aug 21, 2024
1 parent c06c787 commit 48ae863
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/main/groovy/io/micronaut/build/MicronautBasePlugin.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import io.micronaut.build.docs.ConfigurationPropertiesPlugin
import io.micronaut.build.graalvm.NativeImageSupportPlugin
import org.gradle.api.Plugin
import org.gradle.api.Project

/**
* This plugin is responsible for creating the Micronaut Build
* project extension and configuring reasonable defaults.
Expand All @@ -39,10 +40,14 @@ class MicronautBasePlugin implements Plugin<Project> {
}

private void configureProjectVersion(Project project) {
def version = project.providers.gradleProperty("projectVersion").orElse("undefined").get()
if (version.isEmpty() || !Character.isDigit(version.charAt(0))) {
throw new IllegalArgumentException("Version '" + version + "' is not a valid Micronaut version. It must start with a digit.")
}
def version = project.providers.gradleProperty("projectVersion")
.map(v -> {
if (v.isEmpty() || !Character.isDigit(v.charAt(0))) {
throw new IllegalArgumentException("Version '" + v + "' is not a valid Micronaut version. It must start with a digit.")
}
return v;
})
.orElse("undefined").get()
project.version = version
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,9 @@ private Optional<DefaultCandidateDetails> findBestVersion(VersionCatalogTomlMode
if (!candidateDetails.isRejected()) {
processCandidate(candidateDetails);
}
if (candidateDetails.isAccepted()) {
break;
}
if (!candidateDetails.isRejected() && !candidateDetails.hasFallback()) {
candidateDetails.acceptCandidate();
break;
Expand Down

0 comments on commit 48ae863

Please sign in to comment.