Skip to content

Commit 8e6e9de

Browse files
committed
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.
1 parent 8216be6 commit 8e6e9de

File tree

3 files changed

+34
-3
lines changed

3 files changed

+34
-3
lines changed

buildSrc/src/main/groovy/io/spring/gradle/convention/AbstractSpringJavaPlugin.groovy

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ public abstract class AbstractSpringJavaPlugin implements Plugin<Project> {
3535

3636
@Override
3737
public final void apply(Project project) {
38+
initialPlugins(project);
3839
PluginManager pluginManager = project.getPluginManager();
3940
pluginManager.apply(JavaPlugin.class);
4041
pluginManager.apply(ManagementConfigurationPlugin.class)
@@ -69,5 +70,7 @@ public abstract class AbstractSpringJavaPlugin implements Plugin<Project> {
6970
additionalPlugins(project);
7071
}
7172

73+
protected void initialPlugins(Project project) {}
74+
7275
protected abstract void additionalPlugins(Project project);
7376
}

buildSrc/src/main/groovy/io/spring/gradle/convention/SpringSamplePlugin.groovy

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,19 @@ public class SpringSamplePlugin extends AbstractSpringJavaPlugin {
3030
project.sonarqube.skipProject = true
3131
}
3232
}
33+
34+
@Override
35+
protected void initialPlugins(Project project) {
36+
if (project.hasProperty('springBootVersion')) {
37+
String springBootVersion = project.springBootVersion
38+
39+
if (Utils.isSnapshot(springBootVersion)) {
40+
project.ext.forceMavenRepositories = 'snapshot'
41+
}
42+
else if (Utils.isMilestone(springBootVersion)) {
43+
project.ext.forceMavenRepositories = 'milestone'
44+
}
45+
}
46+
47+
}
3348
}

buildSrc/src/main/groovy/io/spring/gradle/convention/Utils.groovy

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,29 @@ public class Utils {
1414

1515
static boolean isSnapshot(Project project) {
1616
String projectVersion = projectVersion(project)
17-
return projectVersion.matches('^.*([.-]BUILD)?-SNAPSHOT$')
17+
return isSnapshot(projectVersion)
1818
}
1919

2020
static boolean isMilestone(Project project) {
2121
String projectVersion = projectVersion(project)
22-
return projectVersion.matches('^.*[.-]M\\d+$') || projectVersion.matches('^.*[.-]RC\\d+$')
22+
return isMilestone(projectVersion)
2323
}
2424

2525
static boolean isRelease(Project project) {
26-
return !(isSnapshot(project) || isMilestone(project))
26+
String projectVersion = projectVersion(project)
27+
return isRelease(projectVersion)
28+
}
29+
30+
static boolean isSnapshot(String projectVersion) {
31+
return projectVersion.matches('^.*([.-]BUILD)?-SNAPSHOT$')
32+
}
33+
34+
static boolean isMilestone(String projectVersion) {
35+
return projectVersion.matches('^.*[.-]M\\d+$') || projectVersion.matches('^.*[.-]RC\\d+$')
36+
}
37+
38+
static boolean isRelease(String projectVersion) {
39+
return !(isSnapshot(projectVersion) || isMilestone(projectVersion))
2740
}
2841

2942
private static String projectVersion(Project project) {

0 commit comments

Comments
 (0)