Add Spring Boot Maven sample#49
Open
Forbiddem wants to merge 1 commit into
Open
Conversation
Adds a third sample under samples/spring-boot-maven/ that mirrors the existing Gradle Spring Boot sample but builds with Maven. The sample runs Pkl's Java code generator during the generate-sources phase via exec-maven-plugin, adds the generated directory as an extra source root via build-helper-maven-plugin, and starts a Spring Boot application that reads its configuration from application.pkl. This addresses the requests in apple#2 for a Maven-based example. Verified end to end with Maven 3.6.3 and JDK 17: * mvn package then java -jar target/spring-boot-maven-1.0.0-SNAPSHOT.jar * mvn spring-boot:run Both produced the expected Server bean output bound from application.pkl.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a third sample under
samples/spring-boot-maven/that mirrors the existing Gradlespring-bootsample but builds with Maven. This addresses the requests in #2 for a Maven-based example.How the build is wired
exec-maven-pluginrunsorg.pkl.codegen.java.Main(frompkl-tools) in thegenerate-sourcesphase, with--generate-spring-boot --generate-getters, writing the generated sources/resources undertarget/generated-sources/pkl/.build-helper-maven-pluginaddstarget/generated-sources/pkl/javaas an extra source root, and the matchingresources/directory as an extra resource root so theorg.pkl.config.java.mapper.propertiesmapper file ends up on the classpath.spring-boot-maven-pluginenablesmvn spring-boot:runand produces an executable jar viamvn package.Files
pom.xml— Spring Boot starter parent 3.5.6,pkl-spring0.18.0,pkl-tools0.31.1, Java 17.src/main/resources/AppConfig.pkl+application.pkl— same shape as the Gradle sample (aServerwith aListing<Endpoint>).src/main/java/samples/boot/maven/Application.java+Server.java— same@ConfigurationPropertiesScan+CommandLineRunnerpattern as the Gradle sample, namespaced undersamples.boot.mavento avoid collision.README.adoc—mvn spring-boot:run+ executable-jar instructions.Test plan
Verified locally with Apache Maven 3.6.3 and Oracle JDK 17.0.12:
mvn packagesucceeds, executable jar built.java -jar target/spring-boot-maven-1.0.0-SNAPSHOT.jarstarts Spring Boot 3.5.6, bindsapplication.pklto the generatedAppConfig, and prints the configuredServerbean with both endpoints (endpoint1:1234,endpoint2:5678).mvn spring-boot:runproduces the same output.AppConfig.javalands attarget/generated-sources/pkl/java/samples/boot/maven/AppConfig.javaand the mapper.propertieslands attarget/generated-sources/pkl/resources/META-INF/org/pkl/config/java/mapper/classes/.Fixes #2 if accepted.