Skip to content

Commit

Permalink
Added support for Spring Boot 3.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
ethauvin committed Dec 15, 2023
1 parent 2665482 commit 8d5686a
Show file tree
Hide file tree
Showing 7 changed files with 149 additions and 80 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@ public void bootwar() throws Exception {

- [View Examples Project](https://github.com/rife2/bld-spring-boot/tree/main/examples)

Don't forget to include the _Spring Boot Loader_ dependency to your project:

```java
scope(standalone)
.include(dependency("org.springframeworkboot:spring-boot-loader:3.2.0"));
```

Please check the [BootJarOperation documentation](https://rife2.github.io/bld-spring-boot/rife/bld/extension/BootJarOperation.html#method-summary)
or [BootWarOperation documentation](https://rife2.github.io/bld-spring-boot/rife/bld/extension/BootWarOperation.html#method-summary)
for all available configuration options.
Expand Down
14 changes: 7 additions & 7 deletions examples/src/bld/java/com/example/demo/DemoApplicationBuild.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ public DemoApplicationBuild() {
repositories = List.of(MAVEN_CENTRAL);

scope(compile)
.include(dependency("org.springframework.boot:spring-boot-starter:3.1.5"))
.include(dependency("org.springframework.boot:spring-boot-starter-actuator:3.1.5"))
.include(dependency("org.springframework.boot:spring-boot-starter-web:3.1.5"));
.include(dependency("org.springframework.boot:spring-boot-starter:3.2.0"))
.include(dependency("org.springframework.boot:spring-boot-starter-actuator:3.2.0"))
.include(dependency("org.springframework.boot:spring-boot-starter-web:3.2.0"));
scope(test)
.include(dependency("org.springframework.boot:spring-boot-starter-test:3.1.5"))
.include(dependency("org.junit.jupiter:junit-jupiter:5.10.0"))
.include(dependency("org.junit.platform:junit-platform-console-standalone:1.10.0"));
.include(dependency("org.springframework.boot:spring-boot-starter-test:3.2.0"))
.include(dependency("org.junit.jupiter:junit-jupiter:5.10.1"))
.include(dependency("org.junit.platform:junit-platform-console-standalone:1.10.1"));
scope(standalone)
.include(dependency("org.springframework.boot:spring-boot-loader:3.1.5"));
.include(dependency("org.springframework.boot:spring-boot-loader:3.2.0"));
}

public static void main(String[] args) {
Expand Down
1 change: 1 addition & 0 deletions src/bld/java/rife/bld/extension/SpringBootBuild.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public SpringBootBuild() {
javaRelease = 17;
downloadSources = true;
autoDownloadPurge = true;

repositories = List.of(MAVEN_LOCAL, MAVEN_CENTRAL, RIFE2_RELEASES);

scope(compile)
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/rife/bld/extension/BootJarOperation.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public BootJarOperation fromProject(Project project) throws IOException {
.destinationFileName(project.archiveBaseName() + "-" + project.version() + "-boot.jar")
.infLibs(project.compileClasspathJars())
.infLibs(project.runtimeClasspathJars())
.launcherClass("org.springframework.boot.loader.JarLauncher")
.launcherClass(BootUtils.launcherClass(project, "JarLauncher"))
.launcherLibs(project.standaloneClasspathJars())
.mainClass(project.mainClass())
.manifestAttributes(List.of(
Expand Down
26 changes: 26 additions & 0 deletions src/main/java/rife/bld/extension/BootUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@

package rife.bld.extension;

import rife.bld.Project;
import rife.tools.FileUtils;
import rife.tools.exceptions.FileUtilsErrorException;

import java.io.File;
import java.io.IOException;
import java.text.DecimalFormat;
import java.util.regex.Pattern;

/**
* Collection of utility-type methods used by {@link AbstractBootOperation Spring Boot operations}.
Expand All @@ -30,6 +32,8 @@
* @since 1.0
*/
public final class BootUtils {
private static final Pattern LOADER_JAR = Pattern.compile("spring-boot-loader-(\\d+).(\\d+).(\\d+).jar");

private BootUtils() {
// no-op
}
Expand Down Expand Up @@ -65,6 +69,28 @@ public static String fileSize(File file) {
+ ' ' + units[digitGroups];
}

/**
* Return the fully qualified name of the launcher class.
*
* @param project the project
* @param name the class name
* @return the fully qualified class name
*/
public static String launcherClass(Project project, String name) {
for (var jar : project.standaloneClasspathJars()) {
var matcher = LOADER_JAR.matcher(jar.getName());
if (matcher.find()) {
var major = Integer.parseInt(matcher.group(1));
var minor = Integer.parseInt(matcher.group(2));
if (major == 3 && minor >= 2 || major > 3) {
return "org.springframework.boot.loader.launch." + name;
}
}
}

return "org.springframework.boot.loader." + name;
}

/**
* Makes a directory for the given path, including any necessary but nonexistent parent directories.
*
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/rife/bld/extension/BootWarOperation.java
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public BootWarOperation fromProject(Project project) throws IOException {
.infLibs(project.compileClasspathJars())
.infLibs(project.runtimeClasspathJars())
.infLibs(project.buildDistDirectory())
.launcherClass("org.springframework.boot.loader.WarLauncher")
.launcherClass(BootUtils.launcherClass(project, "WarLauncher"))
.launcherLibs(project.standaloneClasspathJars())
.mainClass(project.mainClass())
.manifestAttributes(List.of(
Expand Down
Loading

0 comments on commit 8d5686a

Please sign in to comment.