From 8e6e9dec538c6130a7444dc4ee99507242c6f755 Mon Sep 17 00:00:00 2001 From: Rob Winch Date: Tue, 20 Sep 2022 14:42:34 -0500 Subject: [PATCH] Allow snapshot repository for samples When a release is published Spring Boot has not been released, so it can be beneficial to allow the samples to use the snapshot repository. This is determined based on the springBootVersion property. --- .../AbstractSpringJavaPlugin.groovy | 3 +++ .../convention/SpringSamplePlugin.groovy | 15 +++++++++++++++ .../io/spring/gradle/convention/Utils.groovy | 19 ++++++++++++++++--- 3 files changed, 34 insertions(+), 3 deletions(-) diff --git a/buildSrc/src/main/groovy/io/spring/gradle/convention/AbstractSpringJavaPlugin.groovy b/buildSrc/src/main/groovy/io/spring/gradle/convention/AbstractSpringJavaPlugin.groovy index 629bd470..448e9829 100644 --- a/buildSrc/src/main/groovy/io/spring/gradle/convention/AbstractSpringJavaPlugin.groovy +++ b/buildSrc/src/main/groovy/io/spring/gradle/convention/AbstractSpringJavaPlugin.groovy @@ -35,6 +35,7 @@ public abstract class AbstractSpringJavaPlugin implements Plugin { @Override public final void apply(Project project) { + initialPlugins(project); PluginManager pluginManager = project.getPluginManager(); pluginManager.apply(JavaPlugin.class); pluginManager.apply(ManagementConfigurationPlugin.class) @@ -69,5 +70,7 @@ public abstract class AbstractSpringJavaPlugin implements Plugin { additionalPlugins(project); } + protected void initialPlugins(Project project) {} + protected abstract void additionalPlugins(Project project); } diff --git a/buildSrc/src/main/groovy/io/spring/gradle/convention/SpringSamplePlugin.groovy b/buildSrc/src/main/groovy/io/spring/gradle/convention/SpringSamplePlugin.groovy index f41a0ca8..2aa2a915 100644 --- a/buildSrc/src/main/groovy/io/spring/gradle/convention/SpringSamplePlugin.groovy +++ b/buildSrc/src/main/groovy/io/spring/gradle/convention/SpringSamplePlugin.groovy @@ -30,4 +30,19 @@ public class SpringSamplePlugin extends AbstractSpringJavaPlugin { project.sonarqube.skipProject = true } } + + @Override + protected void initialPlugins(Project project) { + if (project.hasProperty('springBootVersion')) { + String springBootVersion = project.springBootVersion + + if (Utils.isSnapshot(springBootVersion)) { + project.ext.forceMavenRepositories = 'snapshot' + } + else if (Utils.isMilestone(springBootVersion)) { + project.ext.forceMavenRepositories = 'milestone' + } + } + + } } diff --git a/buildSrc/src/main/groovy/io/spring/gradle/convention/Utils.groovy b/buildSrc/src/main/groovy/io/spring/gradle/convention/Utils.groovy index 8f5a6a90..74956be1 100644 --- a/buildSrc/src/main/groovy/io/spring/gradle/convention/Utils.groovy +++ b/buildSrc/src/main/groovy/io/spring/gradle/convention/Utils.groovy @@ -14,16 +14,29 @@ public class Utils { static boolean isSnapshot(Project project) { String projectVersion = projectVersion(project) - return projectVersion.matches('^.*([.-]BUILD)?-SNAPSHOT$') + return isSnapshot(projectVersion) } static boolean isMilestone(Project project) { String projectVersion = projectVersion(project) - return projectVersion.matches('^.*[.-]M\\d+$') || projectVersion.matches('^.*[.-]RC\\d+$') + return isMilestone(projectVersion) } static boolean isRelease(Project project) { - return !(isSnapshot(project) || isMilestone(project)) + String projectVersion = projectVersion(project) + return isRelease(projectVersion) + } + + static boolean isSnapshot(String projectVersion) { + return projectVersion.matches('^.*([.-]BUILD)?-SNAPSHOT$') + } + + static boolean isMilestone(String projectVersion) { + return projectVersion.matches('^.*[.-]M\\d+$') || projectVersion.matches('^.*[.-]RC\\d+$') + } + + static boolean isRelease(String projectVersion) { + return !(isSnapshot(projectVersion) || isMilestone(projectVersion)) } private static String projectVersion(Project project) {