Skip to content

Add Spring Boot Maven sample#49

Open
Forbiddem wants to merge 1 commit into
apple:mainfrom
Forbiddem:add-maven-sample
Open

Add Spring Boot Maven sample#49
Forbiddem wants to merge 1 commit into
apple:mainfrom
Forbiddem:add-maven-sample

Conversation

@Forbiddem
Copy link
Copy Markdown

Summary

Adds a third sample under samples/spring-boot-maven/ that mirrors the existing Gradle spring-boot sample but builds with Maven. This addresses the requests in #2 for a Maven-based example.

How the build is wired

  • exec-maven-plugin runs org.pkl.codegen.java.Main (from pkl-tools) in the generate-sources phase, with --generate-spring-boot --generate-getters, writing the generated sources/resources under target/generated-sources/pkl/.
  • build-helper-maven-plugin adds target/generated-sources/pkl/java as an extra source root, and the matching resources/ directory as an extra resource root so the org.pkl.config.java.mapper .properties mapper file ends up on the classpath.
  • spring-boot-maven-plugin enables mvn spring-boot:run and produces an executable jar via mvn package.

Files

  • pom.xml — Spring Boot starter parent 3.5.6, pkl-spring 0.18.0, pkl-tools 0.31.1, Java 17.
  • src/main/resources/AppConfig.pkl + application.pkl — same shape as the Gradle sample (a Server with a Listing<Endpoint>).
  • src/main/java/samples/boot/maven/Application.java + Server.java — same @ConfigurationPropertiesScan + CommandLineRunner pattern as the Gradle sample, namespaced under samples.boot.maven to avoid collision.
  • README.adocmvn spring-boot:run + executable-jar instructions.

Test plan

Verified locally with Apache Maven 3.6.3 and Oracle JDK 17.0.12:

  • mvn package succeeds, executable jar built.
  • java -jar target/spring-boot-maven-1.0.0-SNAPSHOT.jar starts Spring Boot 3.5.6, binds application.pkl to the generated AppConfig, and prints the configured Server bean with both endpoints (endpoint1:1234, endpoint2:5678).
  • mvn spring-boot:run produces the same output.
  • Generated AppConfig.java lands at target/generated-sources/pkl/java/samples/boot/maven/AppConfig.java and the mapper .properties lands at target/generated-sources/pkl/resources/META-INF/org/pkl/config/java/mapper/classes/.

Fixes #2 if accepted.

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Spring boot with Maven ? How to use pkl ? Help provide examples

1 participant